Mod177bTests.inc 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Round 177b: LYNX's modulators (Song::modulators; RackState::modRoutes): relative, bipolar, tempo-synced or free;
  2. // nothing is bound while there are none.
  3. TEST (mod177b_shapes)
  4. {
  5. lynx::Modulator m;
  6. CHECK (std::abs (m.output (0.25) - 1.0f) < 1.0e-4f); // sine: the top a quarter in
  7. CHECK (std::abs (m.output (0.75) + 1.0f) < 1.0e-4f);
  8. m.shape = lynx::ModShape::triangle;
  9. CHECK (std::abs (m.output (0.0)) < 1.0e-4f && std::abs (m.output (0.25) - 1.0f) < 1.0e-4f && std::abs (m.output (0.75) + 1.0f) < 1.0e-4f);
  10. m.shape = lynx::ModShape::square;
  11. CHECK (m.output (0.1) == 1.0f && m.output (0.6) == -1.0f);
  12. m.phase = 0.5f; // the phase moves the start
  13. CHECK (m.output (0.1) == -1.0f);
  14. m.phase = 0.0f;
  15. m.unipolar = true;
  16. CHECK (m.output (0.1) == 1.0f && m.output (0.6) == 0.0f);
  17. m.unipolar = false;
  18. m.shape = lynx::ModShape::random; // the same value for the same cycle, whatever played before
  19. const auto a = m.output (3.2), b = m.output (3.9), c = m.output (4.1);
  20. CHECK (a == b && a != c && a >= -1.0f && a <= 1.0f);
  21. m.shape = lynx::ModShape::smoothRandom; // continuous across the cycle edge
  22. CHECK (std::abs (m.output (4.0 - 1.0e-6) - m.output (4.0)) < 1.0e-3f);
  23. }
  24. TEST (mod177b_modulates_a_target_around_its_value)
  25. {
  26. auto song = lanes177bSong();
  27. const lynx::AutomationTarget master { lynx::AutomationTargetKind::mixerVolume, 0, 0, 0 };
  28. song.mixer[0].volume = 0.5f;
  29. CHECK (lynx::RackState::build (song, nullptr, 48000.0)->modRoutes.empty()); // no modulator: nothing bound
  30. const auto still = lanes177bLevel (song, 0.0);
  31. lynx::Modulator m;
  32. m.shape = lynx::ModShape::square;
  33. m.beats = 4.0;
  34. m.routes = { { master, 0.3f } };
  35. song.modulators.push_back (m);
  36. CHECK (lynx::RackState::build (song, nullptr, 48000.0)->modRoutes.size() == 1);
  37. const auto up = lanes177bLevel (song, lynx::ppq * 0.5); // first half of the cycle: +1 → 0.8
  38. const auto down = lanes177bLevel (song, lynx::ppq * 2.5); // second half: −1 → 0.2
  39. CHECK (up > still * 1.2f && down < still * 0.8f);
  40. // over an automation of the same target: it moves around the automation's value
  41. lynx::Automation a;
  42. a.target = master;
  43. a.points = { { 0, 0.2f, 0.0f }, { lynx::ppq * 16, 0.2f, 0.0f } };
  44. song.automations.push_back (a);
  45. lynx::Clip clip;
  46. clip.kind = lynx::ClipKind::automation;
  47. clip.automation = 0;
  48. clip.length = lynx::ppq * 16;
  49. song.playlist.push_back (clip);
  50. const auto automatedUp = lanes177bLevel (song, lynx::ppq * 0.5); // 0.2 + 0.3
  51. CHECK (std::abs (automatedUp - still) < still * 0.05f);
  52. // not modulated: the tempo, a plugin's parameter
  53. CHECK (! lynx::Modulator::canModulate (song, { lynx::AutomationTargetKind::tempo, 0, 0, 0 }));
  54. CHECK (lynx::Modulator::canModulate (song, master));
  55. song.modulators[0].routes[0].depth = 0.0f; // depth 0: not bound
  56. CHECK (lynx::RackState::build (song, nullptr, 48000.0)->modRoutes.empty());
  57. }