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.

48 lines
1.3KB

  1. #pragma once
  2. #include "BiquadParams.h"
  3. #include "BiquadState.h"
  4. #include "BiquadFilter.h"
  5. #include "ObjectCache.h"
  6. class IIRUpsampler
  7. {
  8. public:
  9. void process(float * outputBuffer, float input)
  10. {
  11. input *= oversample;
  12. for (int i = 0; i < oversample; ++i) {
  13. outputBuffer[i] = BiquadFilter<float>::run(input, state, *params);
  14. input = 0; // just filter a delta - don't average the whole signal
  15. }
  16. }
  17. /**
  18. * cutoff is normalized freq (.5 = nyquist).
  19. * typically cutoff will be < (.5 / FACTOR),
  20. * if not, the filters wouldn't work.
  21. */
  22. #if 0
  23. void setCutoff(float cutoff)
  24. {
  25. assert(cutoff > 0 && cutoff < .5f);
  26. // ButterworthFilterDesigner<float>::designSixPoleLowpass(params, cutoff);
  27. params = ObjectCache<float>::get6PLPParams(cutoff);
  28. }
  29. #endif
  30. /**
  31. * Will set the oversample factor, and set the filter cutoff.
  32. * NOrmalized cutoff is fixed at 1 / 4 * oversample, for a one
  33. * octave passband
  34. */
  35. void setup(int oversampleFactor)
  36. {
  37. assert(oversampleFactor == 4 || oversampleFactor == 16);
  38. oversample = oversampleFactor;
  39. params = ObjectCache<float>::get6PLPParams(1.f / (4.0f * oversample));
  40. }
  41. private:
  42. std::shared_ptr<BiquadParams<float, 3>> params;
  43. BiquadState<float, 3> state;
  44. int oversample = 16;
  45. };