LynxVerbs.cpp 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410
  1. #include "core/LynxVerbs.h"
  2. #include <algorithm>
  3. #include <cmath>
  4. #include <cstdint>
  5. #include <cstdio>
  6. #include "core/Biquad.h"
  7. #include "core/Effects.h"
  8. namespace lynx::verbs
  9. {
  10. namespace
  11. {
  12. constexpr double pi = 3.14159265358979323846;
  13. constexpr int lineCount = 8;
  14. // Line-length sets of the late tank, ms at lineScale 1 (spread over about an octave, no common factors, so the
  15. // modes of the lines do not line up). The last set is a ratio set (× lineScale in ms) for delay networks.
  16. constexpr double shapes[][lineCount] = {
  17. { 37.1, 41.9, 47.3, 53.9, 61.1, 67.7, 74.3, 83.9 }, // 0 hall
  18. { 21.1, 24.7, 28.3, 32.9, 37.3, 41.9, 46.1, 51.7 }, // 1 room / chamber
  19. { 29.3, 33.1, 38.9, 44.3, 51.7, 57.1, 63.7, 71.3 }, // 2 plate
  20. { 0.031, 0.117, 0.229, 0.357, 0.493, 0.641, 0.809, 1.000 }, // 3 delay network (fractions of the delay, see lineSpread)
  21. };
  22. constexpr int shapeCount = (int) (sizeof (shapes) / sizeof (shapes[0]));
  23. // input diffusers: J. Dattorro's lengths (142, 107, 379, 277 samples at 29761 Hz), the right channel slightly apart
  24. constexpr double inApMs[2][4] = { { 4.771, 3.595, 12.735, 9.307 }, { 4.513, 3.871, 11.913, 8.711 } };
  25. constexpr double inApCoef[4] = { 0.75, 0.75, 0.625, 0.625 };
  26. // in-loop all-pass length as a fraction of its line, early smearing all-passes (ms)
  27. constexpr double loopApFraction = 0.16;
  28. constexpr double earlyApMs[2][2] = { { 7.13, 2.31 }, { 6.47, 2.83 } };
  29. constexpr int earlyTaps = 14;
  30. constexpr int buildTaps = 40;
  31. // a small deterministic generator for tap patterns (the same pattern on every machine)
  32. struct Lcg
  33. {
  34. std::uint32_t s;
  35. double next() noexcept
  36. {
  37. s = s * 1664525u + 1013904223u;
  38. return (double) (s >> 8) / 16777216.0;
  39. }
  40. };
  41. inline int nextPow2 (int n)
  42. {
  43. int p = 1;
  44. while (p < n)
  45. p <<= 1;
  46. return p;
  47. }
  48. struct Line
  49. {
  50. std::vector<float> buf;
  51. int mask = 0, pos = 0;
  52. void allocate (int samples)
  53. {
  54. const auto n = nextPow2 (std::max (4, samples + 4));
  55. buf.assign ((std::size_t) n, 0.0f);
  56. mask = n - 1;
  57. pos = 0;
  58. }
  59. void clear() noexcept
  60. {
  61. std::fill (buf.begin(), buf.end(), 0.0f);
  62. pos = 0;
  63. }
  64. void write (float x) noexcept
  65. {
  66. buf[(std::size_t) pos] = x;
  67. pos = (pos + 1) & mask;
  68. }
  69. // d ≥ 1: the sample written d writes ago
  70. float read (int d) const noexcept { return buf[(std::size_t) ((pos - d) & mask)]; }
  71. // fractional delay (≥ 2), 4-point Hermite
  72. float readFrac (double d) const noexcept
  73. {
  74. const auto i = (int) d;
  75. const auto f = (float) (d - i);
  76. const auto xm1 = read (i - 1), x0 = read (i), x1 = read (i + 1), x2 = read (i + 2);
  77. const auto c1 = 0.5f * (x1 - xm1);
  78. const auto c2 = xm1 - 2.5f * x0 + 2.0f * x1 - 0.5f * x2;
  79. const auto c3 = 0.5f * (x2 - xm1) + 1.5f * (x0 - x1);
  80. return ((c3 * f + c2) * f + c1) * f + x0;
  81. }
  82. };
  83. struct Allpass
  84. {
  85. Line line;
  86. int len = 1;
  87. float process (float x, float g) noexcept
  88. {
  89. const auto d = line.read (len);
  90. const auto v = x + g * d;
  91. line.write (v);
  92. return d - g * v;
  93. }
  94. };
  95. struct OnePole
  96. {
  97. float a = 0.0f, z = 0.0f;
  98. void setLowpass (double hz, double sr) noexcept { a = (float) std::exp (-2.0 * pi * std::clamp (hz, 1.0, sr * 0.49) / sr); }
  99. float lp (float x) noexcept { return z = x + a * (z - x); }
  100. };
  101. // the two-head pitch shifter (also plays backwards: ratio −1)
  102. struct Shifter
  103. {
  104. Line line;
  105. double phase = 0.0, window = 2400.0;
  106. void prepare (double sr, double windowSec)
  107. {
  108. window = std::max (64.0, windowSec * sr);
  109. line.allocate ((int) (window * 2.5) + 8);
  110. phase = 0.0;
  111. }
  112. void clear() noexcept
  113. {
  114. line.clear();
  115. phase = 0.0;
  116. }
  117. float process (float x, double ratio) noexcept
  118. {
  119. line.write (x);
  120. phase += (1.0 - ratio) / window;
  121. phase -= std::floor (phase);
  122. float y = 0.0f;
  123. for (int h = 0; h < 2; ++h)
  124. {
  125. auto p = phase + 0.5 * h;
  126. p -= std::floor (p);
  127. const auto w = (float) std::sin (pi * p);
  128. y += w * w * line.readFrac (2.0 + p * window);
  129. }
  130. return y;
  131. }
  132. };
  133. double clampPos (double v, double lo, double hi) noexcept { return std::isfinite (v) ? std::clamp (v, lo, hi) : lo; }
  134. } // namespace
  135. // =================================================================================================================
  136. // laws
  137. double skewLaw (double v, double lo, double hi, double k) noexcept
  138. {
  139. return lo + (hi - lo) * std::pow (std::clamp (v, 0.0, 1.0), k);
  140. }
  141. double skewInverse (double unit, double lo, double hi, double k) noexcept
  142. {
  143. return std::pow (std::clamp ((unit - lo) / (hi - lo), 0.0, 1.0), 1.0 / k);
  144. }
  145. double knotLaw (double v, const double* knots, int count) noexcept
  146. {
  147. v = std::clamp (v, knots[0], knots[2 * (count - 1)]);
  148. for (int i = 1; i < count; ++i)
  149. if (v <= knots[2 * i] || i == count - 1)
  150. {
  151. const auto v0 = knots[2 * i - 2], v1 = knots[2 * i];
  152. const auto u0 = knots[2 * i - 1], u1 = knots[2 * i + 1];
  153. return v1 > v0 ? u0 + (u1 - u0) * (v - v0) / (v1 - v0) : u1;
  154. }
  155. return knots[1];
  156. }
  157. double knotInverse (double unit, const double* knots, int count) noexcept
  158. {
  159. unit = std::clamp (unit, knots[1], knots[2 * count - 1]);
  160. for (int i = 1; i < count; ++i)
  161. if (unit <= knots[2 * i + 1] || i == count - 1)
  162. {
  163. const auto v0 = knots[2 * i - 2], v1 = knots[2 * i];
  164. const auto u0 = knots[2 * i - 1], u1 = knots[2 * i + 1];
  165. return u1 > u0 ? v0 + (v1 - v0) * (unit - u0) / (u1 - u0) : v0;
  166. }
  167. return knots[0];
  168. }
  169. int choice (float v, int count) noexcept
  170. {
  171. if (count <= 1)
  172. return 0;
  173. return std::clamp ((int) std::lround (std::clamp ((double) v, 0.0, 1.0) * (count - 1)), 0, count - 1);
  174. }
  175. void mixGains (float mix, float& dry, float& wet) noexcept
  176. {
  177. const auto m = std::clamp ((double) mix, 0.0, 1.0) * pi * 0.5;
  178. dry = (float) std::cos (m);
  179. wet = (float) std::sin (m);
  180. if (mix >= 1.0f)
  181. dry = 0.0f;
  182. if (mix <= 0.0f)
  183. wet = 0.0f;
  184. }
  185. // =================================================================================================================
  186. // engine
  187. struct Engine::Impl
  188. {
  189. double sr = 48000.0, maxLineSec, maxPreSec;
  190. Line pre[2], raw[2], dif[2];
  191. Allpass inAp[2][4], earlyAp[2][2];
  192. Line lines[lineCount];
  193. Allpass loopAp[lineCount];
  194. struct Absorb
  195. {
  196. OnePole lo, hi, bw, lc;
  197. float gL = 1, gM = 1, gH = 1;
  198. } absorb[lineCount];
  199. double curLen[lineCount] {}; // glided line lengths (samples)
  200. double lfo[lineCount] {};
  201. Shifter shifters[4]; // inside lines 0, 2, 4, 6 (shimmer)
  202. Biquad outLow, outHigh, shelfLow, shelfHigh, band1, band2;
  203. bool outLowOn = false, outHighOn = false, shelfLowOn = false, shelfHighOn = false, bandOn = false;
  204. // tap patterns (unit times and gains), drawn once
  205. double eT[2][earlyTaps] {}, eG[2][earlyTaps] {};
  206. double bT[2][buildTaps] {}, bG[2][buildTaps] {};
  207. int eD[2][earlyTaps] {}, bD[2][buildTaps] {};
  208. float eW[2][earlyTaps] {}, bW[2][buildTaps] {};
  209. Settings last;
  210. bool first = true;
  211. float shiftState = 0.0f;
  212. float apG[lineCount] {}, inG[4] {}, eApG = 0;
  213. double modDepth = 0, modInc[lineCount] {};
  214. double feedbackGain = -1;
  215. Impl (double maxLine, double maxPre) : maxLineSec (maxLine), maxPreSec (maxPre)
  216. {
  217. Lcg r { 0x2545F491u };
  218. for (int c = 0; c < 2; ++c)
  219. {
  220. for (int k = 0; k < earlyTaps; ++k)
  221. {
  222. eT[c][k] = (k + 0.15 + 0.7 * r.next()) / earlyTaps;
  223. eG[c][k] = r.next() < 0.5 ? -1.0 : 1.0;
  224. }
  225. for (int k = 0; k < buildTaps; ++k)
  226. {
  227. bT[c][k] = (k + 0.1 + 0.8 * r.next()) / buildTaps;
  228. bG[c][k] = r.next() < 0.5 ? -1.0 : 1.0;
  229. }
  230. }
  231. }
  232. void prepare (double rate)
  233. {
  234. sr = rate;
  235. const auto ms = sr / 1000.0;
  236. for (int c = 0; c < 2; ++c)
  237. {
  238. pre[c].allocate ((int) (maxPreSec * sr) + 8);
  239. raw[c].allocate ((int) (1.05 * sr) + 8);
  240. dif[c].allocate ((int) (2.05 * sr) + 8);
  241. for (int k = 0; k < 4; ++k)
  242. {
  243. inAp[c][k].len = std::max (1, (int) std::lround (inApMs[c][k] * ms));
  244. inAp[c][k].line.allocate (inAp[c][k].len + 2);
  245. }
  246. for (int k = 0; k < 2; ++k)
  247. {
  248. earlyAp[c][k].len = std::max (1, (int) std::lround (earlyApMs[c][k] * ms));
  249. earlyAp[c][k].line.allocate (earlyAp[c][k].len + 2);
  250. }
  251. }
  252. const auto maxLine = (int) (maxLineSec * sr) + 16;
  253. for (int i = 0; i < lineCount; ++i)
  254. {
  255. lines[i].allocate (maxLine + (int) (0.05 * sr));
  256. loopAp[i].line.allocate ((int) (0.2 * maxLineSec * sr) + 8);
  257. }
  258. for (auto& sh : shifters)
  259. sh.prepare (sr, 0.06);
  260. reset();
  261. }
  262. void reset() noexcept
  263. {
  264. for (int c = 0; c < 2; ++c)
  265. {
  266. pre[c].clear();
  267. raw[c].clear();
  268. dif[c].clear();
  269. for (auto& a : inAp[c])
  270. a.line.clear();
  271. for (auto& a : earlyAp[c])
  272. a.line.clear();
  273. }
  274. for (int i = 0; i < lineCount; ++i)
  275. {
  276. lines[i].clear();
  277. loopAp[i].line.clear();
  278. absorb[i].lo.z = absorb[i].hi.z = absorb[i].bw.z = absorb[i].lc.z = 0.0f;
  279. lfo[i] = 2.0 * pi * i / lineCount;
  280. }
  281. for (auto& sh : shifters)
  282. sh.clear();
  283. outLow.reset();
  284. outHigh.reset();
  285. shelfLow.reset();
  286. shelfHigh.reset();
  287. band1.reset();
  288. band2.reset();
  289. shiftState = 0.0f;
  290. first = true;
  291. }
  292. double targetLen (const Settings& s, int i) const noexcept
  293. {
  294. const auto shape = std::clamp (s.shape, 0, shapeCount - 1);
  295. const auto spread = std::clamp (s.lineSpread, 0.0, 1.0);
  296. const auto ms = shape == 3 ? std::max (0.0, s.lineScale) * (1.0 - spread * (1.0 - shapes[3][i]))
  297. : shapes[shape][i] * std::max (0.0, s.lineScale);
  298. return clampPos (ms * sr / 1000.0, 8.0, maxLineSec * sr);
  299. }
  300. // coefficients that depend on the settings (once per block)
  301. void update (const Settings& s) noexcept
  302. {
  303. const auto ms = sr / 1000.0;
  304. for (int k = 0; k < 4; ++k)
  305. inG[k] = (float) (inApCoef[k] * std::clamp (s.inDiffusion, 0.0, 1.0));
  306. eApG = (float) (0.7 * std::clamp (s.earlyDiffusion, 0.0, 1.0));
  307. // tap delays and gains: early (energy-normalised, falling) and build-up (rising then falling, sum of squares 1)
  308. for (int c = 0; c < 2; ++c)
  309. {
  310. double e = 0, b = 0;
  311. for (int k = 0; k < earlyTaps; ++k)
  312. {
  313. eD[c][k] = std::clamp ((int) (eT[c][k] * std::max (0.0005, s.earlySec) * sr), 1, raw[c].mask - 4);
  314. const auto a = std::exp (-s.earlyDecay * eT[c][k]);
  315. eW[c][k] = (float) (a * eG[c][k]);
  316. e += a * a;
  317. }
  318. for (auto& w : eW[c])
  319. w = (float) (w / std::sqrt (std::max (e, 1e-9)));
  320. const auto gated = s.gateSec > 0.0;
  321. const auto span = gated ? s.gateSec : s.buildSec;
  322. for (int k = 0; k < buildTaps; ++k)
  323. {
  324. bD[c][k] = std::clamp ((int) (bT[c][k] * span * sr), 0, dif[c].mask - 4);
  325. const auto u = bT[c][k];
  326. const auto a = gated ? 0.6 + 0.4 * u : std::sin (pi * std::sqrt (u)); // build: rises, then falls
  327. bW[c][k] = (float) (a * bG[c][k]);
  328. b += a * a;
  329. }
  330. for (auto& w : bW[c])
  331. w = (float) (w / std::sqrt (std::max (b, 1e-9)));
  332. }
  333. // modulation
  334. modDepth = std::max (0.0, s.modDepthMs) * ms;
  335. for (int i = 0; i < lineCount; ++i)
  336. modInc[i] = 2.0 * pi * std::max (0.0, s.modRateHz) * (1.0 + 0.137 * i - 0.019 * i * i * 0.5) / sr;
  337. // loop filters
  338. for (int i = 0; i < lineCount; ++i)
  339. {
  340. auto& a = absorb[i];
  341. a.lo.setLowpass (std::max (20.0, s.lowXover), sr);
  342. a.hi.setLowpass (std::max (20.0, s.highXover), sr);
  343. if (s.loopBandwidth > 0.0 && s.loopBandwidth < 0.49 * sr)
  344. a.bw.setLowpass (s.loopBandwidth, sr);
  345. else
  346. a.bw.a = 0.0f;
  347. if (s.loopLowCut > 0.0)
  348. a.lc.setLowpass (s.loopLowCut, sr);
  349. else
  350. a.lc.a = 1.0f;
  351. apG[i] = (float) (0.6 * std::clamp (s.loopDiffusion, 0.0, 1.0));
  352. }
  353. // output filters
  354. outLowOn = s.outLowCut > 0.0;
  355. if (outLowOn)
  356. {
  357. if (s.outLowOrder == 1) // first order (bilinear)
  358. {
  359. const auto k = std::tan (pi * std::min (s.outLowCut, 0.45 * sr) / sr);
  360. outLow.set (1.0, -1.0, 0.0, 1.0 + k, k - 1.0, 0.0);
  361. }
  362. else
  363. outLow.filter (sr, 1, s.outLowCut, 0.7071);
  364. }
  365. outHighOn = s.outHighCut > 0.0 && s.outHighCut < 0.45 * sr;
  366. if (outHighOn)
  367. {
  368. if (s.outHighOrder == 1)
  369. {
  370. const auto k = std::tan (pi * s.outHighCut / sr);
  371. outHigh.set (k, k, 0.0, 1.0 + k, k - 1.0, 0.0);
  372. }
  373. else
  374. outHigh.filter (sr, 0, s.outHighCut, 0.7071);
  375. }
  376. bandOn = s.bandLimit > 0.0 && s.bandLimit < 0.45 * sr;
  377. if (bandOn)
  378. {
  379. band1.filter (sr, 0, s.bandLimit, 0.5412); // 4th-order Butterworth as two sections
  380. band2.filter (sr, 0, s.bandLimit, 1.3066);
  381. }
  382. shelfLowOn = std::abs (s.lowShelfDb) > 0.01;
  383. if (shelfLowOn)
  384. shelfLow.shelf (sr, s.lowShelfHz, s.lowShelfDb, false, 0.7);
  385. shelfHighOn = std::abs (s.highShelfDb) > 0.01;
  386. if (shelfHighOn)
  387. shelfHigh.shelf (sr, std::min (s.highShelfHz, 0.45 * sr), s.highShelfDb, true, 0.7);
  388. }
  389. // per-line gains for the current lengths (cheap: once per block)
  390. void decayGains (const Settings& s) noexcept
  391. {
  392. for (int i = 0; i < lineCount; ++i)
  393. {
  394. auto& a = absorb[i];
  395. const auto len = curLen[i] + (apG[i] != 0.0f ? (double) loopAp[i].len : 0.0);
  396. if (s.feedback >= 0.0)
  397. {
  398. const auto g = std::min (0.99995, s.feedback);
  399. a.gM = (float) g;
  400. a.gL = (float) std::min (0.99995, std::pow (g, 1.0 / std::max (0.05, s.lowMult)));
  401. a.gH = (float) std::min (0.99995, std::pow (g, 1.0 / std::max (0.05, s.highMult)));
  402. continue;
  403. }
  404. const auto rt = std::max (0.01, s.gateSec > 0.0 ? std::min (s.rt60, 0.12) : s.rt60);
  405. auto gain = [&] (double mult) { return (float) std::min (0.99995, std::pow (10.0, -3.0 * len / (rt * std::max (0.02, mult) * sr))); };
  406. a.gM = gain (1.0);
  407. a.gL = gain (s.lowMult);
  408. a.gH = gain (s.highMult);
  409. }
  410. }
  411. void process (float* L, float* R, int n, const Settings& s) noexcept
  412. {
  413. update (s);
  414. const auto pd = std::clamp ((int) std::lround (s.predelaySec * sr), 0, pre[0].mask - 2);
  415. // loop all-pass lengths follow the line lengths (fixed per block)
  416. for (int i = 0; i < lineCount; ++i)
  417. {
  418. const auto target = targetLen (s, i);
  419. if (first)
  420. curLen[i] = target;
  421. loopAp[i].len = std::clamp ((int) (target * loopApFraction), 1, loopAp[i].line.mask - 2);
  422. }
  423. first = false;
  424. decayGains (s);
  425. const auto glide = 0.25; // samples per sample: a length change glides like tape
  426. const auto norm = (float) (1.0 / std::sqrt ((double) lineCount));
  427. const auto early = (float) s.earlyLevel, late = (float) s.lateLevel, send = (float) s.earlySend;
  428. const auto gated = s.gateSec > 0.0, build = gated || s.buildSec > 0.0005;
  429. const auto parallel = s.parallelLines;
  430. const auto crossAngle = parallel ? 0.0 : 0.25 * pi * std::clamp (s.crossFeed, 0.0, 1.0);
  431. const auto crossCos = (float) std::cos (crossAngle), crossSin = (float) std::sin (crossAngle);
  432. const auto ratio = std::pow (2.0, s.shiftSemis / 12.0), ratio2 = std::pow (2.0, s.shiftSemis2 / 12.0);
  433. const auto voice2 = (float) std::clamp (s.shift2Mix, 0.0, 1.0);
  434. // shimmer: a part of what four of the lines write back goes through a pitch shifter. (1 − a)² + a² ≤ 1 and
  435. // the shifted part is decorrelated, so the loop keeps the decay the absorption filters set: always stable
  436. const auto shimmer = (float) (std::clamp (s.shiftFeedback, 0.0, 1.0) * std::clamp (s.shiftMix, 0.0, 1.0));
  437. const auto width = (float) std::clamp (s.width, -2.0, 2.0), gain = (float) s.gain;
  438. double target[lineCount];
  439. for (int i = 0; i < lineCount; ++i)
  440. target[i] = targetLen (s, i);
  441. for (int t = 0; t < n; ++t)
  442. {
  443. float x[2] = { L[t], R[t] };
  444. float e[2], d[2];
  445. for (int c = 0; c < 2; ++c)
  446. {
  447. pre[c].write (x[c]);
  448. const auto p = pd == 0 ? x[c] : pre[c].read (pd);
  449. raw[c].write (p);
  450. // early reflections
  451. float er = 0.0f;
  452. if (early != 0.0f || send != 0.0f)
  453. for (int k = 0; k < earlyTaps; ++k)
  454. er += eW[c][k] * raw[c].read (eD[c][k]);
  455. if (eApG != 0.0f)
  456. for (auto& a : earlyAp[c])
  457. er = a.process (er, eApG);
  458. e[c] = er;
  459. // input diffusion
  460. auto v = p;
  461. for (int k = 0; k < 4; ++k)
  462. if (inG[k] != 0.0f)
  463. v = inAp[c][k].process (v, inG[k]);
  464. if (build)
  465. {
  466. dif[c].write (v);
  467. float b = 0.0f;
  468. for (int k = 0; k < buildTaps; ++k)
  469. b += bW[c][k] * (bD[c][k] == 0 ? v : dif[c].read (bD[c][k]));
  470. v = b;
  471. }
  472. d[c] = v;
  473. }
  474. // late tank
  475. float sOut[lineCount];
  476. for (int i = 0; i < lineCount; ++i)
  477. {
  478. curLen[i] += std::clamp (target[i] - curLen[i], -glide, glide);
  479. lfo[i] += modInc[i];
  480. if (lfo[i] > 2.0 * pi)
  481. lfo[i] -= 2.0 * pi;
  482. const auto dl = std::max (2.0, curLen[i] - modDepth * 0.5 * (1.0 + std::sin (lfo[i])));
  483. auto y = lines[i].readFrac (dl);
  484. if (apG[i] != 0.0f)
  485. y = loopAp[i].process (y, apG[i]);
  486. auto& a = absorb[i];
  487. const auto lo = a.lo.lp (y), hiLp = a.hi.lp (y);
  488. y = a.gM * y + (a.gL - a.gM) * lo + (a.gH - a.gM) * (y - hiLp);
  489. if (a.bw.a != 0.0f)
  490. y = a.bw.lp (y);
  491. if (a.lc.a != 1.0f)
  492. y -= a.lc.lp (y);
  493. sOut[i] = y;
  494. }
  495. // outputs: two orthogonal sign patterns
  496. // (neither pattern sums to zero, so low frequencies, where the lines move together, are kept)
  497. float lateL = (sOut[0] + sOut[1] + sOut[2] - sOut[3] + sOut[4] + sOut[5] - sOut[6] + sOut[7]) * norm;
  498. float lateR = (sOut[0] - sOut[1] + sOut[2] + sOut[3] + sOut[4] - sOut[5] + sOut[6] + sOut[7]) * norm;
  499. const float in[2] = { d[0] + send * e[0], d[1] + send * e[1] };
  500. if (gated)
  501. {
  502. // gated: the dense tap block is the sound; the short tank only smooths it
  503. lateL = 0.3f * lateL + d[0];
  504. lateR = 0.3f * lateR + d[1];
  505. }
  506. // mixing: each half of the tank (lines 0–3 fed from the left, 4–7 from the right) through a normalised 4-point
  507. // Hadamard, then the halves rotated into each other by crossFeed × 45° (orthogonal for any amount)
  508. float h[lineCount];
  509. if (parallel)
  510. for (int i = 0; i < lineCount; ++i)
  511. h[i] = sOut[i];
  512. for (int half = 0; half < lineCount && ! parallel; half += 4)
  513. {
  514. const auto a0 = sOut[half] + sOut[half + 1], a1 = sOut[half] - sOut[half + 1];
  515. const auto a2 = sOut[half + 2] + sOut[half + 3], a3 = sOut[half + 2] - sOut[half + 3];
  516. h[half] = 0.5f * (a0 + a2);
  517. h[half + 1] = 0.5f * (a1 + a3);
  518. h[half + 2] = 0.5f * (a0 - a2);
  519. h[half + 3] = 0.5f * (a1 - a3);
  520. }
  521. for (int i = 0; i < 4; ++i)
  522. {
  523. const auto a = h[i], b = h[i + 4];
  524. // parallel lines (plain echoes): input signs = the output patterns of their own side, so the left input
  525. // reaches only the left output and the right only the right
  526. constexpr float injL[4] = { 0.5f, 0.5f, 0.5f, -0.5f }, injR[4] = { 0.5f, -0.5f, 0.5f, 0.5f };
  527. auto u = crossCos * a + crossSin * b, w = -crossSin * a + crossCos * b;
  528. if (shimmer > 0.0f && (i & 1) == 0)
  529. {
  530. // the second voice (dual modes) takes line 2 and line 6
  531. const auto r = i == 2 && voice2 > 0.0f ? ratio2 : ratio;
  532. const auto amount = i == 2 && voice2 > 0.0f ? shimmer * voice2 : shimmer;
  533. u = (1.0f - amount) * u + amount * shifters[i / 2].process (u, r);
  534. w = (1.0f - amount) * w + amount * shifters[2 + i / 2].process (w, i == 2 && voice2 > 0.0f ? ratio2 : ratio);
  535. }
  536. const auto alt = (i & 1) == 0 ? 0.5f : -0.5f; // reverbs: decorrelated sides from the first pass on
  537. lines[i].write (u + (parallel ? injL[i] : alt) * in[0]);
  538. lines[i + 4].write (w + (parallel ? injR[i] : alt) * in[1]);
  539. }
  540. auto ol = late * lateL + early * e[0];
  541. auto orr = late * lateR + early * e[1];
  542. // width (M/S)
  543. const auto mid = 0.5f * (ol + orr), side = 0.5f * (ol - orr) * width;
  544. L[t] = (mid + side) * gain;
  545. R[t] = (mid - side) * gain;
  546. }
  547. if (outLowOn)
  548. outLow.processBlock (L, R, n);
  549. if (outHighOn)
  550. outHigh.processBlock (L, R, n);
  551. if (bandOn)
  552. {
  553. band1.processBlock (L, R, n);
  554. band2.processBlock (L, R, n);
  555. }
  556. if (shelfLowOn)
  557. shelfLow.processBlock (L, R, n);
  558. if (shelfHighOn)
  559. shelfHigh.processBlock (L, R, n);
  560. last = s;
  561. }
  562. };
  563. Engine::Engine (double maxLineSec, double maxPredelaySec) : impl (std::make_unique<Impl> (maxLineSec, maxPredelaySec)) {}
  564. Engine::~Engine() = default;
  565. void Engine::prepare (double sampleRate) { impl->prepare (sampleRate); }
  566. void Engine::reset() noexcept { impl->reset(); }
  567. void Engine::process (float* left, float* right, int n, const Settings& s) noexcept { impl->process (left, right, n, s); }
  568. // =================================================================================================================
  569. // front-ends
  570. namespace
  571. {
  572. // a 0..1 control as % text
  573. std::string pct (double v) { char b[32]; std::snprintf (b, sizeof b, "%.0f%%", v * 100.0); return b; }
  574. std::string fmt (const char* f, double v) { char b[48]; std::snprintf (b, sizeof b, f, v); return b; }
  575. std::string hz (double v) { return v >= 1000.0 ? fmt ("%.2f kHz", v / 1000.0) : fmt ("%.0f Hz", v); }
  576. std::string ms (double v) { return v >= 1000.0 ? fmt ("%.2f s", v / 1000.0) : fmt ("%.1f ms", v); }
  577. std::string sec (double v) { return v >= 10.0 ? fmt ("%.1f s", v) : fmt ("%.2f s", v); }
  578. // the decay a front-end asks for, with a floor for modes whose structure cannot decay faster (measured)
  579. double withFloor (double rt, double floor) { return std::sqrt (rt * rt + floor * floor); }
  580. // note lengths of the tempo-synced delays (quarter notes)
  581. constexpr double noteQuarters[] = { 1.0 / 16, 1.0 / 8, 1.0 / 4, 1.0 / 2, 1.0, 2.0, 4.0 };
  582. const char* const noteNames[] = { "1/64", "1/32", "1/16", "1/8", "1/4", "1/2", "1/1" };
  583. // Delay time of a synced control set: sync 0 = ms, 1 = note, 2 = dotted, 3 = triplet
  584. double syncedMs (int sync, int note, double msValue, double bpm)
  585. {
  586. if (sync <= 0 || bpm <= 0.0)
  587. return msValue;
  588. auto q = noteQuarters[std::clamp (note, 0, 6)] * 60000.0 / bpm;
  589. if (sync == 2)
  590. q *= 1.5;
  591. else if (sync == 3)
  592. q *= 2.0 / 3.0;
  593. return q;
  594. }
  595. class VerbEffect : public Effect
  596. {
  597. public:
  598. VerbEffect (EffectKind k, double maxLineSec, double maxPreSec) : kind (k), engine (maxLineSec, maxPreSec) {}
  599. void prepare (double sampleRate) noexcept override
  600. {
  601. rate = sampleRate;
  602. engine.prepare (sampleRate);
  603. }
  604. void reset() noexcept override { engine.reset(); }
  605. void process (float* left, float* right, int n, const EffectParams& p, double bpm) noexcept override
  606. {
  607. Settings s;
  608. float mix = 1.0f;
  609. configure (p, bpm, s, mix);
  610. float dry, wet;
  611. mixGains (mix, dry, wet);
  612. for (int start = 0; start < n; start += chunk)
  613. {
  614. const auto m = std::min (chunk, n - start);
  615. auto* l = left + start;
  616. auto* r = right + start;
  617. std::copy (l, l + m, dl.begin());
  618. std::copy (r, r + m, dr.begin());
  619. preStage (l, r, m, p, bpm);
  620. engine.process (l, r, m, s);
  621. postStage (l, r, m, p, bpm);
  622. for (int i = 0; i < m; ++i)
  623. {
  624. l[i] = dry * dl[(std::size_t) i] + wet * l[i];
  625. r[i] = dry * dr[(std::size_t) i] + wet * r[i];
  626. }
  627. }
  628. }
  629. protected:
  630. virtual void configure (const EffectParams& p, double bpm, Settings& s, float& mix) const noexcept = 0;
  631. virtual void preStage (float*, float*, int, const EffectParams&, double) noexcept {}
  632. virtual void postStage (float*, float*, int, const EffectParams&, double) noexcept {}
  633. static constexpr int chunk = 1024;
  634. EffectKind kind;
  635. Engine engine;
  636. double rate = 48000.0;
  637. std::array<float, chunk> dl {}, dr {};
  638. };
  639. // ---------------------------------------------------------------------------------------------- Epoch Verb
  640. // Laws [EXEC, REA_rodada100 §1]: predelay 0..500 ms (v^2.32), decay 0.2..70 s (v^3.36), bass mult 0.25..4 X (v^2.32),
  641. // bass crossover 100..10000 Hz (v^4.04), high shelf −24..0 dB, high freq / high cut 100..20000 Hz (v^1.754),
  642. // mod rate 0.1..10 Hz, low cut 10..1500 Hz.
  643. struct EpochMode
  644. {
  645. const char* name;
  646. int shape;
  647. double scale, rtScale, rtFloor, lowRt, inDiff, early, earlyMs, buildMs, modScale, gain, preMs, gate;
  648. };
  649. // shape, line scale, RT / Decay, RT floor (s), bass RT ×, input diffusion, early level / span (ms), build-up (ms),
  650. // modulation scale, output gain, own pre-delay (ms), gate (fraction of the decay; 0 = none) — fitted to §1.
  651. const EpochMode epochModes[epoch::modeCount] = {
  652. { "Concert Hall", 0, 1.00, 1.06, 1.20, 1.0, 1.0, 0.55, 9.0, 0.0, 1.0, 0.91, 5.0, 0.0 },
  653. { "Plate", 2, 0.80, 0.90, 0.45, 1.0, 1.0, 0.10, 2.0, 60.0, 1.0, 0.70, 2.0, 0.0 },
  654. { "Room", 1, 0.85, 1.02, 0.45, 1.0, 1.0, 0.10, 20.0, 150.0, 1.0, 0.82, 1.0, 0.0 },
  655. { "Chamber", 1, 1.00, 1.04, 0.45, 1.0, 1.0, 0.15, 30.0, 140.0, 1.0, 0.70, 1.2, 0.0 },
  656. { "Random Space", 0, 1.10, 1.00, 0.90, 1.0, 1.0, 0.00, 1.0, 220.0, 2.0, 1.50, 15.0, 0.0 },
  657. { "Chorus Space", 0, 1.10, 1.00, 1.10, 1.0, 1.0, 0.05, 40.0, 280.0, 3.0, 0.70, 9.0, 0.0 },
  658. { "Ambience", 1, 0.70, 1.00, 0.45, 1.0, 1.0, 0.15, 40.0, 25.0, 1.0, 0.80, 7.5, 0.0 },
  659. { "Bright Hall", 0, 1.05, 1.15, 1.20, 1.0, 1.0, 0.50, 9.0, 0.0, 1.0, 1.00, 5.5, 0.0 },
  660. { "Nave", 0, 1.20, 1.00, 0.80, 1.0, 1.0, 0.35, 14.0, 20.0, 1.0, 0.62, 0.5, 0.0 },
  661. { "Grit Hall", 0, 1.00, 1.10, 1.20, 1.0, 1.0, 0.55, 9.0, 0.0, 1.3, 0.83, 5.0, 0.0 },
  662. { "Grit Plate", 2, 0.75, 0.92, 0.45, 1.0, 1.0, 0.10, 6.0, 40.0, 1.3, 1.25, 1.0, 0.0 },
  663. { "Smooth Plate", 2, 0.85, 1.12, 0.60, 1.0, 1.0, 0.40, 6.0, 0.0, 0.8, 0.46, 4.5, 0.0 },
  664. { "Smooth Room", 1, 0.95, 0.97, 0.70, 1.0, 1.0, 0.30, 8.0, 6.0, 0.8, 0.53, 9.0, 0.0 },
  665. { "Smooth Space", 0, 1.00, 1.04, 0.80, 1.0, 1.0, 0.25, 8.0, 6.0, 0.8, 0.81, 7.5, 0.0 },
  666. { "Gated", 1, 0.60, 0.62, 0.30, 1.0, 1.0, 0.10, 4.0, 0.0, 0.5, 0.90, 1.5, 0.55 },
  667. { "Drift Chamber", 1, 1.00, 1.08, 0.70, 1.0, 1.0, 0.40, 6.0, 0.0, 2.5, 0.43, 4.5, 0.0 },
  668. { "Drift Hall", 0, 1.00, 1.13, 1.20, 1.0, 1.0, 0.45, 9.0, 0.0, 2.5, 0.53, 5.0, 0.0 },
  669. { "Drift Space", 0, 1.30, 1.70, 1.20, 1.0, 1.0, 0.05, 9.0, 110.0, 2.5, 1.00, 4.0, 0.0 },
  670. { "Cathedral", 0, 1.40, 1.30, 1.00, 1.0, 1.0, 0.10, 40.0, 20.0, 1.0, 1.10, 0.5, 0.0 },
  671. { "Grand Hall", 0, 1.50, 1.30, 2.40, 1.7, 1.0, 0.20, 30.0, 20.0, 1.0, 1.30, 55.0, 0.0 },
  672. { "Vintage Chamber", 1, 1.10, 1.20, 0.90, 1.0, 1.0, 0.05, 25.0, 110.0, 0.7, 1.40, 11.0, 0.0 },
  673. { "Vintage Hall", 0, 1.00, 1.08, 1.20, 1.0, 1.0, 0.50, 9.0, 0.0, 0.7, 0.95, 5.0, 0.0 },
  674. };
  675. const char* const epochColours[epoch::colourCount] = { "1970s", "1980s", "Now" };
  676. // colour: loop bandwidth (Hz), output high cut (Hz, 0 = none), modulation scale
  677. constexpr double epochColourBw[3] = { 9000.0, 14000.0, 0.0 }; // 0 = no loop band limit
  678. constexpr double epochColourCut[3] = { 10000.0, 16000.0, 0.0 };
  679. double epochDecay (float v) { return skewLaw (v, 0.2, 70.0, 3.3596); }
  680. double epochPredelay (float v) { return skewLaw (v, 0.0, 500.0, 2.3219); }
  681. double epochBassMult (float v) { return skewLaw (v, 0.25, 4.0, 2.3219); }
  682. double epochBassXover (float v) { return skewLaw (v, 100.0, 10000.0, 4.0444); }
  683. double epochFreq (float v) { return skewLaw (v, 100.0, 20000.0, 1.7540); }
  684. class EpochFx final : public VerbEffect
  685. {
  686. public:
  687. EpochFx() : VerbEffect (EffectKind::epochVerb, 0.25, 0.62) {}
  688. protected:
  689. void configure (const EffectParams& p, double, Settings& s, float& mix) const noexcept override
  690. {
  691. const auto& m = epochModes[choice (p[16], epoch::modeCount)];
  692. const auto colour = choice (p[15], epoch::colourCount);
  693. mix = p[0];
  694. const auto size = (double) p[3];
  695. // a very slow attack also delays the onset (the reference: +45 ms at 100 %)
  696. s.predelaySec = (epochPredelay (p[1]) + m.preMs * (0.4 + 0.6 * size) + 225.0 * std::max (0.0, p[4] - 0.8)) / 1000.0;
  697. const auto decay = epochDecay (p[2]);
  698. s.shape = m.shape;
  699. s.lineScale = m.scale * (0.3 + 0.7 * size);
  700. s.rt60 = withFloor (decay * m.rtScale, m.rtFloor * (0.4 + 0.6 * size)) * (0.84 + 0.16 * p[10]);
  701. const auto bass = epochBassMult (p[5]);
  702. s.lowMult = (bass < 1.0 ? std::pow (bass, 0.35) : bass) * m.lowRt;
  703. s.lowXover = epochBassXover (p[6]);
  704. const auto shelf = -24.0 + 24.0 * p[7];
  705. s.highXover = epochFreq (p[8]);
  706. s.highMult = 1.1 * std::pow (10.0, std::max (shelf, -14.0) / 50.0);
  707. s.highShelfHz = s.highXover;
  708. s.highShelfDb = std::max (shelf, -16.0);
  709. s.inDiffusion = m.inDiff * p[9];
  710. s.loopDiffusion = 0.2 + 0.8 * p[10];
  711. s.modRateHz = 0.1 + 9.9 * p[11];
  712. s.modDepthMs = 0.6 * m.modScale * p[12] / std::sqrt (std::max (0.3, s.modRateHz));
  713. s.outHighCut = epochFreq (p[13]);
  714. s.outHighOrder = 1;
  715. if (epochColourCut[colour] > 0.0)
  716. s.outHighCut = std::min (s.outHighCut, epochColourCut[colour]);
  717. s.loopBandwidth = epochColourBw[colour];
  718. s.outLowCut = 10.0 + 1490.0 * p[14];
  719. s.outLowOrder = 1;
  720. s.earlyLevel = m.early;
  721. s.earlySec = m.earlyMs / 1000.0 * (0.4 + 0.6 * size);
  722. s.buildSec = m.buildMs / 1000.0 * (0.25 + 1.5 * p[4]);
  723. s.gateSec = m.gate > 0.0 ? m.gate * decay + 0.05 : 0.0;
  724. s.gain = m.gain;
  725. }
  726. };
  727. // ---------------------------------------------------------------------------------------------- Atrium
  728. // Laws: like the reference room (linear: predelay 0..500 ms, high cut 100..15000 Hz, sizes / crosses 0..1, mod rates
  729. // 0.05..5 Hz, bass mult 0.5..2 X, bass xover 100..10000 Hz, high mult 0.1..1 X, high xover 100..15000 Hz, early size
  730. // 1..1000 ms, low cut 0..1000 Hz) except Decay: 0.1..100 s with 2 s at the middle (the reference is linear).
  731. struct AtriumType
  732. {
  733. const char* name;
  734. int shape;
  735. double scale, rtScale, inDiff, early, lateGain, cut, modScale;
  736. };
  737. const AtriumType atriumTypes[atrium::typeCount] = {
  738. { "Large Room", 1, 1.00, 1.00, 1.0, 1.00, 1.00, 0.0, 1.0 },
  739. { "Medium Room", 1, 0.80, 1.00, 1.0, 1.00, 1.00, 0.0, 1.0 },
  740. { "Bright Room", 1, 0.90, 0.88, 0.9, 0.80, 0.90, 0.0, 1.0 },
  741. { "Large Chamber", 1, 1.20, 1.00, 1.0, 0.85, 1.05, 0.0, 1.0 },
  742. { "Dark Room", 1, 1.00, 1.00, 1.0, 1.00, 1.00, 0.0, 1.0 },
  743. { "Dark Chamber", 1, 1.15, 1.00, 1.0, 0.90, 1.00, 11000.0, 1.0 },
  744. { "Dark Space", 0, 1.10, 1.00, 1.0, 0.90, 1.00, 10000.0, 1.0 },
  745. { "Deep Space", 0, 1.20, 1.00, 1.0, 0.85, 1.00, 10500.0, 1.2 },
  746. { "Mirror Space", 0, 0.90, 1.00, 0.7, 1.10, 1.00, 10500.0, 1.0 },
  747. { "Vast Space", 0, 1.30, 1.00, 0.8, 1.00, 1.00, 10000.0, 1.2 },
  748. { "Distant Space", 0, 1.25, 1.00, 1.0, 0.70, 1.10, 10500.0, 1.0 },
  749. { "Dense Room", 1, 1.00, 1.00, 1.0, 1.05, 1.00, 10500.0, 1.0 },
  750. };
  751. double atriumDecaySec (float v) { return skewLaw (v, 0.1, 100.0, 5.717); }
  752. class AtriumFx final : public VerbEffect
  753. {
  754. public:
  755. AtriumFx() : VerbEffect (EffectKind::atrium, 0.25, 1.05) {}
  756. protected:
  757. void configure (const EffectParams& p, double, Settings& s, float& mix) const noexcept override
  758. {
  759. const auto& t = atriumTypes[choice (p[19], atrium::typeCount)];
  760. mix = p[0];
  761. s.predelaySec = 0.5 * p[1];
  762. s.rt60 = atriumDecaySec (p[2]) * t.rtScale;
  763. s.outHighCut = 100.0 + 14900.0 * p[3];
  764. s.bandLimit = t.cut;
  765. const auto earlyLate = (double) p[4]; // 0 = early only, 1 = late only
  766. s.earlyLevel = t.early * std::min (1.0, 2.0 * (1.0 - earlyLate)) * 1.4;
  767. s.lateLevel = t.lateGain * std::min (1.0, 2.0 * earlyLate);
  768. s.shape = t.shape;
  769. s.lineScale = t.scale * (0.35 + 0.9 * p[5]);
  770. s.crossFeed = 0.35 + 0.65 * p[6];
  771. s.modRateHz = 0.05 + 4.95 * p[7];
  772. s.modDepthMs = 0.8 * t.modScale * p[8] / std::sqrt (std::max (0.3, s.modRateHz));
  773. s.lowMult = 0.5 + 1.5 * p[9];
  774. s.lowXover = 100.0 + 9900.0 * p[10];
  775. s.highMult = 1.15 * (0.1 + 0.9 * p[11]); // (+15 %: what interpolation and diffusion take away)
  776. s.highXover = 100.0 + 14900.0 * p[12];
  777. s.earlySec = (1.0 + 999.0 * p[13]) / 1000.0;
  778. s.earlyDecay = 2.0 + 3.0 * p[14];
  779. s.earlyDiffusion = 0.3 + 0.7 * p[14];
  780. s.earlySend = p[17];
  781. s.inDiffusion = t.inDiff * p[18];
  782. s.loopDiffusion = 0.3 + 0.6 * p[18];
  783. const auto space = (double) p[20];
  784. s.buildSec = 0.02 + 0.06 * space;
  785. s.gain = 0.47 * (1.0 + 0.6 * space);
  786. s.outLowCut = 1000.0 * p[21];
  787. s.outLowOrder = 1;
  788. if (s.outLowCut < 5.0)
  789. s.outLowCut = 0.0;
  790. }
  791. };
  792. // ---------------------------------------------------------------------------------------------- Foil Plate
  793. // Laws: predelay 0..500 ms (v^2.32), decay 0.5..30 s (measured knots), size / width 0..200 %, mod rate 0.05..5 Hz
  794. // (v^2.38), low EQ 20..2000 Hz, high EQ 200..20000 Hz, EQ gains ±12 dB.
  795. constexpr double foilDecayKnots[] = { 0.0, 0.5, 0.5, 3.0, 0.75, 5.9, 0.775, 6.7, 0.8, 8.0, 0.825, 9.4, 0.85, 11.3, 0.875, 13.1,
  796. 0.9, 15.7, 0.925, 18.4, 0.95, 21.7, 0.975, 25.8, 1.0, 30.0 };
  797. constexpr int foilDecayCount = (int) (sizeof (foilDecayKnots) / sizeof (double) / 2);
  798. struct FoilType
  799. {
  800. const char* name;
  801. double scale, preMs, lowRt, damp, bw, early, gain;
  802. };
  803. // plate types: line scale, own onset (ms), bass RT ×, high-frequency absorption (1/s at 8 kHz), band limit (Hz, 0 = full band),
  804. // early level, gain
  805. const FoilType foilTypes[foil::typeCount] = {
  806. { "Silver", 1.00, 20.5, 1.0, 0.34, 9000.0, 0.35, 1.00 },
  807. { "Pewter", 0.85, 1.0, 1.0, 0.30, 9000.0, 0.45, 1.13 },
  808. { "Nickel", 1.10, 56.0, 1.0, 0.25, 10000.0, 0.35, 0.83 },
  809. { "Bronze", 0.90, 17.0, 1.0, 0.30, 9000.0, 0.55, 1.05 },
  810. { "Bismuth", 1.20, 6.5, 1.0, 0.20, 8500.0, 0.30, 1.00 },
  811. { "Tin", 1.00, 18.5, 1.0, 0.32, 9000.0, 0.35, 1.13 },
  812. { "Zinc", 1.30, 6.5, 1.1, 0.18, 9500.0, 0.30, 1.16 },
  813. { "Platinum", 1.20, 81.0, 1.3, 0.35, 8500.0, 0.25, 0.62 },
  814. { "Tungsten", 1.00, 21.0, 1.0, 0.30, 0.0, 0.35, 0.68 },
  815. { "Iron", 1.10, 56.0, 1.1, 0.30, 0.0, 0.30, 0.60 },
  816. { "Gold", 1.00, 20.5, 1.0, 0.30, 0.0, 0.35, 0.68 },
  817. { "Lead", 1.00, 1.5, 1.0, 0.45, 8500.0, 0.40, 1.00 },
  818. };
  819. double foilDecaySec (float v) { return knotLaw (v, foilDecayKnots, foilDecayCount); }
  820. class FoilFx final : public VerbEffect
  821. {
  822. public:
  823. FoilFx() : VerbEffect (EffectKind::foilPlate, 0.2, 0.62) {}
  824. protected:
  825. void configure (const EffectParams& p, double, Settings& s, float& mix) const noexcept override
  826. {
  827. const auto& t = foilTypes[choice (p[11], foil::typeCount)];
  828. mix = p[0];
  829. const auto size = 2.0 * p[3];
  830. s.predelaySec = (epochPredelay (p[1]) + t.preMs * (0.55 + 0.45 * size)) / 1000.0;
  831. s.shape = 2;
  832. s.lineScale = t.scale * (0.5 + 0.5 * size);
  833. const auto rt = foilDecaySec (p[2]);
  834. s.rt60 = rt;
  835. // plates lose highs faster the longer they ring: 1/RT(8 kHz) = 1/RT + damp (measured, §3)
  836. s.highMult = 1.0 / (1.0 + t.damp * rt);
  837. s.highXover = 5000.0;
  838. s.lowMult = t.lowRt;
  839. s.lowXover = 250.0;
  840. s.bandLimit = t.bw;
  841. s.inDiffusion = 1.0;
  842. s.loopDiffusion = 0.85;
  843. // 0 % = mono, 100 % = decorrelated, 200 % = slightly anti-correlated (−0.21, measured)
  844. s.width = p[4] <= 0.5f ? 2.0 * p[4] : 1.0 + 0.48 * (p[4] - 0.5);
  845. s.modRateHz = skewLaw (p[5], 0.05, 5.0, 2.381);
  846. s.modDepthMs = 1.0 * p[6] / std::sqrt (std::max (0.3, s.modRateHz));
  847. s.lowShelfHz = 20.0 + 1980.0 * p[7];
  848. s.lowShelfDb = 0.75 * (-12.0 + 24.0 * p[8]);
  849. s.highShelfHz = 200.0 + 19800.0 * p[9];
  850. s.highShelfDb = -12.0 + 24.0 * p[10];
  851. // the plate speaks at once after its own delay: a short, smeared early burst
  852. s.earlyLevel = t.early;
  853. s.earlySec = 0.015;
  854. s.earlyDiffusion = 0.8;
  855. s.gain = t.gain;
  856. }
  857. };
  858. // ---------------------------------------------------------------------------------------------- Nebula
  859. // Laws: delay 0..2000 ms (measured knots), feedback / density / warp 0..100 %, width −100..100 %, low cut 10..2000 Hz,
  860. // high cut 200..20000 Hz, mod rate 0.01..10 Hz (v^2.33). Feedback F gives a gain of √F per pass of the delay.
  861. constexpr double nebulaDelayKnots[] = { 0.0, 0.0, 0.5, 300.0, 0.75, 588.5, 0.775, 675.0, 0.925, 1425.0, 0.95, 1583.3, 0.975, 1791.7, 1.0, 2000.0 };
  862. constexpr int nebulaDelayCount = (int) (sizeof (nebulaDelayKnots) / sizeof (double) / 2);
  863. struct NebulaMode
  864. {
  865. const char* name;
  866. double dm0, dm100, mult0, mult100, corr;
  867. };
  868. // decay multiplier at density 0 / 100, line length × delay at density 0 / 100, stereo correlation (measured, §4)
  869. const NebulaMode nebulaModes[nebula::modeCount] = {
  870. { "Ripple", 1.03, 1.26, 1, 1, 0.93 }, { "Swell", 3.43, 3.82, 1, 2, -0.31 },
  871. { "Fold", 1.33, 1.39, 1, 2, -0.25 }, { "Drift", 2.56, 2.67, 1, 1, 0.25 },
  872. { "Abyss", 3.64, 3.97, 1, 2, -0.21 }, { "Vortex", 7.04, 6.77, 2, 2, 0.29 },
  873. { "Glint", 1.03, 1.17, 1, 1, 0.77 }, { "Pulse", 1.03, 1.22, 1, 1, 0.87 },
  874. { "Expanse", 4.29, 12.8, 8, 1, 0.39 }, { "Haze", 2.14, 12.3, 4, 1, 0.63 },
  875. { "Veil", 2.02, 5.04, 2, 1, 0.72 }, { "Mist", 1.00, 1.01, 1, 1, 0.47 },
  876. { "Monolith", 2.16, 16.3, 4, 1, 1.0 }, { "Eternity", 20.0, 20.7, 8, 1, -0.30 },
  877. { "Tide", 1.00, 1.12, 1, 1, 0.54 }, { "Shoal", 1.03, 1.30, 1, 1, 0.37 },
  878. { "Spark", 1.00, 1.05, 1, 1, 0.95 }, { "Plateau", 2.10, 9.65, 4, 1, 0.0 },
  879. { "Dusk", 4.15, 12.65, 8, 1, 0.31 }, { "Mirage", 1.00, 1.35, 1, 2, -0.43 },
  880. { "Cluster", 1.02, 1.01, 1, 1, -0.10 }, { "Beacon", 1.16, 1.04, 1, 1, 0.84 },
  881. };
  882. double nebulaDelayMs (float v) { return knotLaw (v, nebulaDelayKnots, nebulaDelayCount); }
  883. const char* const syncNames[4] = { "ms", "Note", "Dotted", "Triplet" };
  884. class NebulaFx final : public VerbEffect
  885. {
  886. public:
  887. NebulaFx() : VerbEffect (EffectKind::nebula, 4.2, 0.05) {}
  888. protected:
  889. void configure (const EffectParams& p, double bpm, Settings& s, float& mix) const noexcept override
  890. {
  891. const auto& m = nebulaModes[choice (p[12], nebula::modeCount)];
  892. mix = p[0];
  893. const auto delay = std::max (1.0, syncedMs (choice (p[1], 4), choice (p[2], 7), nebulaDelayMs (p[3]), bpm));
  894. const auto warp = (double) p[4];
  895. const auto fb = (double) p[5];
  896. const auto dens = (double) p[6];
  897. const auto lerpLog = [&] (double a, double b) { return std::exp (std::log (a) + (std::log (b) - std::log (a)) * dens); };
  898. const auto mult = lerpLog (m.mult0, m.mult100);
  899. const auto sw = warp * warp * (3.0 - 2.0 * warp); // smoothstep: lines shorten as warp rises
  900. s.shape = 3;
  901. s.lineScale = delay * mult;
  902. s.lineSpread = sw;
  903. // √F per pass of the delay: RT = 6·D / −log10 F, times the shape's measured decay multiple (which already holds
  904. // its line-length multiple); warp shortens the lines and so the decay
  905. const auto meanSec = delay * (1.0 - 0.53 * sw) / 1000.0; // (the warp fractions average 0.47)
  906. s.rt60 = fb >= 0.9999 ? 1000.0 : 6.0 * meanSec * lerpLog (m.dm0, m.dm100) / std::max (1e-4, -std::log10 (std::max (1e-6, fb)));
  907. s.rt60 = std::min (s.rt60, 1000.0);
  908. s.inDiffusion = dens;
  909. s.loopDiffusion = 0.85 * dens;
  910. s.crossFeed = 0.3 + 0.7 * dens;
  911. s.parallelLines = dens < 0.02; // density 0: plain repeats of the delay
  912. // stereo: plain echoes are mono (density 0); the shape's correlation at full density; warp decorrelates
  913. const auto corr = (1.0 + (m.corr - 1.0) * dens) * (1.0 - std::min (1.0, 2.0 * warp));
  914. const auto w = std::sqrt ((1.0 - corr) / (1.0 + corr + 1e-3));
  915. s.width = (-1.0 + 2.0 * p[7]) * std::min (2.0, w);
  916. s.outLowCut = 10.0 + 1990.0 * p[8];
  917. s.outHighCut = 200.0 + 19800.0 * p[9];
  918. s.modRateHz = skewLaw (p[10], 0.01, 10.0, 2.328);
  919. s.modDepthMs = 2.0 * p[11] / std::sqrt (std::max (0.1, s.modRateHz));
  920. s.gain = 0.9;
  921. }
  922. };
  923. // ---------------------------------------------------------------------------------------------- Halo
  924. // The reference exposes bare 0..1 values; the laws below are what the measurements showed (§5): shift −12..+12
  925. // semitones (linear), decay set mainly by Size (≈ 1.5 s + 12.5 s × size), high cut 100..15000 Hz first order (the
  926. // reference room's law), low cut 0..1000 Hz; mod rate / depth laws not confirmed.
  927. struct HaloMode
  928. {
  929. const char* name;
  930. double scale, rtScale, bright;
  931. };
  932. const HaloMode haloModes[3] = { { "Wide", 1.2, 1.0, 0.0 }, { "Dense", 0.9, 1.05, 0.0 }, { "Bright", 1.0, 0.75, 1.0 } };
  933. const char* const haloShiftModes[5] = { "Up", "Up + down", "Up, bright", "Up + down, bright", "No shift" };
  934. const char* const haloColours[2] = { "Bright", "Dark" };
  935. double haloShiftSemis (float v) { return -12.0 + 24.0 * v; }
  936. class HaloFx final : public VerbEffect
  937. {
  938. public:
  939. HaloFx() : VerbEffect (EffectKind::halo, 0.3, 0.05) {}
  940. protected:
  941. void configure (const EffectParams& p, double, Settings& s, float& mix) const noexcept override
  942. {
  943. mix = p[0];
  944. const auto& m = haloModes[choice (p[9], 3)];
  945. const auto shiftMode = choice (p[10], 5);
  946. const auto dark = choice (p[11], 2) == 1;
  947. const auto size = (double) p[4];
  948. s.shiftSemis = haloShiftSemis (p[1]);
  949. s.shiftFeedback = shiftMode == 4 ? 0.0 : 0.9 * p[2]; // the shifted share of the recirculation
  950. s.shiftMix = 1.0;
  951. s.shift2Mix = shiftMode == 1 || shiftMode == 3 ? 0.7 : 0.0;
  952. s.shiftSemis2 = s.shiftSemis - 24.0;
  953. s.inDiffusion = p[3];
  954. s.loopDiffusion = 0.2 + 0.7 * p[3];
  955. s.buildSec = 0.02 + 0.3 * size * (1.0 - p[3] * 0.5);
  956. s.shape = 0;
  957. s.lineScale = m.scale * (0.3 + 1.2 * size);
  958. s.rt60 = (1.5 + 12.5 * size) * m.rtScale * std::min (3.0, 1.0 + 2.8 * p[2] * p[2]); // feedback lengthens the tail (§5)
  959. s.earlyLevel = 0.45; // it speaks at once
  960. s.earlySec = 0.03;
  961. s.earlyDiffusion = p[3];
  962. s.outLowCut = 250.0 * p[5]; // gentle: the reference's low cut barely shows at 63 Hz (§5, not confirmed)
  963. s.outLowOrder = 1;
  964. if (s.outLowCut < 5.0)
  965. s.outLowCut = 0.0;
  966. s.outHighCut = 100.0 + 14900.0 * p[6];
  967. s.outHighOrder = 1;
  968. if (shiftMode == 2 || shiftMode == 3 || m.bright > 0.0)
  969. s.highShelfDb = 4.0, s.highShelfHz = 3000.0;
  970. s.loopBandwidth = dark ? 5000.0 : 0.0;
  971. s.modRateHz = 0.05 + 4.95 * p[7];
  972. s.modDepthMs = 1.2 * p[8] / std::sqrt (std::max (0.3, s.modRateHz));
  973. s.gain = dark ? 0.75 : 0.95;
  974. }
  975. };
  976. // ---------------------------------------------------------------------------------------------- Horizon
  977. constexpr double horizonDecayKnots[] = { 0.0, 0.2, 0.5, 5.0, 0.75, 9.81, 0.775, 12.5, 0.8, 16.67, 0.825, 21.25, 0.85, 27.5,
  978. 0.875, 33.75, 0.9, 41.67, 0.925, 50.0, 0.95, 57.5, 0.975, 63.75, 1.0, 70.0 };
  979. constexpr int horizonDecayCount = (int) (sizeof (horizonDecayKnots) / sizeof (double) / 2);
  980. constexpr double horizonEchoKnots[] = { 0.0, 0.0, 0.5, 100.0, 0.675, 197.2, 0.7, 250.0, 0.75, 375.0, 0.775, 456.2, 0.8, 550.0,
  981. 0.825, 643.8, 0.85, 762.5, 0.875, 918.8, 0.9, 1075.0, 0.925, 1250.0, 0.95, 1500.0, 0.975, 1750.0,
  982. 1.0, 2000.0 };
  983. constexpr int horizonEchoCount = (int) (sizeof (horizonEchoKnots) / sizeof (double) / 2);
  984. const char* const horizonEchoModes[horizon::echoModeCount] = { "Clean", "Tape", "Digital", "Analog", "Detune", "Reverse",
  985. "Reverse Up", "Reverse Down", "Reverse Up/Down", "Sparkle", "Swarm", "Lo-fi" };
  986. struct HorizonReverb
  987. {
  988. const char* name;
  989. int shape;
  990. double scale, rtScale, preMs, buildMs, early, gain;
  991. };
  992. const HorizonReverb horizonReverbs[horizon::reverbModeCount] = {
  993. { "Room", 1, 1.0, 0.80, 50.0, 60.0, 0.3, 1.5 }, { "Chamber", 1, 1.2, 1.00, 45.0, 45.0, 0.3, 3.0 },
  994. { "Plate", 2, 1.0, 1.00, 25.0, 8.0, 0.0, 3.6 }, { "Hall", 0, 1.0, 0.92, 35.0, 60.0, 0.2, 1.25 },
  995. { "Cathedral", 0, 1.3, 1.05, 60.0, 80.0, 0.1, 1.6 }, { "Space", 0, 1.5, 1.10, 70.0, 90.0, 0.0, 0.5 },
  996. { "Freeze", 0, 1.4, 3.30, 70.0, 900.0, 0.0, 0.4 }, { "Gated", 1, 0.8, 0.60, 30.0, 0.0, 0.1, 0.9 },
  997. };
  998. const char* const horizonColours[4] = { "Bright", "Neutral", "Dark", "Vintage" };
  999. constexpr double horizonColourCut[4] = { 0.0, 16000.0, 11000.0, 9000.0 };
  1000. double horizonDecaySec (float v) { return knotLaw (v, horizonDecayKnots, horizonDecayCount); }
  1001. double horizonEchoMs (float v) { return knotLaw (v, horizonEchoKnots, horizonEchoCount); }
  1002. class HorizonFx final : public VerbEffect
  1003. {
  1004. public:
  1005. HorizonFx() : VerbEffect (EffectKind::horizon, 0.25, 0.25) {}
  1006. void prepare (double sampleRate) noexcept override
  1007. {
  1008. VerbEffect::prepare (sampleRate);
  1009. for (auto& l : echo)
  1010. l.allocate ((int) (2.6 * sampleRate) + 16);
  1011. for (auto& sh : shifters)
  1012. sh.prepare (sampleRate, 0.08);
  1013. reset();
  1014. }
  1015. void reset() noexcept override
  1016. {
  1017. VerbEffect::reset();
  1018. for (auto& l : echo)
  1019. l.clear();
  1020. for (auto& sh : shifters)
  1021. sh.clear();
  1022. tone[0].z = tone[1].z = 0.0f;
  1023. wow = 0.0;
  1024. crush[0] = crush[1] = 0.0f;
  1025. crushPhase = 0.0;
  1026. }
  1027. protected:
  1028. void configure (const EffectParams& p, double, Settings& s, float& mix) const noexcept override
  1029. {
  1030. const auto& m = horizonReverbs[choice (p[22], horizon::reverbModeCount)];
  1031. mix = p[0];
  1032. const auto size = (double) p[12];
  1033. s.shape = m.shape;
  1034. s.lineScale = m.scale * (0.5 + 0.8 * size);
  1035. s.predelaySec = m.preMs * (0.6 + 0.8 * size) / 1000.0;
  1036. const auto decay = horizonDecaySec (p[11]);
  1037. s.rt60 = decay * m.rtScale;
  1038. s.buildSec = m.buildMs / 1000.0 * (0.3 + 1.4 * p[13]);
  1039. const auto earlyLate = (double) p[14];
  1040. s.earlyLevel = m.early * (1.5 - earlyLate);
  1041. s.earlySec = 0.04 * (0.5 + size);
  1042. s.lateLevel = 0.5 + earlyLate;
  1043. s.inDiffusion = 0.4 + 0.6 * p[15];
  1044. s.loopDiffusion = 0.1 + 0.8 * p[15];
  1045. s.gateSec = choice (p[22], horizon::reverbModeCount) == 7 ? 0.5 * decay + 0.05 : 0.0;
  1046. s.modRateHz = skewLaw (p[17], 0.01, 10.0, 2.328);
  1047. s.modDepthMs = 1.0 * p[18] / std::sqrt (std::max (0.1, s.modRateHz));
  1048. s.outLowCut = skewLaw (p[19], 20.0, 1000.0, 1.807);
  1049. s.outHighCut = skewLaw (p[20], 1000.0, 20000.0, 1.078);
  1050. const auto colour = choice (p[23], 4);
  1051. if (horizonColourCut[colour] > 0.0)
  1052. s.outHighCut = std::min (s.outHighCut, horizonColourCut[colour]);
  1053. if (colour == 3)
  1054. s.outLowCut = std::max (s.outLowCut, 250.0);
  1055. s.width = -1.0 + 2.0 * p[1];
  1056. s.gain = m.gain * p[16];
  1057. }
  1058. // the echo before the reverb (routing "echo → reverb"), or after it
  1059. void echoStage (float* l, float* r, int n, const EffectParams& p, double bpm) noexcept
  1060. {
  1061. const auto level = (float) p[9];
  1062. if (level <= 0.0f)
  1063. return;
  1064. const auto delay = std::max (1.0, syncedMs (choice (p[2], 4), std::min (5, choice (p[3], 6)), horizonEchoMs (p[4]), bpm)) * rate / 1000.0;
  1065. const auto fb = (float) (0.98 * p[5]);
  1066. const auto spread = (double) p[6];
  1067. const auto drive = std::pow (10.0, 24.0 * p[7] / 20.0);
  1068. const auto detune = (-30.0 + 60.0 * p[8]) / 100.0; // semitones
  1069. const auto mode = choice (p[21], horizon::echoModeCount);
  1070. double ratio = 1.0, ratio2 = 1.0;
  1071. bool shift = false, dual = false;
  1072. double cut = 18000.0, wowDepth = 0.0;
  1073. switch (mode)
  1074. {
  1075. case 1: cut = 7000.0; wowDepth = 0.0015; break; // tape
  1076. case 3: cut = 5000.0; break; // analog
  1077. case 4: shift = true; ratio = std::pow (2.0, (detune + 0.12) / 12.0); ratio2 = std::pow (2.0, -(detune + 0.12) / 12.0); dual = true; break;
  1078. case 5: shift = true; ratio = -1.0; break; // reverse
  1079. case 6: shift = true; ratio = -2.0; break;
  1080. case 7: shift = true; ratio = -0.5; break;
  1081. case 8: shift = true; ratio = -2.0; ratio2 = -0.5; dual = true; break;
  1082. case 9: shift = true; ratio = 2.0; break; // sparkle: an octave up in the repeats
  1083. case 10: shift = true; ratio = std::pow (2.0, 0.15 / 12.0); ratio2 = std::pow (2.0, -0.15 / 12.0); dual = true; wowDepth = 0.003; break;
  1084. case 11: cut = 4000.0; break; // lo-fi
  1085. default: break;
  1086. }
  1087. if (! shift && std::abs (detune) > 1e-3)
  1088. {
  1089. shift = true;
  1090. ratio = std::pow (2.0, detune / 12.0);
  1091. }
  1092. tone[0].setLowpass (cut, rate);
  1093. tone[1].a = tone[0].a;
  1094. const auto spreadL = delay * (1.0 - 0.25 * spread), spreadR = delay * (1.0 + 0.25 * spread);
  1095. const auto wowInc = 2.0 * pi * 0.7 / rate;
  1096. const auto hold = mode == 11 ? std::max (1.0, rate / 11025.0) : 1.0;
  1097. for (int i = 0; i < n; ++i)
  1098. {
  1099. wow += wowInc;
  1100. if (wow > 2.0 * pi)
  1101. wow -= 2.0 * pi;
  1102. const auto w = 1.0 + wowDepth * std::sin (wow);
  1103. float y[2] = { echo[0].readFrac (std::max (2.0, spreadL * w)), echo[1].readFrac (std::max (2.0, spreadR * w)) };
  1104. float x[2] = { l[i], r[i] };
  1105. for (int c = 0; c < 2; ++c)
  1106. {
  1107. auto v = y[c];
  1108. if (shift)
  1109. {
  1110. auto a = shifters[c].process (v, ratio);
  1111. if (dual)
  1112. a = 0.5f * (a + shifters[c + 2].process (v, ratio2));
  1113. v = a;
  1114. }
  1115. v = tone[c].lp (v);
  1116. if (drive > 1.0001)
  1117. v = (float) (std::tanh (drive * v) / std::sqrt (drive));
  1118. if (mode == 11)
  1119. {
  1120. if (c == 0)
  1121. crushPhase += 1.0;
  1122. if (crushPhase >= hold)
  1123. crush[c] = std::round (v * 64.0f) / 64.0f;
  1124. v = crush[c];
  1125. }
  1126. y[c] = v;
  1127. }
  1128. if (crushPhase >= hold)
  1129. crushPhase -= hold;
  1130. echo[0].write (x[0] + fb * y[0]);
  1131. echo[1].write (x[1] + fb * y[1]);
  1132. l[i] = x[0] + level * y[0];
  1133. r[i] = x[1] + level * y[1];
  1134. }
  1135. }
  1136. void preStage (float* l, float* r, int n, const EffectParams& p, double bpm) noexcept override
  1137. {
  1138. if (choice (p[10], 2) == 0)
  1139. echoStage (l, r, n, p, bpm);
  1140. }
  1141. void postStage (float* l, float* r, int n, const EffectParams& p, double bpm) noexcept override
  1142. {
  1143. if (choice (p[10], 2) == 1)
  1144. echoStage (l, r, n, p, bpm);
  1145. }
  1146. Line echo[2];
  1147. Shifter shifters[4];
  1148. OnePole tone[2];
  1149. double wow = 0.0, crushPhase = 0.0;
  1150. float crush[2] {};
  1151. };
  1152. // ---------------------------------------------------------------------------------------------- tables for the UI
  1153. std::vector<EffectParamInfo> params (std::initializer_list<EffectParamInfo> list) { return list; }
  1154. } // namespace
  1155. const char* epoch::modeName (int i) noexcept { return epochModes[std::clamp (i, 0, epoch::modeCount - 1)].name; }
  1156. const char* epoch::colourName (int i) noexcept { return epochColours[std::clamp (i, 0, epoch::colourCount - 1)]; }
  1157. double epoch::predelayMs (float v) noexcept { return epochPredelay (v); }
  1158. double epoch::decaySec (float v) noexcept { return epochDecay (v); }
  1159. const char* atrium::typeName (int i) noexcept { return atriumTypes[std::clamp (i, 0, atrium::typeCount - 1)].name; }
  1160. double atrium::decaySec (float v) noexcept { return atriumDecaySec (v); }
  1161. float atrium::decayValue (double s) noexcept { return (float) skewInverse (s, 0.1, 100.0, 5.717); }
  1162. const char* foil::typeName (int i) noexcept { return foilTypes[std::clamp (i, 0, foil::typeCount - 1)].name; }
  1163. double foil::decaySec (float v) noexcept { return foilDecaySec (v); }
  1164. const char* nebula::modeName (int i) noexcept { return nebulaModes[std::clamp (i, 0, nebula::modeCount - 1)].name; }
  1165. double nebula::delayMs (float v) noexcept { return nebulaDelayMs (v); }
  1166. const char* horizon::echoModeName (int i) noexcept { return horizonEchoModes[std::clamp (i, 0, horizon::echoModeCount - 1)]; }
  1167. const char* horizon::reverbModeName (int i) noexcept { return horizonReverbs[std::clamp (i, 0, horizon::reverbModeCount - 1)].name; }
  1168. double horizon::decaySec (float v) noexcept { return horizonDecaySec (v); }
  1169. double horizon::echoMs (float v) noexcept { return horizonEchoMs (v); }
  1170. bool isLynxVerb (EffectKind k) noexcept
  1171. {
  1172. return k == EffectKind::epochVerb || k == EffectKind::atrium || k == EffectKind::foilPlate || k == EffectKind::nebula
  1173. || k == EffectKind::halo || k == EffectKind::horizon;
  1174. }
  1175. const EffectInfo& info (EffectKind kind)
  1176. {
  1177. // defaults = the reference plugins' defaults (their saved normalised values)
  1178. static const EffectInfo epochInfo { "Epoch Verb",
  1179. params ({ { "Mix", 1.0f }, { "Predelay", 0.25f }, { "Decay", 0.42048f }, { "Size", 1.0f }, { "Attack", 0.5f },
  1180. { "Bass mult", 0.623039f }, { "Bass xover", 0.381065f }, { "High shelf", 0.0f }, { "High freq", 0.5f },
  1181. { "Early diffusion", 1.0f }, { "Late diffusion", 1.0f }, { "Mod rate", 0.245455f }, { "Mod depth", 0.38f },
  1182. { "High cut", 0.590539f }, { "Low cut", 0.0f }, { "Color", 0.0f }, { "Mode", 0.0f } }) };
  1183. static const EffectInfo atriumInfo { "Atrium",
  1184. params ({ { "Mix", 1.0f }, { "Predelay", 0.02f }, { "Decay", 0.5f }, { "High cut", 0.530201f }, { "Early/late", 0.5f },
  1185. { "Late size", 0.5f }, { "Late cross", 1.0f }, { "Late mod rate", 0.090909f }, { "Late mod depth", 0.5f },
  1186. { "Bass mult", 0.333333f }, { "Bass xover", 0.090909f }, { "High mult", 0.444444f }, { "High xover", 0.530201f },
  1187. { "Early size", 0.029029f }, { "Early cross", 0.1f }, { "Early mod rate", 0.090909f }, { "Early mod depth", 0.0f },
  1188. { "Early send", 0.0f }, { "Diffusion", 1.0f }, { "Type", 0.0f }, { "Space", 0.0f }, { "Low cut", 0.0f } }) };
  1189. static const EffectInfo foilInfo { "Foil Plate",
  1190. params ({ { "Mix", 1.0f }, { "Predelay", 0.0f }, { "Decay", 0.5f }, { "Size", 0.5f }, { "Width", 0.5f },
  1191. { "Mod rate", 0.365345f }, { "Mod depth", 0.0f }, { "Low EQ freq", 0.348774f }, { "Low EQ gain", 0.5f },
  1192. { "High EQ freq", 0.5f }, { "High EQ gain", 0.5f }, { "Type", 0.0f } }) };
  1193. static const EffectInfo nebulaInfo { "Nebula",
  1194. params ({ { "Mix", 0.5f }, { "Sync", 0.0f }, { "Note", 0.333333f }, { "Delay", 0.5f }, { "Warp", 0.0f },
  1195. { "Feedback", 0.5f }, { "Density", 0.0f }, { "Width", 1.0f }, { "Low cut", 0.0f }, { "High cut", 1.0f },
  1196. { "Mod rate", 0.273834f }, { "Mod depth", 0.5f }, { "Mode", 0.0f } }) };
  1197. static const EffectInfo haloInfo { "Halo",
  1198. params ({ { "Mix", 0.5f }, { "Shift", 1.0f }, { "Feedback", 0.0f }, { "Diffusion", 0.919192f }, { "Size", 0.5f },
  1199. { "Low cut", 0.0f }, { "High cut", 0.530201f }, { "Mod rate", 0.1f }, { "Mod depth", 0.3f },
  1200. { "Reverb mode", 0.0f }, { "Shift mode", 0.0f }, { "Color", 0.0f } }) };
  1201. static const EffectInfo horizonInfo { "Horizon",
  1202. params ({ { "Mix", 0.5f }, { "Width", 1.0f }, { "Echo sync", 0.0f }, { "Echo note", 0.4f }, { "Echo time", 0.15f },
  1203. { "Echo feedback", 0.0f }, { "Echo spread", 0.0f }, { "Echo drive", 0.125f }, { "Echo detune", 0.566667f },
  1204. { "Echo level", 0.0f }, { "Routing", 0.0f }, { "Decay", 0.291667f }, { "Size", 0.5f }, { "Attack", 0.5f },
  1205. { "Early/late", 0.5f }, { "Density", 1.0f }, { "Reverb level", 1.0f }, { "Mod rate", 0.132226f },
  1206. { "Mod depth", 0.4f }, { "Low EQ freq", 0.25f }, { "High EQ freq", 0.208197f }, { "Echo mode", 0.090909f },
  1207. { "Reverb mode", 0.142857f }, { "Color", 0.333333f } }) };
  1208. switch (kind)
  1209. {
  1210. case EffectKind::atrium: return atriumInfo;
  1211. case EffectKind::foilPlate: return foilInfo;
  1212. case EffectKind::nebula: return nebulaInfo;
  1213. case EffectKind::halo: return haloInfo;
  1214. case EffectKind::horizon: return horizonInfo;
  1215. default: return epochInfo;
  1216. }
  1217. }
  1218. std::string paramText (EffectKind kind, int param, float v, double bpm)
  1219. {
  1220. (void) bpm;
  1221. switch (kind)
  1222. {
  1223. case EffectKind::epochVerb:
  1224. switch (param)
  1225. {
  1226. case 1: return ms (epochPredelay (v));
  1227. case 2: return sec (epochDecay (v));
  1228. case 5: return fmt ("%.2f X", epochBassMult (v));
  1229. case 6:
  1230. case 8:
  1231. case 13: return hz (param == 6 ? epochBassXover (v) : epochFreq (v));
  1232. case 7: return fmt ("%.1f dB", -24.0 + 24.0 * v);
  1233. case 11: return fmt ("%.2f Hz", 0.1 + 9.9 * v);
  1234. case 14: return hz (10.0 + 1490.0 * v);
  1235. case 15: return epoch::colourName (choice (v, epoch::colourCount));
  1236. case 16: return epoch::modeName (choice (v, epoch::modeCount));
  1237. default: return pct (v);
  1238. }
  1239. case EffectKind::atrium:
  1240. switch (param)
  1241. {
  1242. case 1: return ms (500.0 * v);
  1243. case 2: return sec (atriumDecaySec (v));
  1244. case 3: return hz (100.0 + 14900.0 * v);
  1245. case 5: case 6: case 8: case 14: case 16: case 17: case 18: return fmt ("%.2f", v);
  1246. case 7: case 15: return fmt ("%.2f Hz", 0.05 + 4.95 * v);
  1247. case 9: return fmt ("%.2f X", 0.5 + 1.5 * v);
  1248. case 10: return hz (100.0 + 9900.0 * v);
  1249. case 11: return fmt ("%.2f X", 0.1 + 0.9 * v);
  1250. case 12: return hz (100.0 + 14900.0 * v);
  1251. case 13: return ms (1.0 + 999.0 * v);
  1252. case 19: return atrium::typeName (choice (v, atrium::typeCount));
  1253. case 21: return hz (1000.0 * v);
  1254. default: return pct (v);
  1255. }
  1256. case EffectKind::foilPlate:
  1257. switch (param)
  1258. {
  1259. case 1: return ms (epochPredelay (v));
  1260. case 2: return sec (foilDecaySec (v));
  1261. case 3: case 4: return pct (2.0 * v);
  1262. case 5: return fmt ("%.2f Hz", skewLaw (v, 0.05, 5.0, 2.381));
  1263. case 7: return hz (20.0 + 1980.0 * v);
  1264. case 9: return hz (200.0 + 19800.0 * v);
  1265. case 8: case 10: return fmt ("%+.1f dB", -12.0 + 24.0 * v);
  1266. case 11: return foil::typeName (choice (v, foil::typeCount));
  1267. default: return pct (v);
  1268. }
  1269. case EffectKind::nebula:
  1270. switch (param)
  1271. {
  1272. case 1: return syncNames[choice (v, 4)];
  1273. case 2: return noteNames[choice (v, 7)];
  1274. case 3: return ms (nebulaDelayMs (v));
  1275. case 7: return pct (-1.0 + 2.0 * v);
  1276. case 8: return hz (10.0 + 1990.0 * v);
  1277. case 9: return hz (200.0 + 19800.0 * v);
  1278. case 10: return fmt ("%.2f Hz", skewLaw (v, 0.01, 10.0, 2.328));
  1279. case 12: return nebula::modeName (choice (v, nebula::modeCount));
  1280. default: return pct (v);
  1281. }
  1282. case EffectKind::halo:
  1283. switch (param)
  1284. {
  1285. case 1: return fmt ("%+.1f st", haloShiftSemis (v));
  1286. case 5: return hz (10.0 + 990.0 * v); // the reference reads 10 Hz at 0 (its editor)
  1287. case 6: return hz (100.0 + 14900.0 * v);
  1288. case 7: return fmt ("%.2f Hz", 0.05 + 4.95 * v);
  1289. case 9: return haloModes[choice (v, 3)].name;
  1290. case 10: return haloShiftModes[choice (v, 5)];
  1291. case 11: return haloColours[choice (v, 2)];
  1292. default: return pct (v);
  1293. }
  1294. case EffectKind::horizon:
  1295. switch (param)
  1296. {
  1297. case 1: return pct (-1.0 + 2.0 * v);
  1298. case 2: return syncNames[choice (v, 4)];
  1299. case 3: return noteNames[std::min (5, choice (v, 6))];
  1300. case 4: return ms (horizonEchoMs (v));
  1301. case 7: return fmt ("%.1f dB", 24.0 * v);
  1302. case 8: return fmt ("%+.1f ct", -30.0 + 60.0 * v);
  1303. case 10: return choice (v, 2) == 0 ? "Echo > Reverb" : "Reverb > Echo";
  1304. case 11: return sec (horizonDecaySec (v));
  1305. case 17: return fmt ("%.2f Hz", skewLaw (v, 0.01, 10.0, 2.328));
  1306. case 19: return hz (skewLaw (v, 20.0, 1000.0, 1.807));
  1307. case 20: return hz (skewLaw (v, 1000.0, 20000.0, 1.078));
  1308. case 21: return horizon::echoModeName (choice (v, horizon::echoModeCount));
  1309. case 22: return horizon::reverbModeName (choice (v, horizon::reverbModeCount));
  1310. case 23: return horizonColours[choice (v, 4)];
  1311. default: return pct (v);
  1312. }
  1313. default: return pct (v);
  1314. }
  1315. }
  1316. std::unique_ptr<Effect> make (EffectKind kind)
  1317. {
  1318. switch (kind)
  1319. {
  1320. case EffectKind::atrium: return std::make_unique<AtriumFx>();
  1321. case EffectKind::foilPlate: return std::make_unique<FoilFx>();
  1322. case EffectKind::nebula: return std::make_unique<NebulaFx>();
  1323. case EffectKind::halo: return std::make_unique<HaloFx>();
  1324. case EffectKind::horizon: return std::make_unique<HorizonFx>();
  1325. default: return std::make_unique<EpochFx>();
  1326. }
  1327. }
  1328. } // namespace lynx::verbs