DistructorTests.inc 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include "core/DistructorFx.h"
  2. // Distructor, exact (REA_rodada71): goldens of the installation's Distructor module (Module_x64.dll, run unmodified)
  3. // on module states of our own and this test's input, state loaded before the rate, blocks of 512. Every module type
  4. // except the Harmor shapes (IPP vector math, last-bit differences) and the cabinet (float FFT) is bit-identical; the
  5. // goldens below were printed with 9–17 significant digits, hence the small tolerances.
  6. TEST (distructor_engine)
  7. {
  8. using namespace lynx::distructor;
  9. constexpr int n = 6000;
  10. std::vector<float> inL (n), inR (n);
  11. std::uint32_t s = 12345;
  12. for (int i = 0; i < n; ++i)
  13. {
  14. const double env = (double) (i % 8192) / 8192.0;
  15. for (int c = 0; c < 2; ++c)
  16. {
  17. s = s * 1664525u + 1013904223u;
  18. const auto v = (float) ((double) (std::int32_t) s * 4.656612873077393e-10 * 0.6 * env);
  19. (c == 0 ? inL : inR)[(std::size_t) i] = v;
  20. }
  21. }
  22. struct Case
  23. {
  24. const char* name;
  25. int type, algo, os;
  26. bool dc;
  27. int ftype;
  28. bool smooth;
  29. int mode;
  30. std::vector<std::pair<int, int>> set;
  31. double ss, y100, y2500, y5999, tol;
  32. };
  33. const std::vector<Case> cases {
  34. { "blood", 0, 0, 0, true, 0, true, 0, { { 0, 3000 }, { 1, 7000 }, { 2, 6000 }, { 3, 5000 }, { 4, 4000 }, { 5, 1 } }, 2001.1990785276823, 0.0278644934, -0.601555288, 0.168672472, 1e-8 },
  35. { "fastdist", 0, 1, 1, true, 0, true, 0, { { 16, 150 }, { 17, 6 }, { 18, 100 }, { 19, 90 }, { 20, 1 } }, 143.82232147647986, 0.00746897794, -0.0530273616, 0.117043905, 1e-8 },
  36. { "softclip", 0, 2, 0, false, 0, true, 0, { { 21, 60 }, { 22, 140 }, { 36, 9000 } }, 1312.7187293429124, 0.00815192796, -0.242243469, 0.569292426, 1e-8 },
  37. { "wavefolder", 0, 14, 0, true, 0, true, 0, { { 6, 4000 }, { 7, 6000 }, { 8, 3000 }, { 9, 5000 } }, 1236.1941906718992, -0.49445802, 0.268441975, -0.121243574, 1e-8 },
  38. { "aperture", 0, 15, 0, false, 0, true, 0, { { 10, 3000 }, { 11, 4000 }, { 12, 6000 }, { 13, 3000 }, { 14, 7000 }, { 15, 1 } }, 1090.3262624138356, 0.0248198062, 0.312451929, -0.366700262, 1e-8 },
  39. { "abrasive", 0, 16, 0, true, 0, true, 0, { { 28, 3000 }, { 29, 1000 }, { 30, 7000 }, { 31, 4000 }, { 32, 6000 }, { 33, 1 } }, 239.01098844425007, 0.00306873373, -0.061636474, -0.081221506, 1e-8 },
  40. { "crusher", 0, 17, 2, false, 0, true, 0, { { 34, 4000 }, { 35, 6000 } }, 215.42537704839316, 0.0, -0.0133385342, 0.0485080183, 1e-8 },
  41. { "lp6smooth", 1, 0, 0, true, 0, true, 0, { { 39, 3000 }, { 40, 5000 } }, 3.1195923783758652, 5.37097258e-05, 0.00172995729, -0.0229271241, 1e-8 },
  42. { "peak", 1, 0, 0, true, 12, false, 0, { { 39, 5500 }, { 40, 8000 } }, 592.80632262414531, 0.00598734571, 0.0257016197, -0.0100544095, 1e-8 },
  43. { "lp24alt", 1, 0, 0, true, 11, true, 0, { { 39, 6000 }, { 40, 7000 } }, 9.1666408914450805, 0.0779398531, -0.0234151389, 0.0129876016, 1e-8 },
  44. { "vowel", 1, 0, 0, true, 15, false, 0, { { 39, 4000 }, { 40, 6000 } }, 1284.2456911154554, -0.00385778164, 0.211883456, 1.1561923, 1e-8 },
  45. { "phaser2", 1, 0, 0, true, 17, true, 0, { { 39, 5000 }, { 40, 3000 } }, 532.58466069000406, 0.00691025518, 0.0993106291, -0.175770327, 1e-8 },
  46. { "combminus", 1, 0, 0, true, 14, false, 0, { { 39, 3000 }, { 40, 8000 } }, 327.17195266393452, 0.00354568847, -0.145344049, 0.0769093186, 1e-8 },
  47. { "chorus", 2, 0, 0, true, 0, true, 2, { { 43, 60 }, { 44, 1500 }, { 45, 2500 }, { 46, 2000 }, { 47, 800 }, { 48, 500 } }, 138.33688823977343, 0.00275966898, -0.143275425, 0.00370971859, 1e-8 },
  48. { "flathat", 0, 5, 0, true, 0, true, 0, { { 23, 400 }, { 24, 100 }, { 25, 900 }, { 26, -300 }, { 27, 900 } }, 13.957440036846645, 0.00286740158, -0.028486846, 0.0676169544, 1e-6 },
  49. };
  50. for (const auto& c : cases)
  51. {
  52. auto m = defaultModule ((ModuleType) c.type);
  53. m.algorithm = c.algo, m.oversample = c.os, m.removeDc = c.dc, m.filterType = c.ftype, m.smoothFilter = c.smooth;
  54. m.chorusMode = c.mode;
  55. for (const auto& [k, v] : c.set)
  56. m.p[(std::size_t) k] = v;
  57. State st;
  58. st.modules.push_back (m);
  59. st.clip = false;
  60. // the FL layout round trip
  61. const auto parsed = parse (serialize (st));
  62. CHECK (parsed && parsed->modules.size() == 1 && parsed->modules[0].p == m.p && parsed->modules[0].filterType == m.filterType);
  63. Engine e;
  64. e.prepare (44100.0, 512);
  65. e.set (st);
  66. auto l = inL, r = inR;
  67. for (int i = 0; i < n; i += 512)
  68. e.process (l.data() + i, r.data() + i, std::min (512, n - i));
  69. double ss = 0;
  70. for (int i = 0; i < n; ++i)
  71. ss += (double) l[(std::size_t) i] * l[(std::size_t) i] + (double) r[(std::size_t) i] * r[(std::size_t) i];
  72. const bool ok = std::abs (ss - c.ss) < c.tol * std::max (1.0, c.ss) && std::abs (l[100] - c.y100) < c.tol + 1e-9
  73. && std::abs (r[2500] - c.y2500) < c.tol + 1e-9 && std::abs (l[5999] - c.y5999) < c.tol + 1e-9;
  74. if (! ok)
  75. std::printf (" %s: ss %.17g y %.9g %.9g %.9g\n", c.name, ss, l[100], r[2500], l[5999]);
  76. CHECK (ok);
  77. }
  78. // the slot blob keeps the FL state and the impulse files; the slot parameters follow FL's controls
  79. State st;
  80. st.modules.push_back (defaultModule (ModuleType::ampCab));
  81. st.modules.push_back (defaultModule (ModuleType::distortion));
  82. st.modules[0].impulse = 21;
  83. const auto fl = serialize (st);
  84. const auto blob = packBlob (fl, { { 21, std::vector<std::uint8_t> { 1, 2, 3 } } });
  85. const auto back = parseBlob (blob);
  86. CHECK (back && back->modules.size() == 2 && back->modules[0].impulseFile.size() == 3 && back->modules[1].impulseFile.empty());
  87. CHECK (impulsesUsed (st) == std::vector<int> { 21 } && impulsePath (21).find ("IMP Cabinet Mono Closest.wv") != std::string::npos);
  88. std::array<float, effectParams> p {};
  89. toParams (st, p.data());
  90. CHECK (p[0] == 0.5f && p[1] == 1.0f && p[2] == 0.5f && p[12] == 1.0f && p[6] == 0.0f);
  91. // with the installation: the cabinet impulses decode and every demo-project Distructor imports exactly (see the
  92. // real-FLP survey); here the Amp/Cab module must produce sound from an installation impulse
  93. if (! realFlpDir.empty())
  94. {
  95. const auto folder = std::filesystem::path (realFlpDir).parent_path() / "Plugins" / "Fruity" / "Effects" / "Distructor" / "module" / "impulses";
  96. if (std::filesystem::exists (folder))
  97. {
  98. setImpulseFolder (folder.string());
  99. State cab;
  100. cab.modules.push_back (defaultModule (ModuleType::ampCab));
  101. cab.modules[0].impulse = 1;
  102. cab.modules[0].p[37] = 10000;
  103. Engine e;
  104. e.prepare (44100.0, 512);
  105. e.set (cab);
  106. auto l = inL, r = inR;
  107. for (int i = 0; i < n; i += 512)
  108. e.process (l.data() + i, r.data() + i, std::min (512, n - i));
  109. double ss = 0;
  110. for (int i = 0; i < n; ++i)
  111. ss += (double) l[(std::size_t) i] * l[(std::size_t) i];
  112. CHECK (ss > 1.0);
  113. setImpulseFolder ({});
  114. }
  115. }
  116. }