CDSPProcessor.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //$ nobt
  2. //$ nocpp
  3. /**
  4. * @file CDSPProcessor.h
  5. *
  6. * @brief The base virtual class for DSP processing algorithms.
  7. *
  8. * This file includes the base virtual class for DSP processing algorithm
  9. * classes like FIR filtering and interpolation.
  10. *
  11. * r8brain-free-src Copyright (c) 2013-2021 Aleksey Vaneev
  12. * See the "LICENSE" file for license.
  13. */
  14. #ifndef R8B_CDSPPROCESSOR_INCLUDED
  15. #define R8B_CDSPPROCESSOR_INCLUDED
  16. #include "r8bbase.h"
  17. namespace r8b {
  18. /**
  19. * @brief The base virtual class for DSP processing algorithms.
  20. *
  21. * This class can be used as a base class for various DSP processing
  22. * algorithms (processors). DSP processors that are derived from this class
  23. * can be seamlessly integrated into various DSP processing graphs.
  24. */
  25. class CDSPProcessor : public R8B_BASECLASS
  26. {
  27. R8BNOCTOR( CDSPProcessor );
  28. public:
  29. CDSPProcessor()
  30. {
  31. }
  32. virtual ~CDSPProcessor()
  33. {
  34. }
  35. /**
  36. * @return The latency, in samples, which is present in the output signal.
  37. * This value is usually zero if the DSP processor "consumes" the latency
  38. * automatically.
  39. */
  40. virtual int getLatency() const = 0;
  41. /**
  42. * @return Fractional latency, in samples, which is present in the output
  43. * signal. This value is usually zero if a linear-phase filtering is used.
  44. * With minimum-phase filters in use, this value can be non-zero even if
  45. * the getLatency() function returns zero.
  46. */
  47. virtual double getLatencyFrac() const = 0;
  48. /**
  49. * @param MaxInLen The number of samples planned to process at once, at
  50. * most.
  51. * @return The maximal length of the output buffer required when
  52. * processing the "MaxInLen" number of input samples.
  53. */
  54. virtual int getMaxOutLen( const int MaxInLen ) const = 0;
  55. /**
  56. * Function clears (resets) the state of *this object and returns it to
  57. * the state after construction. All input data accumulated in the
  58. * internal buffer so far will be discarded.
  59. */
  60. virtual void clear() = 0;
  61. /**
  62. * Function performs DSP processing.
  63. *
  64. * @param ip Input data pointer.
  65. * @param l0 How many samples to process.
  66. * @param[out] op0 Output data pointer. The capacity of this buffer should
  67. * be equal to the value returned by the getMaxOutLen() function for the
  68. * given "l0". This buffer can be equal to "ip" only if the
  69. * getMaxOutLen( l0 ) function returned a value lesser than "l0". This
  70. * pointer can be incremented on function's return if latency compensation
  71. * was performed by the processor. Note that on function's return, this
  72. * pointer may point to some internal buffers, including the "ip" buffer,
  73. * ignoring the originally passed value.
  74. * @return The number of output samples written to the "op0" buffer and
  75. * available after processing. This value can be smaller or larger in
  76. * comparison to the original "l0" value due to processing and filter's
  77. * latency compensation that took place, and due to resampling if it was
  78. * performed.
  79. */
  80. virtual int process( double* ip, int l0, double*& op0 ) = 0;
  81. };
  82. } // namespace r8b
  83. #endif // R8B_CDSPPROCESSOR_INCLUDED