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.

63 lines
973B

  1. #include "IIRUpsampler.h"
  2. #include "IIRDecimator.h"
  3. #include "asserts.h"
  4. static void setup(IIRUpsampler& up, IIRDecimator& dec)
  5. {
  6. // float cutoff = .25 / 16;
  7. up.setup(16);
  8. dec.setup(16);
  9. }
  10. // test that the functions can be called
  11. static void test0()
  12. {
  13. float buffer[16];
  14. IIRUpsampler up;
  15. IIRDecimator dec;
  16. setup(up, dec);
  17. up.process(buffer, 0);
  18. dec.process(buffer);
  19. }
  20. // test 0 -> 0
  21. static void test1()
  22. {
  23. float buffer[16];
  24. IIRUpsampler up;
  25. IIRDecimator dec;
  26. setup(up, dec);
  27. up.process(buffer, 0);
  28. const float x = dec.process(buffer);
  29. assertEQ(x, 0);
  30. }
  31. // test 10 -> 10
  32. static void test2()
  33. {
  34. float buffer[16];
  35. IIRUpsampler up;
  36. IIRDecimator dec;
  37. setup(up, dec);
  38. float x;
  39. for (int i = 0; i < 100; ++i) {
  40. up.process(buffer, 10);
  41. x = dec.process(buffer);
  42. }
  43. assertClose(x, 10, .001);
  44. }
  45. void testRateConversion()
  46. {
  47. test0();
  48. test1();
  49. test2();
  50. }