You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CDSPProcessor.h 3.3KB

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