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.

50 lines
1015B

  1. #include "asserts.h"
  2. #include "Tremolo.h"
  3. #include "TestComposite.h"
  4. using Trem = Tremolo<TestComposite>;
  5. static void test0()
  6. {
  7. Trem t;
  8. t.setSampleRate(44100);
  9. t.init();
  10. assertEQ(t.outputs[Trem::SAW_OUTPUT].value, 0);
  11. assertEQ(t.outputs[Trem::AUDIO_OUTPUT].value, 0);
  12. t.step();
  13. }
  14. static void test1Sub(float skew)
  15. {
  16. Trem t;
  17. t.setSampleRate(44100);
  18. t.init();
  19. t.params[Trem::CLOCK_MULT_PARAM].value = 4; // 4 is free run for Trem
  20. t.params[Trem::LFO_RATE_PARAM].value = 5; // max speed
  21. t.params[Trem::LFO_SKEW_PARAM].value = skew;
  22. float max = -100;
  23. float min = 100;
  24. for (int i = 0; i < 5000; ++i) {
  25. t.step();
  26. const float x = t.outputs[Trem::SAW_OUTPUT].value;
  27. max = std::max(x, max);
  28. min = std::min(x, min);
  29. }
  30. assertClose(max, .5f, .001);
  31. assertClose(min, -.5f, .001);
  32. }
  33. static void test1()
  34. {
  35. test1Sub(0);
  36. test1Sub(5);
  37. test1Sub(-5);
  38. }
  39. void testTremolo()
  40. {
  41. test0();
  42. test1();
  43. }