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.

52 lines
1.3KB

  1. #pragma once
  2. #include "BiquadParams.h"
  3. #include "BiquadState.h"
  4. #include "BiquadFilter.h"
  5. /**
  6. * A traditional decimator, using IIR filters for interpolation
  7. *
  8. * template parameter OVERSAMPLE is the
  9. * decimation rate.
  10. */
  11. class IIRDecimator
  12. {
  13. public:
  14. float process(const float * input)
  15. {
  16. float x = 0;
  17. for (int i = 0; i < oversample; ++i) {
  18. x = BiquadFilter<float>::run(input[i], state, *params);
  19. }
  20. return x;
  21. }
  22. /**
  23. * cutoff is normalized freq (.5 = nyquist).
  24. * typically cutoff will be < (.5 / OVERSAMPLE),
  25. * if not, the filters wouldn't work.
  26. */
  27. #if 0
  28. void setCutoff(float cutoff)
  29. {
  30. assert(cutoff > 0 && cutoff < .5f);
  31. params = ObjectCache<float>::get6PLPParams(cutoff);
  32. }
  33. #endif
  34. /**
  35. * will set the oversample factor, and set the filter cutoff.
  36. * NOrmalized cutoff is fixed at 1 / 4 * oversample, for a one
  37. * octave passband
  38. */
  39. void setup(int oversampleFactor)
  40. {
  41. assert(oversampleFactor == 4 || oversampleFactor == 16);
  42. oversample = oversampleFactor;
  43. params = ObjectCache<float>::get6PLPParams(1.f / (4.0f * oversample));
  44. }
  45. private:
  46. std::shared_ptr<BiquadParams<float, 3>> params;
  47. BiquadState<float, 3> state;
  48. int oversample = 16;
  49. };