Match124Tests.inc 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. // Round 124: LYNX's substitutes matched to the official trials at her settings (docs/analise/REA_rodada124.md).
  2. // Golden values are the REFERENCE's measured outputs (fxmeasure, 48 kHz); the substitute must stay within them.
  3. namespace m124
  4. {
  5. constexpr double sr = 48000.0;
  6. struct Stereo
  7. {
  8. std::vector<float> l, r;
  9. };
  10. inline Stereo run (const lynx::EffectSlot& slot, Stereo x)
  11. {
  12. auto fx = lynx::makeEffect (slot);
  13. fx->prepare (sr);
  14. fx->reset();
  15. for (std::size_t off = 0; off < x.l.size(); off += 512)
  16. {
  17. const auto m = (int) std::min<std::size_t> (512, x.l.size() - off);
  18. fx->process (x.l.data() + off, x.r.data() + off, m, slot.params, 120.0);
  19. }
  20. return x;
  21. }
  22. inline Stereo sine (double hz, double db, double secs)
  23. {
  24. Stereo s;
  25. const auto n = (std::size_t) (secs * sr);
  26. s.l.resize (n);
  27. for (std::size_t i = 0; i < n; ++i)
  28. s.l[i] = (float) (std::pow (10.0, db / 20.0) * std::sin (2.0 * 3.141592653589793 * hz * (double) i / sr));
  29. s.r = s.l;
  30. return s;
  31. }
  32. // the gain (dB) at hz of y over x from `from` on (a single-bin DFT)
  33. inline double gainDb (const std::vector<float>& x, const std::vector<float>& y, double hz, std::size_t from)
  34. {
  35. double xr = 0, xi = 0, yr = 0, yi = 0;
  36. for (auto i = from; i < x.size(); ++i)
  37. {
  38. const auto w = 2.0 * 3.141592653589793 * hz * (double) i / sr;
  39. xr += x[i] * std::cos (w), xi += x[i] * std::sin (w);
  40. yr += y[i] * std::cos (w), yi += y[i] * std::sin (w);
  41. }
  42. return 10.0 * std::log10 ((yr * yr + yi * yi) / (xr * xr + xi * xi));
  43. }
  44. inline lynx::EffectSlot substitute (const lynx::ForeignPlugin& fp)
  45. {
  46. auto slot = subst113::pluginSlot (fp);
  47. CHECK (lynx::substituteEffectSlot (slot, lynx::pluginIdentity (fp)));
  48. slot.mix = 1.0f;
  49. return slot;
  50. }
  51. } // namespace m124
  52. TEST (fresh_air_dynamic_model_matches_the_trial_round124)
  53. {
  54. using namespace lynx;
  55. ForeignPlugin fa;
  56. fa.format = ForeignPlugin::Format::vst3;
  57. fa.name = "Fresh Air";
  58. fa.classId = substtest::classIdOf ("f2a24ccd9800ac4900439bb9001cb96a");
  59. fa.hasClassId = true;
  60. fa.state = substtest::flVst3State (subst113::freshAirState (0.292f, 0.252f)); // her main setting (733 slots)
  61. const auto slot = m124::substitute (fa);
  62. CHECK (slot.kind == EffectKind::aether && slot.params[mixsuite::aether::dynamic] == 1.0f);
  63. // [EXEC] the official trial at 0.292 / 0.252, steady sines (dB of output over input)
  64. struct Point { double hz, level, gain; };
  65. static constexpr Point golden[] = { { 1000, -60, 1.083 }, { 1000, -12, 1.083 }, { 1000, 0, 1.461 },
  66. { 4000, -60, 3.681 }, { 4000, -12, 1.815 }, { 4000, 0, 1.795 },
  67. { 10000, -60, 9.762 }, { 10000, -30, 8.129 }, { 10000, -12, 3.384 }, { 10000, 0, 2.380 },
  68. { 16000, -60, 12.077 }, { 16000, -30, 9.432 }, { 16000, -12, 4.087 }, { 16000, 0, 2.647 } };
  69. for (const auto& g : golden)
  70. {
  71. const auto x = m124::sine (g.hz, g.level, 0.5);
  72. const auto y = m124::run (slot, x);
  73. const auto d = m124::gainDb (x.l, y.l, g.hz, (std::size_t) (0.3 * m124::sr));
  74. // (16 kHz at -30 dBFS, a steady sine just past the high band's second knee, is the model's worst point: 0.36 dB;
  75. // the dynamics were fitted on her takes, where the spectra agree within 0.05 dB RMS)
  76. const auto tolerance = g.hz == 16000 && g.level == -30 ? 0.4 : 0.25;
  77. if (std::abs (d - g.gain) > tolerance)
  78. std::printf (" Fresh Air %g Hz %g dBFS: %.3f dB, reference %.3f\n", g.hz, g.level, d, g.gain);
  79. CHECK (std::abs (d - g.gain) <= tolerance);
  80. }
  81. // no latency, unlike the classic oversampled exciter path
  82. auto fx = makeEffect (slot);
  83. fx->prepare (m124::sr);
  84. std::vector<float> l (64, 0.0f), r (64, 0.0f);
  85. fx->process (l.data(), r.data(), 64, slot.params, 120.0);
  86. CHECK (fx->latencySamples() == 0);
  87. }
  88. TEST (doubler_her_state_timing_is_sample_exact_round124)
  89. {
  90. using namespace lynx;
  91. namespace g = voicetools::gemini;
  92. // her Doubler (1969 slots): voices 78.2 / 100 ms, -1 / 0 cents, feedback 39 %, hard left / right, aligned
  93. PluginIdentity id;
  94. id.format = ForeignPlugin::Format::vst3;
  95. id.name = "WaveShell1-VST3 15.5_x64";
  96. id.state = substtest::wavesComponent ("Doubler", "0 1 0 0 1 * * * * 0 -28.7 841 3538 -13.7 0 16 0 0 0 0 64 20 32 -60 -40 -20 "
  97. "1 0 -45 0 -1 78.2 39 0 1 * 1 0 45 0 0 100 39 0 1 *");
  98. const auto* entry = findPluginSubstitute (id, false);
  99. CHECK (entry != nullptr);
  100. if (entry == nullptr)
  101. return;
  102. int n = 0;
  103. auto slot = makeSubstituteSlot (*entry, &id, &n);
  104. slot.mix = 1.0f;
  105. CHECK (slot.kind == EffectKind::geminiDoubler);
  106. for (const double rate : { 48000.0, 44100.0 })
  107. {
  108. m124::Stereo x;
  109. x.l.assign ((std::size_t) (0.5 * rate), 0.0f);
  110. x.r = x.l;
  111. x.r[1000] = 0.5f;
  112. auto fx = makeEffect (slot);
  113. fx->prepare (rate);
  114. fx->reset();
  115. for (std::size_t off = 0; off < x.l.size(); off += 512)
  116. fx->process (x.l.data() + off, x.r.data() + off, (int) std::min<std::size_t> (512, x.l.size() - off), slot.params, 120.0);
  117. // [EXEC] the trial at 48 and 44.1 kHz: the direct 320 samples late, the 0-cent voice its delay + 495 samples,
  118. // every repeat one sample more, 0.39 × a first-order 16 Hz high-pass (first sample 0.39 × 0.998954)
  119. const auto d = (std::size_t) std::lround (0.1 * rate);
  120. CHECK (std::abs (x.r[1000 + 320] - 0.5f) < 1e-6f);
  121. CHECK (std::abs (x.r[1000 + d + 495] - 0.5f) < 1e-6f);
  122. const auto k = std::tan (3.141592653589793 * 16.0 / rate);
  123. CHECK (std::abs (x.r[1000 + 2 * (d + 495) + 1] - 0.5f * 0.39f * (float) (1.0 / (1.0 + k))) < 1e-5f);
  124. }
  125. // the -1-cent voice drifts by 1 - 2^(-1/1200) samples per sample from 495 (linear reads)
  126. {
  127. m124::Stereo x;
  128. x.l.assign (48000 * 2, 0.0f);
  129. x.r = x.l;
  130. auto s2 = slot;
  131. s2.params[g::directOn] = 0.0f;
  132. s2.params[(std::size_t) g::voiceParam (0, g::vFeedback)] = 0.0f;
  133. const std::size_t at = 48000;
  134. x.l[at] = 1.0f;
  135. const auto y = m124::run (s2, x);
  136. const auto expected = (double) at + 3753.6 + 495.0 + (1.0 - std::pow (2.0, -1.0 / 1200.0)) * (double) (at + 3753.6 + 495.0);
  137. double num = 0.0, den = 0.0;
  138. for (std::size_t i = (std::size_t) expected - 4; i < (std::size_t) expected + 5; ++i)
  139. num += (double) i * y.l[i], den += y.l[i];
  140. CHECK (std::abs (num / den - expected) < 0.05);
  141. }
  142. }
  143. TEST (h_delay_hybrid_engine_matches_the_trial_round124)
  144. {
  145. using namespace lynx;
  146. namespace e = echosuite::echoform;
  147. PluginIdentity id;
  148. id.format = ForeignPlugin::Format::vst3;
  149. id.name = "WaveShell1-VST3 16.0_x64";
  150. id.state = substtest::wavesComponent ("H-Delay", "* 1 120 1000 16 * 100 60 0 0 1 * * * 0 20100 * 19 * 0 0.1 0 * 0");
  151. const auto* entry = findPluginSubstitute (id, false);
  152. CHECK (entry != nullptr);
  153. if (entry == nullptr)
  154. return;
  155. int n = 0;
  156. auto slot = makeSubstituteSlot (*entry, &id, &n);
  157. slot.mix = 1.0f;
  158. CHECK (e::hybridOf (slot.params[e::hybrid]) == 1);
  159. // [EXEC] Analog off, a lone 0 dBFS impulse on the left: (L + R)/√2 through x / (1 + |x|) on every pass
  160. m124::Stereo x;
  161. x.l.assign (48000 * 4, 0.0f);
  162. x.r = x.l;
  163. x.l[1000] = 1.0f;
  164. x.l[1480] = 0.01f; // 10 ms later: the gain is still released only part of the way (one shared 10 ms release)
  165. const auto y = m124::run (slot, x);
  166. CHECK (std::abs (y.l[1000 + 48000] - 0.414212f) < 2e-6f);
  167. CHECK (std::abs (y.r[1000 + 96001] - 0.292893f) < 2e-6f);
  168. CHECK (std::abs (y.l[1000 + 144002] - 0.09538f) < 2e-5f);
  169. CHECK (std::abs (y.l[1480 + 48000] - 0.005994f) < 2e-6f);
  170. // the two lines share their gain: a loud left pass turns the right one down
  171. m124::Stereo z;
  172. z.l.assign (48000 * 3, 0.0f);
  173. z.r = z.l;
  174. for (std::size_t i = 0; i < 4800; ++i)
  175. z.l[1000 + i] = (float) (0.5 * std::sin (2.0 * 3.141592653589793 * 200.0 * (double) i / 48000.0));
  176. for (std::size_t i = 0; i < 4800; ++i)
  177. z.l[49000 + i] = (float) (0.9 * std::sin (2.0 * 3.141592653589793 * 300.0 * (double) i / 48000.0));
  178. const auto w = m124::run (slot, z);
  179. double eLinked = 0.0;
  180. for (std::size_t i = 97001; i < 97001 + 4800; ++i)
  181. eLinked += (double) w.r[i] * w.r[i];
  182. z.l.assign (z.l.size(), 0.0f);
  183. for (std::size_t i = 0; i < 4800; ++i)
  184. z.l[1000 + i] = (float) (0.5 * std::sin (2.0 * 3.141592653589793 * 200.0 * (double) i / 48000.0));
  185. const auto v = m124::run (slot, z);
  186. double eAlone = 0.0;
  187. for (std::size_t i = 97001; i < 97001 + 4800; ++i)
  188. eAlone += (double) v.r[i] * v.r[i];
  189. CHECK (eLinked < eAlone * 0.8);
  190. }