Playlist189iTests.inc 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // --- Round 189i: FL's per-clip edge declicker (PLFadeHandleMenu: Manual, Declicker Automatic / Disabled / Enabled) ----
  2. // (FLEngine 2026 [DECOMP] FUN_00d01bc0 / FUN_00cfc020 / FUN_00cfbf60 menu, FUN_00d27cf0 / FUN_00d253d0 / FUN_00d24400
  3. // voice, FUN_012c6ae0 / FUN_00977870 declicker tables; notes in /mnt/e/lynx-work/flgap189i; FL /R renders round 189l)
  4. #include "core/ClipOps.h"
  5. #include "core/Instruments.h"
  6. #include "core/Scheduler.h"
  7. namespace
  8. {
  9. // an audio clip voice of a DC 0.5 sample with the channel's declicking `mode`: renders `before` frames, ends the clip,
  10. // renders 1000 more; returns both blocks
  11. struct Edge189i
  12. {
  13. std::vector<float> head, tail;
  14. };
  15. Edge189i edge189i (int mode, std::uint16_t shape, float fadeIn = 0.0f, float fadeOut = 0.0f, float elapsed = 0.0f)
  16. {
  17. auto data = std::make_shared<lynx::SampleData>();
  18. data->sampleRate = 44100.0;
  19. data->left.assign (44100 * 2, 0.5f);
  20. auto clip = lynx::makeInstrument (lynx::InstrumentKind::audioClip, data);
  21. clip->prepare (44100.0);
  22. lynx::ChannelDef def;
  23. def.instrument = lynx::InstrumentKind::audioClip;
  24. def.sampler.declickMode = mode;
  25. clip->configure (def, 120.0);
  26. const auto key = lynx::audioClipKey (3);
  27. clip->setNextClipFades (elapsed, 20000.0f, fadeIn, fadeOut, shape);
  28. clip->noteOnAt (key, 1.0f, 0.1);
  29. Edge189i e;
  30. e.head.assign (9000, 0.0f);
  31. std::vector<float> r (9000);
  32. clip->render (e.head.data(), r.data(), 9000, 1.0f, 1.0f);
  33. clip->noteOff (key);
  34. e.tail.assign (1000, 0.0f);
  35. clip->render (e.tail.data(), r.data(), 1000, 1.0f, 1.0f);
  36. return e;
  37. }
  38. int sounding189i (const std::vector<float>& v)
  39. {
  40. int n = 0;
  41. while (n < (int) v.size() && std::fabs (v[(std::size_t) n]) > 0.0f)
  42. ++n;
  43. return n;
  44. }
  45. } // namespace
  46. // The clip's end (FL /R renders, round 189l): channels in modes 2 / 3 / 4 take their declicking release (raised cosine of
  47. // 20 / 20 / 100 ms) when the end is Automatic / Enabled; modes 0 and 1 cut sharply whatever the choice, and so do Disabled
  48. // (shape bit 6), a manual end (bit 8) and an end with a fade out
  49. TEST (playlist189i_clip_end_declick)
  50. {
  51. const auto generic = edge189i (3, 0);
  52. const auto level = generic.head.back();
  53. CHECK (level > 0.1f);
  54. CHECK (std::abs (sounding189i (generic.tail) - 882) <= 2);
  55. CHECK (std::abs (generic.tail[441] / level - 0.5f) < 0.02f);
  56. CHECK (std::abs (sounding189i (edge189i (2, 0).tail) - 882) <= 2); // Transient (bleeding): 20 ms
  57. CHECK (sounding189i (edge189i (0, 0).tail) == 0); // Out only: sharp
  58. CHECK (sounding189i (edge189i (1, 0).tail) == 0); // Transient (no bleeding): sharp
  59. CHECK (sounding189i (edge189i (3, 64).tail) == 0);
  60. CHECK (sounding189i (edge189i (3, 256).tail) == 0);
  61. CHECK (sounding189i (edge189i (3, 0, 0.0f, 100.0f).tail) == 0);
  62. }
  63. // The clip's start: modes 3 / 4 / 5 fade in with a raised cosine (20 / 100 / 200 ms), modes 1 / 2 remove the first
  64. // frame's step over 4 ms, mode 0 has no attack; Disabled (bit 5) or a manual start (bit 7) start at full level
  65. TEST (playlist189i_clip_start_declick)
  66. {
  67. const auto plain = edge189i (0, 0).head;
  68. CHECK (plain[0] > 0.1f && std::abs (plain[0] - plain[100]) < 1e-6f);
  69. const auto generic = edge189i (3, 0).head; // 20 ms = 882 frames
  70. const auto level = generic[5000];
  71. CHECK (generic[0] < 0.001f * level);
  72. CHECK (std::abs (generic[441] / level - 0.5f) < 0.01f);
  73. CHECK (std::abs (generic[900] - level) < 1e-6f);
  74. const auto transient = edge189i (2, 0).head; // 4 ms = 176 frames: x - x0 (1 + cos((k + 1) pi / 177)) / 2
  75. CHECK (transient[0] < 0.001f * level);
  76. CHECK (std::abs (transient[87] / level - 0.5f) < 0.02f);
  77. CHECK (std::abs (transient[200] - level) < 1e-6f);
  78. CHECK (std::abs (edge189i (3, 32).head[0] - level) < 1e-6f);
  79. CHECK (std::abs (edge189i (3, 128).head[0] - level) < 1e-6f);
  80. CHECK (edge189i (3, 128, 0.0f, 0.0f, 500.0f).head[0] < 0.001f * level); // started past its manual start: declicked
  81. }
  82. // The menu's data: FL's bits (manual 0 / 1, choice >> 2 / >> 14), Manual off zeroes the fade
  83. TEST (playlist189i_declick_choice_bits)
  84. {
  85. using namespace lynx;
  86. Clip a;
  87. a.kind = ClipKind::audio;
  88. a.channel = 2;
  89. a.track = 4;
  90. a.start = 0;
  91. a.length = 96;
  92. a.offset = 48;
  93. clipops::setDeclickChoice (a, 0, clipops::declickDisabled);
  94. clipops::setDeclickChoice (a, 1, clipops::declickEnabled);
  95. CHECK (a.flFadeFlags == ((3u << 2) | (2u << 14)));
  96. CHECK (clipops::declickChoice (a, 0) == 3 && clipops::declickChoice (a, 1) == 2);
  97. a.fadeOut = 10;
  98. clipops::setManualFade (a, 1, true);
  99. CHECK (clipops::manualFade (a, 1) && ! clipops::manualFade (a, 0) && (a.flFadeFlags & 2u) != 0);
  100. clipops::setManualFade (a, 1, false);
  101. CHECK (! clipops::manualFade (a, 1) && a.fadeOut == 0);
  102. }