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.

65 lines
1.4KB

  1. #include <assert.h>
  2. #include <vector>
  3. #include "FrequencyShifter.h"
  4. #include "TestComposite.h"
  5. #include "ExtremeTester.h"
  6. using Shifter = FrequencyShifter<TestComposite>;
  7. // just test the can compile, etc..
  8. static void test0()
  9. {
  10. Shifter fs;
  11. fs.setSampleRate(44100);
  12. fs.init();
  13. fs.step();
  14. }
  15. // test for signal
  16. static void test1()
  17. {
  18. Shifter fs;
  19. fs.setSampleRate(44100);
  20. fs.init();
  21. fs.inputs[Shifter::AUDIO_INPUT].value = 0;
  22. fs.outputs[Shifter::SIN_OUTPUT].value = 0;
  23. // with no input, should have no output
  24. for (int i = 0; i < 50; ++i) {
  25. fs.step();
  26. assert(fs.outputs[Shifter::SIN_OUTPUT].value == 0);
  27. }
  28. fs.inputs[Shifter::AUDIO_INPUT].value = 1;
  29. // this should produce output
  30. for (int i = 0; i < 50; ++i) {
  31. fs.step();
  32. assert(!AudioMath::closeTo(fs.outputs[Shifter::SIN_OUTPUT].value, 0, .00001));
  33. assert(!AudioMath::closeTo(fs.outputs[Shifter::COS_OUTPUT].value, 0, .00001));
  34. }
  35. }
  36. static void testExtreme()
  37. {
  38. using fp = std::pair<float, float>;
  39. std::vector< std::pair<float, float> > paramLimits;
  40. Shifter va;
  41. va.setSampleRate(44100);
  42. va.init();
  43. paramLimits.resize(va.NUM_PARAMS);
  44. paramLimits[va.PITCH_PARAM] = fp(-5.f, 5.f);
  45. ExtremeTester<Shifter>::test(va, paramLimits, true, "shifter");
  46. }
  47. void testFrequencyShifter()
  48. {
  49. test0();
  50. test1();
  51. testExtreme();
  52. }