Rec168xTests.inc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Round 168x (issue #41, Carlrune20): "Arming a mixer insert and recording captures only the dry input. There's no way
  2. // to record the signal after the insert's effects". FL has the option: the insert's "Record" positions (External input
  3. // only / External and mixer input / Post effects / Post EQ / Post level and panning / Post track; Post EQ is FL 2026's
  4. // default). The renderer taps the insert at that point for the take. Evidence: docs/analise/REA_rodada168x.md §2.
  5. namespace
  6. {
  7. struct Rec168Taps
  8. {
  9. lynx::Song song = lynx::Song::makeDefault();
  10. lynx::RackRenderer renderer;
  11. lynx::LiveInput input;
  12. std::vector<float> a = std::vector<float> (256, 0.25f), b = std::vector<float> (256, 0.25f), l = std::vector<float> (256),
  13. r = std::vector<float> (256);
  14. Rec168Taps()
  15. {
  16. song.channels.clear();
  17. song.playlist.clear();
  18. song.mixer = lynx::Song::defaultMixer (4);
  19. auto& mt = song.mixer[2];
  20. mt.inputChannel = 0; // In 1 - In 2 (a DC of 0.25: easy to follow through the insert)
  21. mt.monitor = lynx::InputMonitor::automatic;
  22. auto gain = lynx::makeEffectSlot (lynx::EffectKind::utility);
  23. gain.params[0] = 0.625f; // +6 dB
  24. mt.effects.push_back (gain);
  25. mt.eq.gainDb[0] = 6.0f; // the built-in EQ's low shelf: +6 dB at DC
  26. mt.volume = lynx::faderPosition (0.5f); // −6 dB
  27. renderer.prepare (48000.0, 512);
  28. renderer.setLiveInput (&input);
  29. input.channels[0] = a.data();
  30. input.channels[1] = b.data();
  31. input.numChannels = 2;
  32. input.armed[2].store (true);
  33. input.recording.store (true);
  34. const lynx::RecordSource points[] { lynx::RecordSource::externalAndMixer, lynx::RecordSource::postEffects, lynx::RecordSource::postEq,
  35. lynx::RecordSource::postLevel, lynx::RecordSource::postTrack };
  36. for (int k = 0; k < 5; ++k)
  37. {
  38. input.taps[(std::size_t) k].point.store ((int) points[k]);
  39. input.taps[(std::size_t) k].track.store (2);
  40. }
  41. input.tapCount.store (5);
  42. }
  43. // a few blocks (the fader glides, the EQ settles), then sample 200 of the last block at each tap
  44. std::array<float, 5> run (const lynx::RackState* state)
  45. {
  46. for (int block = 0; block < 12; ++block)
  47. {
  48. for (auto& tap : input.taps)
  49. for (auto& d : tap.data)
  50. std::fill (d.begin(), d.begin() + 256, 0.0f); // AudioEngine clears them before each block
  51. renderer.process (state, true, 0.0, 256, l.data(), r.data());
  52. }
  53. std::array<float, 5> out {};
  54. for (int k = 0; k < 5; ++k)
  55. out[(std::size_t) k] = input.taps[(std::size_t) k].data[0][200];
  56. return out;
  57. }
  58. };
  59. bool rec168Near (float a, float b) { return std::abs (a - b) < 0.02f * std::max (0.05f, std::abs (b)); }
  60. } // namespace
  61. TEST (rec168_fl_default_is_post_eq)
  62. {
  63. // FL 2026's new inserts record Post EQ (its demo projects save 0xA5 = 3 on every insert)
  64. lynx::MixerTrack track;
  65. CHECK (track.recordSource == lynx::RecordSource::postEq && ! track.recordDryToo);
  66. CHECK ((int) lynx::RecordSource::externalInput == 0 && (int) lynx::RecordSource::postTrack == 5); // FL's byte values
  67. flp::Project project;
  68. CHECK (project.mixer.empty());
  69. flp::MixerInsert insert;
  70. CHECK (insert.recordSource == -1); // no 0xA5 event: LYNX keeps the default
  71. }
  72. TEST (rec168_taps_follow_fl_insert_order)
  73. {
  74. Rec168Taps t;
  75. auto state = lynx::RackState::build (t.song, nullptr, 48000.0);
  76. const auto v = t.run (state.get());
  77. // input 0.25 → slots (+6 dB) → EQ (+6 dB at DC) → fader (half) → mute
  78. CHECK (rec168Near (v[0], 0.25f)); // External and mixer input: the insert's input, before the slots
  79. CHECK (rec168Near (v[1], 0.25f * 1.995f)); // Post effects
  80. CHECK (rec168Near (v[2], 0.25f * 1.995f * 1.995f)); // Post EQ (FL's default)
  81. CHECK (v[3] > v[2] * 0.45f && v[3] < v[2] * 0.55f); // Post level and panning (−6 dB, the pan law at the centre)
  82. CHECK (rec168Near (v[4], v[3])); // Post track: the same while the insert plays
  83. CHECK (rec168Near (t.l[200], v[4])); // ... which is what reaches the Master
  84. // muted: Post track goes silent, the positions before the mute keep recording (the effects still run)
  85. t.song.mixer[2].muted = true;
  86. auto muted = lynx::RackState::build (t.song, state.get(), 48000.0);
  87. const auto m = t.run (muted.get());
  88. CHECK (std::abs (m[4]) < 1e-6f && std::abs (t.l[200]) < 1e-6f);
  89. CHECK (rec168Near (m[1], v[1]) && rec168Near (m[2], v[2]) && rec168Near (m[3], v[3]));
  90. // no taps: the renderer does no tap work (the buffers stay as they were)
  91. t.input.tapCount.store (0);
  92. t.input.taps[1].data[0][200] = 7.0f;
  93. t.renderer.process (muted.get(), true, 0.0, 256, t.l.data(), t.r.data());
  94. CHECK (t.input.taps[1].data[0][200] == 7.0f);
  95. }
  96. TEST (rec168_wet_take_latency_is_the_slots_latency)
  97. {
  98. // a take tapped after the slots arrives late by their latency (the input itself is not delayed by the plan's
  99. // alignment); the manual track latency delays nothing inside the insert
  100. auto song = lynx::Song::makeDefault();
  101. song.channels.clear();
  102. song.mixer = lynx::Song::defaultMixer (4);
  103. song.mixer[2].latencyMs = 10.0f;
  104. std::vector<std::vector<int>> slots (4);
  105. slots[2] = { 64, 128 };
  106. slots[1] = { 500 };
  107. for (int k = 0; k < 2; ++k)
  108. song.mixer[2].effects.push_back (lynx::makeEffectSlot (lynx::EffectKind::utility));
  109. song.mixer[1].effects.push_back (lynx::makeEffectSlot (lynx::EffectKind::utility));
  110. song.mixer[1].sends.push_back ({ 2, 1.0f });
  111. const auto plan = lynx::computePdc (song, {}, slots, 48000.0);
  112. CHECK (lynx::insertEffectsLatency (plan, song, 2, 48000.0) == 192);
  113. CHECK (lynx::insertEffectsLatency (plan, song, 1, 48000.0) == 500);
  114. CHECK (lynx::insertEffectsLatency (plan, song, 3, 48000.0) == 0);
  115. CHECK (lynx::insertEffectsLatency (plan, song, 99, 48000.0) == 0);
  116. }