InputTests.inc 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // --- External audio input per mixer insert (core/LiveInput.h, RackRenderer) - round 88 ------------------------------
  2. TEST (input_sources_pairs_then_monos)
  3. {
  4. const auto four = lynx::inputSources ({ "In 1", "In 2", "In 3", "In 4" });
  5. CHECK (four.size() == 6);
  6. CHECK (four.size() == 6 && four[0].channel == 0 && four[0].stereo && four[0].name == "In 1 - In 2");
  7. CHECK (four.size() == 6 && four[1].channel == 2 && four[1].stereo && four[1].name == "In 3 - In 4");
  8. CHECK (four.size() == 6 && four[2].channel == 0 && ! four[2].stereo && four[2].name == "In 1");
  9. CHECK (four.size() == 6 && four[5].channel == 3 && ! four[5].stereo);
  10. const auto odd = lynx::inputSources ({ "L", "R", "Mic" }); // the last channel has no pair
  11. CHECK (odd.size() == 4 && odd[0].name == "L - R" && odd[3].name == "Mic");
  12. const auto mono = lynx::inputSources ({ "Microphone" });
  13. CHECK (mono.size() == 1 && mono[0].channel == 0 && ! mono[0].stereo);
  14. CHECK (lynx::inputSources ({}).empty());
  15. CHECK (lynx::inputSourceName (-1, true, { "a", "b" }).empty());
  16. CHECK (lynx::inputSourceName (0, true, { "a", "b" }) == "a - b");
  17. CHECK (lynx::inputSourceName (1, false, { "a", "b" }) == "b");
  18. CHECK (lynx::inputSourceName (4, true, { "a", "b" }) == "In 5 - In 6"); // a channel the open device doesn't have
  19. }
  20. TEST (input_monitor_modes)
  21. {
  22. using lynx::InputMonitor;
  23. CHECK (! lynx::inputMonitored (InputMonitor::off, true, false, true));
  24. CHECK (lynx::inputMonitored (InputMonitor::on, false, true, false));
  25. CHECK (lynx::inputMonitored (InputMonitor::whenArmed, true, true, false) && ! lynx::inputMonitored (InputMonitor::whenArmed, false, false, true));
  26. // auto: armed and (recording or stopped); playback without recording plays the take, not the input
  27. CHECK (lynx::inputMonitored (InputMonitor::automatic, true, false, false));
  28. CHECK (lynx::inputMonitored (InputMonitor::automatic, true, true, true));
  29. CHECK (! lynx::inputMonitored (InputMonitor::automatic, true, true, false));
  30. CHECK (! lynx::inputMonitored (InputMonitor::automatic, false, false, false));
  31. CHECK (lynx::MixerTrack {}.monitor == InputMonitor::whenArmed && lynx::MixerTrack {}.inputChannel == -1); // FL's default (round 190ev)
  32. lynx::MixerTrack t;
  33. t.inputChannel = 1;
  34. t.inputStereo = true;
  35. CHECK (lynx::inputChannelsOf (t, 4) == std::make_pair (1, 2));
  36. CHECK (lynx::inputChannelsOf (t, 2) == std::make_pair (1, 1)); // the pair's second channel isn't there: mono
  37. CHECK (lynx::inputChannelsOf (t, 1).second == 0);
  38. t.inputStereo = false;
  39. CHECK (lynx::inputChannelsOf (t, 4) == std::make_pair (1, 1));
  40. }
  41. TEST (input_reaches_insert_and_meters)
  42. {
  43. auto song = lynx::Song::makeDefault();
  44. song.channels.clear();
  45. song.playlist.clear();
  46. song.mixer = lynx::Song::defaultMixer (4);
  47. song.mixer[2].inputChannel = 0; // stereo pair 1-2
  48. song.mixer[3].inputChannel = 2; // mono channel 3, monitoring off
  49. song.mixer[3].inputStereo = false;
  50. song.mixer[3].monitor = lynx::InputMonitor::off;
  51. song.mixer[2].monitor = lynx::InputMonitor::on;
  52. auto state = lynx::RackState::build (song, nullptr, 48000.0);
  53. lynx::RackRenderer renderer;
  54. renderer.prepare (48000.0, 512);
  55. lynx::LiveInput input;
  56. renderer.setLiveInput (&input);
  57. std::vector<float> a (256, 0.25f), b (256, -0.5f), c (256, 0.75f), l (256), r (256);
  58. input.channels[0] = a.data();
  59. input.channels[1] = b.data();
  60. input.channels[2] = c.data();
  61. input.numChannels = 3;
  62. renderer.process (state.get(), false, 0.0, 256, l.data(), r.data());
  63. // insert 2 at unity, routed to the Master at unity: the input comes out (left = ch 1, right = ch 2)
  64. CHECK (std::abs (l[100] - 0.25f) < 1e-3f && std::abs (r[100] + 0.5f) < 1e-3f);
  65. CHECK (std::abs (input.meters.takePeak (2, 0) - 0.25f) < 1e-6f && std::abs (input.meters.takePeak (2, 1) - 0.5f) < 1e-6f);
  66. CHECK (std::abs (input.meters.takePeak (3, 0) - 0.75f) < 1e-6f); // metered even though it isn't heard
  67. CHECK (input.meters.takePeak (1, 0) == 0.0f);
  68. // auto monitoring: heard while armed and stopped, not during playback without recording
  69. song.mixer[2].monitor = lynx::InputMonitor::automatic;
  70. auto autoState = lynx::RackState::build (song, state.get(), 48000.0);
  71. renderer.process (autoState.get(), false, 0.0, 256, l.data(), r.data());
  72. CHECK (std::abs (l[200]) < 1e-6f);
  73. input.armed[2].store (true);
  74. renderer.process (autoState.get(), false, 0.0, 256, l.data(), r.data());
  75. CHECK (std::abs (l[200] - 0.25f) < 1e-3f);
  76. renderer.process (autoState.get(), true, 0.0, 256, l.data(), r.data());
  77. CHECK (std::abs (l[200]) < 1e-6f);
  78. input.recording.store (true);
  79. renderer.process (autoState.get(), true, 0.0, 256, l.data(), r.data());
  80. CHECK (std::abs (l[200] - 0.25f) < 1e-3f);
  81. // the input goes through the insert's fader: muted insert, nothing out
  82. song.mixer[2].muted = true;
  83. auto muted = lynx::RackState::build (song, autoState.get(), 48000.0);
  84. // (the fader glides at most 0.001 per sample, REA_rodada85 §3: silent after 1000 samples)
  85. for (int block = 0; block < 5; ++block)
  86. renderer.process (muted.get(), true, 0.0, 256, l.data(), r.data());
  87. CHECK (std::abs (l[200]) < 1e-6f);
  88. // no input open: nothing happens
  89. input.numChannels = 0;
  90. song.mixer[2].muted = false;
  91. auto none = lynx::RackState::build (song, muted.get(), 48000.0);
  92. renderer.process (none.get(), true, 0.0, 256, l.data(), r.data());
  93. renderer.process (none.get(), true, 0.0, 256, l.data(), r.data());
  94. CHECK (std::abs (l[200]) < 1e-6f);
  95. }