Effects.cpp 157 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471
  1. #include "core/Patcher.h"
  2. #include "core/Effects.h"
  3. #include "core/FormulaController.h"
  4. #include "core/RhythmPan.h"
  5. #include "core/MixSuite.h"
  6. #include "core/VoiceMatch.h"
  7. #include "core/EchoSuite.h"
  8. #include "core/LynxTune.h"
  9. #include "core/LynxVerbs.h"
  10. #include "core/Effector.h"
  11. #include "core/PitcherDsp.h"
  12. #include "core/Reeverb2.h"
  13. #include "core/LuxeVerb.h"
  14. #include "core/ConvolverFx.h"
  15. #include "core/VintagePhaser.h"
  16. #include "core/Vocodex.h"
  17. #include "core/FruityVocoder.h"
  18. #include "core/MaximusFx.h"
  19. #include "core/ParametricEqFl.h"
  20. #include "core/EquoFx.h"
  21. #include "core/DistructorFx.h"
  22. #include "core/MultibandDelayFx.h"
  23. #include "core/PitchShifterFl.h"
  24. #include "core/FruityDynamics.h"
  25. #include "core/FruityShapers.h"
  26. #include "core/FruityBasicFx.h"
  27. #include "core/FruityFilters.h"
  28. #include "core/NewtoneFx.h"
  29. #include "core/FruityDelay.h"
  30. #include "core/FrequencySplitter.h"
  31. #include "core/HardcoreFx.h"
  32. #include "core/StereoFx.h"
  33. #include "core/ChorusFx.h"
  34. #include "core/GrossBeat.h"
  35. #include "core/LovePhilter.h"
  36. #include "core/FruityDelayBank.h"
  37. #include "core/FruityMultiband.h"
  38. #include "core/FlangusFastDist.h"
  39. #include "core/FruityPhaser.h"
  40. #include "core/Biquad.h"
  41. #include "core/FacetEq.h"
  42. #include "core/ApexLimiter.h"
  43. #include "core/DynamicsSuite.h"
  44. #include "core/VoiceTools.h"
  45. #include "core/VoiceShift.h"
  46. #include <algorithm>
  47. #include <atomic>
  48. #include <cmath>
  49. #include <complex>
  50. #include <cstdio>
  51. namespace lynx
  52. {
  53. namespace
  54. {
  55. constexpr double pi = 3.141592653589793;
  56. constexpr double maxSampleRate = 192000.0;
  57. float dbToGain (float db) noexcept { return std::pow (10.0f, db / 20.0f); }
  58. // approximate tanh (Padé), saturating at ±1: much cheaper than std::tanh per sample
  59. inline float fastTanh (float x) noexcept
  60. {
  61. if (x > 3.0f)
  62. return 1.0f;
  63. if (x < -3.0f)
  64. return -1.0f;
  65. const auto x2 = x * x;
  66. return x * (27.0f + x2) / (27.0f + 9.0f * x2);
  67. }
  68. // sine of a phase in turns (0..1) via refined parabola (error < 0.1%), for LFOs
  69. inline float sinTurns (double phase) noexcept
  70. {
  71. const auto x = (float) (phase < 0.5 ? phase : phase - 1.0) * 2.0f;
  72. const auto y = 4.0f * x * (1.0f - std::abs (x));
  73. return 0.225f * (y * std::abs (y) - y) + y;
  74. }
  75. float gainToDb (float g) noexcept { return 20.0f * std::log10 (std::max (g, 1e-9f)); }
  76. // 0..1 -> logarithmic range [lo, hi]
  77. float logRange (float v, float lo, float hi) noexcept { return lo * std::pow (hi / lo, std::clamp (v, 0.0f, 1.0f)); }
  78. // ---------------------------------------------------------------------------
  79. // Parameter mapping (shared by the DSP and the UI text)
  80. float eqGainDb (float v) { return (v - 0.5f) * 36.0f; } // -18..+18 dB
  81. float eqMidHz (float v) { return logRange (v, 200.0f, 5000.0f); }
  82. float compThresholdDb (float v) { return -60.0f + v * 60.0f; }
  83. float compRatio (float v) { return 1.0f + v * 19.0f; }
  84. float compAttackMs (float v) { return logRange (v, 0.1f, 100.0f); }
  85. float compReleaseMs (float v) { return logRange (v, 10.0f, 1000.0f); }
  86. float compMakeupDb (float v) { return v * 24.0f; }
  87. // BPM-synced Delay divisions, in beats (quarter notes).
  88. constexpr std::array<double, 8> delayDivisions { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, 4.0 };
  89. constexpr std::array<const char*, 8> delayNames { "1/16", "1/8", "1/8 dot.", "1/4", "1/4 dot.", "1/2", "1/2 dot.", "1 bar" };
  90. int delayIndex (float v) { return std::clamp ((int) (v * (float) delayDivisions.size()), 0, (int) delayDivisions.size() - 1); }
  91. float reverbLowCutHz (float v) { return logRange (v, 20.0f, 3000.0f); } // 0 = off
  92. float reverbHighCutHz (float v) { return logRange (v, 500.0f, 22000.0f); } // 1 = off
  93. float limiterCeilingDb (float v) { return -12.0f + v * 12.0f; }
  94. float limiterGainDb (float v) { return v * 24.0f; }
  95. float limiterReleaseMs (float v) { return logRange (v, 10.0f, 1000.0f); }
  96. int filterType (float v) { return std::clamp ((int) (v * 3.0f), 0, 2); } // low-pass, high-pass, band-pass
  97. constexpr std::array<const char*, 3> filterNames { "Low-pass", "High-pass", "Band-pass" };
  98. float filterHz (float v) { return logRange (v, 20.0f, 20000.0f); }
  99. float filterQ (float v) { return logRange (v, 0.5f, 12.0f); }
  100. float distortionDriveDb (float v) { return v * 36.0f; }
  101. float distortionToneHz (float v) { return logRange (v, 800.0f, 20000.0f); }
  102. float chorusRateHz (float v) { return logRange (v, 0.05f, 5.0f); }
  103. float chorusDepthMs (float v) { return v * 8.0f; }
  104. // ---------------------------------------------------------------------------
  105. class Eq final : public Effect
  106. {
  107. public:
  108. void prepare (double sr) noexcept override
  109. {
  110. sampleRate = sr;
  111. lastParams.fill (-1.0f); // force recalculation
  112. reset();
  113. }
  114. void reset() noexcept override
  115. {
  116. for (auto& b : bands)
  117. b.reset();
  118. }
  119. void process (float* l, float* r, int n, const EffectParams& params, double) noexcept override
  120. {
  121. if (params != lastParams)
  122. {
  123. lastParams = params;
  124. bands[0].shelf (sampleRate, 120.0, eqGainDb (params[0]), false);
  125. bands[1].peaking (sampleRate, eqMidHz (params[2]), 0.8, eqGainDb (params[1]));
  126. bands[2].shelf (sampleRate, 8000.0, eqGainDb (params[3]), true);
  127. output = dbToGain (eqGainDb (params[4]));
  128. }
  129. for (int i = 0; i < n; ++i)
  130. {
  131. auto a = l[i], b = r[i];
  132. for (auto& band : bands)
  133. {
  134. a = band.process (a, 0);
  135. b = band.process (b, 1);
  136. }
  137. l[i] = a * output;
  138. r[i] = b * output;
  139. }
  140. }
  141. private:
  142. double sampleRate = 44100.0;
  143. std::array<Biquad, 3> bands;
  144. std::array<float, maxEffectParams> lastParams {};
  145. float output = 1.0f;
  146. };
  147. // ---------------------------------------------------------------------------
  148. class Compressor final : public Effect
  149. {
  150. public:
  151. void prepare (double sr) noexcept override { sampleRate = sr; vintage.prepare (sr); reset(); }
  152. void reset() noexcept override
  153. {
  154. envelopeDb = 0.0f;
  155. inPower = outPower = 0.0f;
  156. autoGain = 1.0f;
  157. vintage.reset();
  158. }
  159. // round 123: voicing 1 = the measured program-dependent compressor (core/VoiceMatch.h); it delays the audio
  160. int latencySamples() const noexcept override { return latency.load (std::memory_order_relaxed); }
  161. // round 129: the editor's meters (Effect::controlOutput): 0 = gain reduction (0..1 over 0..30 dB), 2 / 3 = input /
  162. // output peak — the level meters the compressors it stands in for show (Renaissance Compressor's three meters)
  163. float controlOutput (int k) const noexcept override
  164. {
  165. return k == 0 ? meterGr.load (std::memory_order_relaxed) : k == 2 ? meterIn.load (std::memory_order_relaxed)
  166. : k == 3 ? meterOut.load (std::memory_order_relaxed) : k == 4 ? meterLimit.load (std::memory_order_relaxed) : 0.0f;
  167. }
  168. // round 135w: the reference's built-in 0 dBFS output limiter — the gain drops at once to keep every sample at or
  169. // under 0 dBFS and recovers over 50 ms; meter 4 = its reduction this block (0..1 over 0..12 dB), the activity pill
  170. void outputLimit (float* l, float* r, int n) noexcept
  171. {
  172. const auto rel = (float) (1.0 - std::exp (-1.0 / (0.05 * sampleRate)));
  173. float most = 1.0f;
  174. for (int i = 0; i < n; ++i)
  175. {
  176. const auto peak = std::max (std::abs (l[i]), std::abs (r[i]));
  177. limitGain += rel * (1.0f - limitGain);
  178. if (peak * limitGain > 1.0f)
  179. limitGain = 1.0f / peak;
  180. l[i] *= limitGain;
  181. r[i] *= limitGain;
  182. most = std::min (most, limitGain);
  183. }
  184. meterLimit.store (std::clamp (-20.0f * std::log10 (std::max (most, 1e-6f)) / 12.0f, 0.0f, 1.0f), std::memory_order_relaxed);
  185. }
  186. void process (float* l, float* r, int n, const EffectParams& params, double) noexcept override
  187. {
  188. if (params[8] >= 0.5f)
  189. {
  190. latency.store (vintage.latency(), std::memory_order_relaxed);
  191. float peakIn = 0.0f, peakOut = 0.0f;
  192. for (int i = 0; i < n; ++i)
  193. peakIn = std::max (peakIn, std::max (std::abs (l[i]), std::abs (r[i])));
  194. vmatch::progcomp::Settings v;
  195. v.thresholdDb = compThresholdDb (params[0]);
  196. v.ratio = compRatio (params[1]);
  197. v.attackMs = compAttackMs (params[2]);
  198. v.releaseMs = compReleaseMs (params[3]);
  199. v.gainDb = compMakeupDb (params[4]);
  200. v.mix = std::clamp ((double) params[6], 0.0, 1.0);
  201. v.trimDb = -18.0 + 36.0 * std::clamp ((double) params[7], 0.0, 1.0);
  202. v.manual = params[9] >= 0.5f;
  203. v.opto = params[10] >= 0.5f;
  204. v.smooth = params[11] >= 0.5f;
  205. vintage.process (l, r, n, v);
  206. if (params[12] >= 0.5f)
  207. outputLimit (l, r, n);
  208. else
  209. meterLimit.store (0.0f, std::memory_order_relaxed);
  210. for (int i = 0; i < n; ++i)
  211. peakOut = std::max (peakOut, std::max (std::abs (l[i]), std::abs (r[i])));
  212. useSidechain = false;
  213. meterGr.store (std::clamp (vintage.reductionDb() / 30.0f, 0.0f, 1.0f), std::memory_order_relaxed);
  214. meterIn.store (std::min (peakIn, 1.0f), std::memory_order_relaxed);
  215. meterOut.store (std::min (peakOut, 1.0f), std::memory_order_relaxed);
  216. return;
  217. }
  218. latency.store (0, std::memory_order_relaxed);
  219. // "Auto gain" (round 107): the long-term level stays where it was (slow in/out power match, ±12 dB), so the
  220. // compressor shapes the dynamics without making the track quieter. Used where its settings are a guess (a
  221. // substitute for a missing plugin, whose own makeup gain is unknown).
  222. const auto levelMatch = params[5] >= 0.5f;
  223. const auto powerCoeff = (float) std::exp (-1.0 / (1.5 * sampleRate));
  224. const auto gainCoeff = (float) std::exp (-1.0 / (0.05 * sampleRate));
  225. const auto threshold = compThresholdDb (params[0]);
  226. const auto ratio = compRatio (params[1]);
  227. const auto attack = (float) std::exp (-1.0 / (compAttackMs (params[2]) * 0.001 * sampleRate));
  228. const auto release = (float) std::exp (-1.0 / (compReleaseMs (params[3]) * 0.001 * sampleRate));
  229. const auto makeup = dbToGain (compMakeupDb (params[4]));
  230. const auto thresholdGain = dbToGain (threshold);
  231. const auto sidechain = useSidechain;
  232. useSidechain = false;
  233. float peakIn = 0.0f, peakOut = 0.0f, maxGr = 0.0f;
  234. // round 129: parallel mix (dry with the compressed signal) and a trim after it (±18 dB); older projects load
  235. // 100 % / 0 dB
  236. const auto wetMix = std::clamp (params[6], 0.0f, 1.0f);
  237. const auto trim = dbToGain (-18.0f + 36.0f * std::clamp (params[7], 0.0f, 1.0f));
  238. for (int i = 0; i < n; ++i)
  239. {
  240. peakIn = std::max (peakIn, std::max (std::abs (l[i]), std::abs (r[i])));
  241. // linked stereo peak detector, "hard knee" curve; below the threshold the log is not needed.
  242. // With sidechain, the detector listens to the other track (kick ducking)
  243. const auto peak = sidechain ? (sideL != nullptr ? std::max (std::abs (sideL[i]), std::abs (sideR[i])) : 0.0f)
  244. : std::max (std::abs (l[i]), std::abs (r[i]));
  245. const auto reductionDb = peak > thresholdGain ? (gainToDb (peak) - threshold) * (1.0f - 1.0f / ratio) : 0.0f;
  246. // the envelope rises with the attack and falls with the release
  247. const auto coeff = reductionDb > envelopeDb ? attack : release;
  248. envelopeDb = reductionDb + coeff * (envelopeDb - reductionDb);
  249. if (envelopeDb < 1.0e-4f)
  250. envelopeDb = 0.0f; // no audible reduction: skip the pow
  251. auto gain = envelopeDb > 0.0f ? dbToGain (-envelopeDb) * makeup : makeup;
  252. if (levelMatch)
  253. {
  254. const auto in = 0.5f * (l[i] * l[i] + r[i] * r[i]);
  255. inPower = in + powerCoeff * (inPower - in);
  256. const auto out = in * gain * gain;
  257. outPower = out + powerCoeff * (outPower - out);
  258. // follow only while there is signal (silence keeps the last match)
  259. const auto target = inPower > 1.0e-8f && outPower > 1.0e-12f ? std::clamp (std::sqrt (inPower / outPower), 0.25f, 4.0f) : autoGain;
  260. autoGain = target + gainCoeff * (autoGain - target);
  261. gain *= autoGain;
  262. }
  263. l[i] = (l[i] * gain * wetMix + l[i] * (1.0f - wetMix)) * trim;
  264. r[i] = (r[i] * gain * wetMix + r[i] * (1.0f - wetMix)) * trim;
  265. maxGr = std::max (maxGr, envelopeDb);
  266. }
  267. if (params[12] >= 0.5f)
  268. outputLimit (l, r, n);
  269. else
  270. meterLimit.store (0.0f, std::memory_order_relaxed);
  271. for (int i = 0; i < n; ++i)
  272. peakOut = std::max (peakOut, std::max (std::abs (l[i]), std::abs (r[i])));
  273. meterGr.store (std::clamp (maxGr / 30.0f, 0.0f, 1.0f), std::memory_order_relaxed);
  274. meterIn.store (std::min (peakIn, 1.0f), std::memory_order_relaxed);
  275. meterOut.store (std::min (peakOut, 1.0f), std::memory_order_relaxed);
  276. }
  277. void setSidechain (const float* left, const float* right) noexcept override
  278. {
  279. sideL = left;
  280. sideR = right;
  281. useSidechain = true;
  282. }
  283. private:
  284. std::atomic<float> meterGr { 0.0f }, meterIn { 0.0f }, meterOut { 0.0f }, meterLimit { 0.0f };
  285. float limitGain = 1.0f;
  286. std::atomic<int> latency { 0 };
  287. vmatch::progcomp::Compressor vintage;
  288. double sampleRate = 44100.0;
  289. float envelopeDb = 0.0f;
  290. float inPower = 0.0f, outPower = 0.0f, autoGain = 1.0f;
  291. const float* sideL = nullptr;
  292. const float* sideR = nullptr;
  293. bool useSidechain = false;
  294. };
  295. // ---------------------------------------------------------------------------
  296. class Delay final : public Effect
  297. {
  298. public:
  299. static constexpr double maxSeconds = 3.0;
  300. Delay()
  301. {
  302. const auto size = (std::size_t) (maxSeconds * maxSampleRate) + 4;
  303. buffer[0].assign (size, 0.0f);
  304. buffer[1].assign (size, 0.0f);
  305. }
  306. void prepare (double sr) noexcept override { sampleRate = sr; reset(); }
  307. void reset() noexcept override
  308. {
  309. std::fill (buffer[0].begin(), buffer[0].end(), 0.0f);
  310. std::fill (buffer[1].begin(), buffer[1].end(), 0.0f);
  311. damp[0] = damp[1] = 0.0f;
  312. write = 0;
  313. }
  314. void process (float* l, float* r, int n, const EffectParams& params, double bpm) noexcept override
  315. {
  316. const auto beats = delayDivisions[(std::size_t) delayIndex (params[0])];
  317. const auto seconds = std::min (maxSeconds - 0.01, beats * 60.0 / std::max (bpm, 20.0));
  318. const auto delaySamples = std::max<std::size_t> (1, (std::size_t) (seconds * sampleRate));
  319. const auto feedback = params[1] * 0.95f;
  320. const auto mix = params[2];
  321. const auto pingPong = params[3] > 0.5f;
  322. const auto dampCoeff = 1.0f - params[4] * 0.9f; // 1 = no filter in the feedback path
  323. const auto size = buffer[0].size();
  324. for (int i = 0; i < n; ++i)
  325. {
  326. const auto readPos = (write + size - delaySamples) % size;
  327. auto echoL = buffer[0][readPos];
  328. auto echoR = buffer[1][readPos];
  329. // 1-pole low-pass in the feedback path: repeats get darker
  330. damp[0] += dampCoeff * (echoL - damp[0]);
  331. damp[1] += dampCoeff * (echoR - damp[1]);
  332. echoL = damp[0];
  333. echoR = damp[1];
  334. const auto inL = l[i], inR = r[i];
  335. if (pingPong) // mono input on the left side, repeats alternate
  336. {
  337. buffer[0][write] = 0.5f * (inL + inR) + echoR * feedback;
  338. buffer[1][write] = echoL * feedback;
  339. }
  340. else
  341. {
  342. buffer[0][write] = inL + echoL * feedback;
  343. buffer[1][write] = inR + echoR * feedback;
  344. }
  345. l[i] = inL + mix * echoL;
  346. r[i] = inR + mix * echoR;
  347. write = (write + 1) % size;
  348. }
  349. }
  350. private:
  351. double sampleRate = 44100.0;
  352. std::array<std::vector<float>, 2> buffer;
  353. std::size_t write = 0;
  354. float damp[2] {};
  355. };
  356. // ---------------------------------------------------------------------------
  357. // Schroeder/Moorer-style reverb (the "Freeverb" structure, public domain):
  358. // 8 comb filters with low-pass in the feedback + 4 all-passes per side.
  359. class Reverb final : public Effect
  360. {
  361. public:
  362. Reverb()
  363. {
  364. const auto scale = maxSampleRate / 44100.0;
  365. for (int ch = 0; ch < 2; ++ch)
  366. {
  367. for (std::size_t i = 0; i < combTunings.size(); ++i)
  368. combs[ch][i].buffer.assign ((std::size_t) ((combTunings[i] + stereoSpread) * scale) + 2, 0.0f);
  369. for (std::size_t i = 0; i < allpassTunings.size(); ++i)
  370. allpasses[ch][i].buffer.assign ((std::size_t) ((allpassTunings[i] + stereoSpread) * scale) + 2, 0.0f);
  371. }
  372. predelayBuffer.assign ((std::size_t) (maxPredelaySeconds * maxSampleRate) + 4, 0.0f);
  373. }
  374. static constexpr double maxPredelaySeconds = 1.0;
  375. void prepare (double sr) noexcept override
  376. {
  377. sampleRate = sr;
  378. lastLowCut = lastHighCut = -1.0f;
  379. const auto scale = sr / 44100.0;
  380. for (int ch = 0; ch < 2; ++ch)
  381. {
  382. const auto spread = ch == 1 ? stereoSpread : 0;
  383. for (std::size_t i = 0; i < combTunings.size(); ++i)
  384. combs[ch][i].length = std::min (combs[ch][i].buffer.size(), (std::size_t) ((combTunings[i] + spread) * scale));
  385. for (std::size_t i = 0; i < allpassTunings.size(); ++i)
  386. allpasses[ch][i].length = std::min (allpasses[ch][i].buffer.size(), (std::size_t) ((allpassTunings[i] + spread) * scale));
  387. }
  388. reset();
  389. }
  390. void reset() noexcept override
  391. {
  392. for (auto& side : combs)
  393. for (auto& c : side)
  394. {
  395. std::fill (c.buffer.begin(), c.buffer.end(), 0.0f);
  396. c.index = 0;
  397. c.store = 0.0f;
  398. }
  399. for (auto& side : allpasses)
  400. for (auto& a : side)
  401. {
  402. std::fill (a.buffer.begin(), a.buffer.end(), 0.0f);
  403. a.index = 0;
  404. }
  405. std::fill (predelayBuffer.begin(), predelayBuffer.end(), 0.0f);
  406. predelayWrite = 0;
  407. lowCut.reset();
  408. highCut.reset();
  409. }
  410. void process (float* l, float* r, int n, const EffectParams& params, double) noexcept override
  411. {
  412. const auto feedback = 0.7f + params[0] * 0.28f; // room size
  413. const auto damping = params[1] * 0.4f;
  414. const auto width = params[2];
  415. const auto mix = params[3];
  416. const auto dry = params[4]; // 0 = reverb only (reverb on a send)
  417. const auto wet1 = width / 2.0f + 0.5f;
  418. const auto wet2 = (1.0f - width) / 2.0f;
  419. constexpr float inputGain = 0.015f;
  420. // at the wet input: low/high cut (at the extremes = off) and predelay
  421. const auto lowCutHz = params[5], highCutHz = params[6];
  422. const auto useLowCut = lowCutHz > 0.001f, useHighCut = highCutHz < 0.999f;
  423. if (lowCutHz != lastLowCut || highCutHz != lastHighCut)
  424. {
  425. lastLowCut = lowCutHz;
  426. lastHighCut = highCutHz;
  427. lowCut.filter (sampleRate, 1, reverbLowCutHz (lowCutHz), 0.7071);
  428. highCut.filter (sampleRate, 0, reverbHighCutHz (highCutHz), 0.7071);
  429. }
  430. const auto predelay = std::min ((int) (params[7] * maxPredelaySeconds * sampleRate), (int) predelayBuffer.size() - 1);
  431. const auto predelayLength = (int) predelayBuffer.size();
  432. // filter by filter over a chunk (each comb/allpass fully in cache), with the same summing
  433. // order as sample-by-sample processing
  434. constexpr int span = 256;
  435. float input[span], out[2][span];
  436. for (int start = 0; start < n; start += span)
  437. {
  438. const auto m = std::min (span, n - start);
  439. auto* bl = l + start;
  440. auto* br = r + start;
  441. for (int i = 0; i < m; ++i)
  442. {
  443. auto x = (bl[i] + br[i]) * inputGain;
  444. if (useLowCut)
  445. x = lowCut.process (x, 0);
  446. if (useHighCut)
  447. x = highCut.process (x, 0);
  448. if (predelay > 0)
  449. {
  450. predelayBuffer[(std::size_t) predelayWrite] = x;
  451. auto read = predelayWrite - predelay;
  452. if (read < 0)
  453. read += predelayLength;
  454. x = predelayBuffer[(std::size_t) read];
  455. if (++predelayWrite == predelayLength)
  456. predelayWrite = 0;
  457. }
  458. input[i] = x;
  459. }
  460. for (int ch = 0; ch < 2; ++ch)
  461. {
  462. std::fill (out[ch], out[ch] + m, 0.0f);
  463. // 4 combs per loop: the feedback chains are independent and the CPU interleaves
  464. // them (a single comb is bound by the damping filter's latency)
  465. for (std::size_t c = 0; c + 4 <= combs[ch].size(); c += 4)
  466. Comb::process4 (&combs[ch][c], input, out[ch], m, feedback, damping);
  467. for (auto& a : allpasses[ch])
  468. a.process (out[ch], m);
  469. }
  470. for (int i = 0; i < m; ++i)
  471. {
  472. bl[i] = bl[i] * dry + mix * (out[0][i] * wet1 + out[1][i] * wet2);
  473. br[i] = br[i] * dry + mix * (out[1][i] * wet1 + out[0][i] * wet2);
  474. }
  475. }
  476. }
  477. private:
  478. struct Comb
  479. {
  480. std::vector<float> buffer;
  481. std::size_t length = 1, index = 0;
  482. float store = 0.0f;
  483. // four combs at once; sums into `out` in the same order as one by one
  484. static void process4 (Comb* c, const float* input, float* out, int n, float feedback, float damping) noexcept
  485. {
  486. float* buf[4] = { c[0].buffer.data(), c[1].buffer.data(), c[2].buffer.data(), c[3].buffer.data() };
  487. std::size_t idx[4] = { c[0].index, c[1].index, c[2].index, c[3].index };
  488. const std::size_t len[4] = { c[0].length, c[1].length, c[2].length, c[3].length };
  489. float st[4] = { c[0].store, c[1].store, c[2].store, c[3].store };
  490. const auto keep = 1.0f - damping;
  491. for (int i = 0; i < n; ++i)
  492. {
  493. float o[4];
  494. for (int k = 0; k < 4; ++k)
  495. {
  496. o[k] = buf[k][idx[k]];
  497. st[k] = o[k] * keep + st[k] * damping;
  498. buf[k][idx[k]] = input[i] + st[k] * feedback;
  499. if (++idx[k] == len[k])
  500. idx[k] = 0;
  501. }
  502. out[i] = out[i] + o[0] + o[1] + o[2] + o[3];
  503. }
  504. for (int k = 0; k < 4; ++k)
  505. {
  506. c[k].index = idx[k];
  507. c[k].store = st[k];
  508. }
  509. }
  510. };
  511. struct Allpass
  512. {
  513. std::vector<float> buffer;
  514. std::size_t length = 1, index = 0;
  515. void process (float* io, int n) noexcept
  516. {
  517. auto* buf = buffer.data();
  518. auto idx = index;
  519. const auto len = length;
  520. for (int i = 0; i < n; ++i)
  521. {
  522. const auto input = io[i];
  523. const auto delayed = buf[idx];
  524. io[i] = delayed - input;
  525. buf[idx] = input + delayed * 0.5f;
  526. if (++idx == len)
  527. idx = 0;
  528. }
  529. index = idx;
  530. }
  531. };
  532. static constexpr std::array<int, 8> combTunings { 1116, 1188, 1277, 1356, 1422, 1491, 1557, 1617 };
  533. static constexpr std::array<int, 4> allpassTunings { 556, 441, 341, 225 };
  534. static constexpr int stereoSpread = 23;
  535. std::array<std::array<Comb, 8>, 2> combs;
  536. std::array<std::array<Allpass, 4>, 2> allpasses;
  537. double sampleRate = 44100.0;
  538. Biquad lowCut, highCut;
  539. float lastLowCut = -1.0f, lastHighCut = -1.0f;
  540. std::vector<float> predelayBuffer;
  541. int predelayWrite = 0;
  542. };
  543. // ---------------------------------------------------------------------------
  544. // Lookahead limiter: gain starts dropping before the peak arrives (1.5 ms delay,
  545. // reported as latency so PDC aligns it with the other tracks).
  546. class Limiter final : public Effect
  547. {
  548. public:
  549. static constexpr double lookaheadSeconds = 0.0015;
  550. Limiter()
  551. {
  552. const auto size = (std::size_t) (lookaheadSeconds * maxSampleRate) + 4;
  553. delay[0].assign (size, 0.0f);
  554. delay[1].assign (size, 0.0f);
  555. maxValues.assign (size, 0.0f);
  556. maxTimes.assign (size, 0);
  557. }
  558. void prepare (double sr) noexcept override
  559. {
  560. sampleRate = sr;
  561. lookahead = std::max (1, (int) std::lround (lookaheadSeconds * sr));
  562. attack = (float) (1.0 - std::exp (-1.0 / (lookahead * 0.3)));
  563. reset();
  564. }
  565. void reset() noexcept override
  566. {
  567. std::fill (delay[0].begin(), delay[0].end(), 0.0f);
  568. std::fill (delay[1].begin(), delay[1].end(), 0.0f);
  569. position = 0;
  570. gain = 1.0f;
  571. clock = 0;
  572. // the window starts full of zeros: a single 0 candidate covers all of them
  573. head = 0;
  574. count = 1;
  575. maxValues[0] = 0.0f;
  576. maxTimes[0] = -1;
  577. }
  578. int latencySamples() const noexcept override { return lookahead; }
  579. void process (float* l, float* r, int n, const EffectParams& params, double) noexcept override
  580. {
  581. const auto ceiling = dbToGain (limiterCeilingDb (params[0]));
  582. const auto input = dbToGain (limiterGainDb (params[1]));
  583. const auto release = (float) (1.0 - std::exp (-1.0 / (limiterReleaseMs (params[2]) * 0.001 * sampleRate)));
  584. for (int i = 0; i < n; ++i)
  585. {
  586. const auto a = l[i] * input, b = r[i] * input;
  587. const auto peak = std::max (std::abs (a), std::abs (b));
  588. // largest peak among the last `lookahead` samples (sliding maximum with a monotonic queue)
  589. const auto capacity = (int) maxValues.size();
  590. while (count > 0 && maxValues[(std::size_t) ((head + count - 1) % capacity)] <= peak)
  591. --count;
  592. const auto slot = (std::size_t) ((head + count) % capacity);
  593. maxValues[slot] = peak;
  594. maxTimes[slot] = clock;
  595. ++count;
  596. if (maxTimes[(std::size_t) head] <= clock - lookahead)
  597. {
  598. head = (head + 1) % capacity;
  599. --count;
  600. }
  601. ++clock;
  602. const auto ahead = maxValues[(std::size_t) head];
  603. const auto target = ahead > ceiling ? ceiling / ahead : 1.0f;
  604. gain += (target - gain) * (target < gain ? attack : release);
  605. const auto outL = delay[0][(std::size_t) position] * gain;
  606. const auto outR = delay[1][(std::size_t) position] * gain;
  607. delay[0][(std::size_t) position] = a;
  608. delay[1][(std::size_t) position] = b;
  609. if (++position == lookahead)
  610. position = 0;
  611. // safety: never exceed the ceiling
  612. l[i] = std::clamp (outL, -ceiling, ceiling);
  613. r[i] = std::clamp (outR, -ceiling, ceiling);
  614. }
  615. }
  616. private:
  617. double sampleRate = 44100.0;
  618. int lookahead = 64, position = 0;
  619. float attack = 0.1f, gain = 1.0f;
  620. std::array<std::vector<float>, 2> delay;
  621. std::vector<float> maxValues; // monotonic (decreasing) queue for the sliding maximum
  622. std::vector<std::int64_t> maxTimes;
  623. int head = 0, count = 0;
  624. std::int64_t clock = 0;
  625. };
  626. // ---------------------------------------------------------------------------
  627. class Filter final : public Effect
  628. {
  629. public:
  630. void prepare (double sr) noexcept override
  631. {
  632. sampleRate = sr;
  633. last.fill (-1.0f);
  634. reset();
  635. }
  636. void reset() noexcept override { biquad.reset(); }
  637. void process (float* l, float* r, int n, const EffectParams& params, double) noexcept override
  638. {
  639. if (params[0] != last[0] || params[1] != last[1] || params[2] != last[2])
  640. {
  641. last = params;
  642. biquad.filter (sampleRate, filterType (params[0]), filterHz (params[1]), filterQ (params[2]));
  643. }
  644. const auto mix = params[3];
  645. for (int i = 0; i < n; ++i)
  646. {
  647. l[i] += (biquad.process (l[i], 0) - l[i]) * mix;
  648. r[i] += (biquad.process (r[i], 1) - r[i]) * mix;
  649. }
  650. }
  651. private:
  652. double sampleRate = 44100.0;
  653. Biquad biquad;
  654. EffectParams last {};
  655. };
  656. // ---------------------------------------------------------------------------
  657. class Distortion final : public Effect
  658. {
  659. public:
  660. void prepare (double sr) noexcept override
  661. {
  662. sampleRate = sr;
  663. lastTone = -1.0f;
  664. reset();
  665. }
  666. void reset() noexcept override { tone.reset(); }
  667. void process (float* l, float* r, int n, const EffectParams& params, double) noexcept override
  668. {
  669. if (params[1] != lastTone)
  670. {
  671. lastTone = params[1];
  672. tone.filter (sampleRate, 0, distortionToneHz (params[1]), 0.707);
  673. }
  674. const auto drive = dbToGain (distortionDriveDb (params[0]));
  675. const auto mix = params[2];
  676. const auto output = dbToGain ((params[3] - 0.5f) * 24.0f);
  677. // compensate the drive gain so the volume doesn't blow up
  678. const auto compensate = 1.0f / fastTanh (std::max (drive, 1.0f));
  679. for (int i = 0; i < n; ++i)
  680. {
  681. const auto wl = tone.process (fastTanh (l[i] * drive) * compensate, 0);
  682. const auto wr = tone.process (fastTanh (r[i] * drive) * compensate, 1);
  683. l[i] = (l[i] + (wl - l[i]) * mix) * output;
  684. r[i] = (r[i] + (wr - r[i]) * mix) * output;
  685. }
  686. }
  687. private:
  688. double sampleRate = 44100.0;
  689. Biquad tone;
  690. float lastTone = -1.0f;
  691. };
  692. // ---------------------------------------------------------------------------
  693. // Chorus: an LFO-modulated delay line, with opposite phases on L and R.
  694. class Chorus final : public Effect
  695. {
  696. public:
  697. static constexpr double maxSeconds = 0.05;
  698. Chorus()
  699. {
  700. const auto size = (std::size_t) (maxSeconds * maxSampleRate) + 4;
  701. buffer[0].assign (size, 0.0f);
  702. buffer[1].assign (size, 0.0f);
  703. }
  704. void prepare (double sr) noexcept override
  705. {
  706. sampleRate = sr;
  707. length = (int) std::min<std::size_t> (buffer[0].size(), (std::size_t) (maxSeconds * sr) + 4);
  708. reset();
  709. }
  710. void reset() noexcept override
  711. {
  712. std::fill (buffer[0].begin(), buffer[0].end(), 0.0f);
  713. std::fill (buffer[1].begin(), buffer[1].end(), 0.0f);
  714. write = 0;
  715. phase = 0.0;
  716. }
  717. void process (float* l, float* r, int n, const EffectParams& params, double) noexcept override
  718. {
  719. const auto rate = chorusRateHz (params[0]);
  720. const auto depth = chorusDepthMs (params[1]) * 0.001 * sampleRate;
  721. const auto mix = params[2];
  722. const auto feedback = params[3] * 0.7f;
  723. const auto base = 0.012 * sampleRate; // 12 ms
  724. const auto step = rate / sampleRate;
  725. for (int i = 0; i < n; ++i)
  726. {
  727. float* io[2] = { l + i, r + i };
  728. const auto s = sinTurns (phase); // L and R in opposite phases: the same sine with flipped sign
  729. for (int ch = 0; ch < 2; ++ch)
  730. {
  731. const auto lfo = ch == 0 ? s : -s;
  732. const auto delaySamples = base + depth * 0.5 * (1.0 + lfo);
  733. auto readPos = (double) write - delaySamples;
  734. while (readPos < 0.0)
  735. readPos += length;
  736. const auto i0 = (int) readPos;
  737. const auto frac = (float) (readPos - i0);
  738. const auto& buf = buffer[(std::size_t) ch];
  739. const auto next = i0 + 1 == length ? 0 : i0 + 1;
  740. const auto delayed = buf[(std::size_t) i0] + frac * (buf[(std::size_t) next] - buf[(std::size_t) i0]);
  741. buffer[(std::size_t) ch][(std::size_t) write] = *io[ch] + delayed * feedback;
  742. *io[ch] += (delayed - *io[ch]) * mix * 0.5f;
  743. }
  744. if (++write == length)
  745. write = 0;
  746. phase += step;
  747. if (phase >= 1.0)
  748. phase -= 1.0;
  749. }
  750. }
  751. private:
  752. double sampleRate = 44100.0;
  753. std::array<std::vector<float>, 2> buffer;
  754. int length = 1, write = 0;
  755. double phase = 0.0;
  756. };
  757. // ---------------------------------------------------------------------------
  758. // 7-band parametric EQ: each band is a cookbook biquad (or up to 4 in series for the cuts,
  759. // with the Qs of a Butterworth of the requested order).
  760. constexpr std::array<std::array<double, 4>, 4> butterworthQ { { { 0.70710678, 0, 0, 0 },
  761. { 0.54119610, 1.30656296, 0, 0 },
  762. { 0.51763809, 0.70710678, 1.93185165, 0 },
  763. { 0.50979558, 0.60134489, 0.89997622, 2.56291545 } } };
  764. // Stage coefficients of a band; returns the number of stages (0 = band off/transparent).
  765. int bandStages (const EffectParams& p, int band, double sr, std::array<Biquad, 4>& out) noexcept
  766. {
  767. const auto t = peq::type (p[(std::size_t) peq::param (band, 0)]);
  768. const auto hz = std::min (peq::hz (p[(std::size_t) peq::param (band, 1)]), sr * 0.45);
  769. const auto db = peq::gainDb (p[(std::size_t) peq::param (band, 2)]);
  770. const auto q = peq::q (p[(std::size_t) peq::param (band, 3)]);
  771. switch (t)
  772. {
  773. case peq::BandType::off: return 0;
  774. case peq::BandType::peak:
  775. if (std::abs (db) < 0.01)
  776. return 0;
  777. out[0].peaking (sr, hz, q, db);
  778. return 1;
  779. case peq::BandType::lowShelf:
  780. case peq::BandType::highShelf:
  781. if (std::abs (db) < 0.01)
  782. return 0;
  783. out[0].shelf (sr, hz, db, t == peq::BandType::highShelf, std::clamp (q, 0.1, 4.0)); // Q = shelf slope S
  784. return 1;
  785. case peq::BandType::lowCut:
  786. case peq::BandType::highCut:
  787. {
  788. // cascaded: the Qs of a Butterworth of that order, scaled by the band Q (0.707 = Butterworth)
  789. const auto stages = peq::slopeStages (p[(std::size_t) (peq::slopeParam + band)]);
  790. const auto& qs = butterworthQ[(std::size_t) (stages - 1)];
  791. for (int s = 0; s < stages; ++s)
  792. out[(std::size_t) s].filter (sr, t == peq::BandType::lowCut ? 1 : 0, hz, stages == 1 ? q : qs[(std::size_t) s] * q / 0.70710678);
  793. return stages;
  794. }
  795. case peq::BandType::bandPass:
  796. out[0].filter (sr, 2, hz, q);
  797. return 1;
  798. case peq::BandType::notch:
  799. {
  800. const auto w = 2.0 * pi * hz / sr;
  801. const auto alpha = std::sin (w) / (2.0 * q);
  802. out[0].set (1, -2 * std::cos (w), 1, 1 + alpha, -2 * std::cos (w), 1 - alpha);
  803. return 1;
  804. }
  805. }
  806. return 0;
  807. }
  808. class ParametricEq final : public Effect
  809. {
  810. public:
  811. ParametricEq() = default;
  812. // a slot imported from FL: its engine is set up at once, so the latency is known before the first block
  813. explicit ParametricEq (const EffectParams& params)
  814. {
  815. if (peq::flLaw (params))
  816. {
  817. lastParams = params;
  818. flMode = true;
  819. fl.set (peqfl::fromParams (params));
  820. }
  821. }
  822. void prepare (double sr) noexcept override
  823. {
  824. sampleRate = sr;
  825. if (! flMode)
  826. lastParams.fill (-1.0f);
  827. fl.prepare (sr);
  828. reset();
  829. }
  830. void reset() noexcept override
  831. {
  832. for (auto& band : stages)
  833. for (auto& s : band)
  834. s.reset();
  835. fl.reset();
  836. }
  837. int latencySamples() const noexcept override { return flMode ? fl.latencySamples() : 0; }
  838. void process (float* l, float* r, int n, const EffectParams& params, double) noexcept override
  839. {
  840. if (peq::flLaw (params))
  841. {
  842. // FL's Parametric EQ 2 / Parametric EQ, exact (core/ParametricEqFl.h)
  843. if (params != lastParams || ! flMode)
  844. {
  845. lastParams = params;
  846. flMode = true;
  847. fl.set (peqfl::fromParams (params));
  848. }
  849. fl.process (l, r, n);
  850. return;
  851. }
  852. flMode = false;
  853. if (params != lastParams)
  854. {
  855. lastParams = params;
  856. active = 0;
  857. for (int b = 0; b < peq::bands; ++b)
  858. {
  859. std::array<Biquad, 4> fresh;
  860. const auto count = bandStages (params, b, sampleRate, fresh);
  861. // keep the state of filters that remain (no click when turning a knob)
  862. for (int s = 0; s < count; ++s)
  863. {
  864. auto& stage = stages[(std::size_t) b][(std::size_t) s];
  865. stage.b0 = fresh[(std::size_t) s].b0; stage.b1 = fresh[(std::size_t) s].b1; stage.b2 = fresh[(std::size_t) s].b2;
  866. stage.a1 = fresh[(std::size_t) s].a1; stage.a2 = fresh[(std::size_t) s].a2;
  867. }
  868. for (int s = count; s < 4; ++s)
  869. stages[(std::size_t) b][(std::size_t) s].reset();
  870. for (int s = 0; s < count; ++s)
  871. order[(std::size_t) active++] = &stages[(std::size_t) b][(std::size_t) s];
  872. }
  873. output = (float) std::pow (10.0, peq::gainDb (params[peq::outputParam]) / 20.0);
  874. }
  875. for (int k = 0; k < active; ++k)
  876. order[(std::size_t) k]->processBlock (l, r, n);
  877. if (output != 1.0f)
  878. for (int i = 0; i < n; ++i)
  879. {
  880. l[i] *= output;
  881. r[i] *= output;
  882. }
  883. }
  884. private:
  885. double sampleRate = 44100.0;
  886. std::array<std::array<Biquad, 4>, peq::bands> stages;
  887. std::array<Biquad*, peq::bands * 4> order {};
  888. int active = 0;
  889. float output = 1.0f;
  890. EffectParams lastParams {};
  891. peqfl::Engine fl;
  892. bool flMode = false;
  893. };
  894. // ---------------------------------------------------------------------------
  895. // Utility: stereo matrix (L->L, R->L, L->R, R->R), balance and gain.
  896. float utilityGainDb (float v) { return (v - 0.5f) * 48.0f; } // ±24 dB
  897. float utilityMatrix (float v) { return v * 4.0f - 2.0f; } // −2..2 (0.75 = 1.0)
  898. // Volume gate: 32 steps per 4-beat bar (Gross Beat's "volume"). Per-step gain,
  899. // mix with the original signal and attack/release smoothing.
  900. namespace gate
  901. {
  902. constexpr int steps = 32;
  903. constexpr int mixParam = 32, attackParam = 33, releaseParam = 34;
  904. inline double attackMs (float v) { return std::pow (501.0, (double) v) - 1.0; }
  905. inline double releaseMs (float v) { return 2.0 * (std::pow (501.0, (double) v) - 1.0); }
  906. } // namespace gate
  907. class VolumeGate final : public Effect
  908. {
  909. public:
  910. void prepare (double sr) noexcept override { sampleRate = sr; }
  911. void reset() noexcept override { gain = 1.0f; }
  912. void setSongPosition (double ticks) noexcept override { tick = ticks; }
  913. void process (float* l, float* r, int n, const EffectParams& p, double bpm) noexcept override
  914. {
  915. const auto mix = std::clamp (p[gate::mixParam], 0.0f, 1.0f);
  916. const auto up = (float) (1.0 - std::exp (-1.0 / (std::max (0.05, gate::attackMs (p[gate::attackParam])) * 0.001 * sampleRate)));
  917. const auto down = (float) (1.0 - std::exp (-1.0 / (std::max (0.05, gate::releaseMs (p[gate::releaseParam])) * 0.001 * sampleRate)));
  918. const auto ticksPerSample = std::max (1.0, bpm) / 60.0 * ppq / sampleRate;
  919. const auto bar = 4.0 * ppq;
  920. auto position = std::fmod (std::max (0.0, tick), bar);
  921. for (int i = 0; i < n; ++i)
  922. {
  923. const auto step = std::clamp ((int) (position / bar * gate::steps), 0, gate::steps - 1);
  924. const auto target = 1.0f - mix + mix * std::clamp (p[(std::size_t) step], 0.0f, 1.0f);
  925. gain += (target - gain) * (target > gain ? up : down);
  926. l[i] *= gain;
  927. r[i] *= gain;
  928. position += ticksPerSample;
  929. if (position >= bar)
  930. position -= bar;
  931. }
  932. tick += ticksPerSample * n;
  933. }
  934. private:
  935. double sampleRate = 44100.0, tick = 0.0;
  936. float gain = 1.0f;
  937. };
  938. // Real-time pitch shift: two read heads on a delay line whose delay varies as a sawtooth
  939. // (the "rotating tape"); when one head wraps around, the other is mid-window and the
  940. // sine/cosine crossfade hides the jump. Parameters: semitones (±24), cents (±100), mix, window.
  941. namespace pitch
  942. {
  943. inline double semitones (float v) { return std::round ((std::clamp ((double) v, 0.0, 1.0) - 0.5) * 48.0); }
  944. inline double cents (float v) { return (std::clamp ((double) v, 0.0, 1.0) - 0.5) * 200.0; }
  945. inline double windowMs (float v) { return 20.0 + 100.0 * std::clamp ((double) v, 0.0, 1.0); }
  946. } // namespace pitch
  947. class PitchShift final : public Effect
  948. {
  949. public:
  950. static constexpr double maxSeconds = 0.13;
  951. PitchShift()
  952. {
  953. const auto size = (std::size_t) (maxSeconds * maxSampleRate) + 8;
  954. buffer[0].assign (size, 0.0f);
  955. buffer[1].assign (size, 0.0f);
  956. }
  957. void prepare (double sr) noexcept override
  958. {
  959. sampleRate = sr;
  960. length = (int) std::min<std::size_t> (buffer[0].size(), (std::size_t) (maxSeconds * sr) + 8);
  961. reset();
  962. }
  963. void reset() noexcept override
  964. {
  965. std::fill (buffer[0].begin(), buffer[0].end(), 0.0f);
  966. std::fill (buffer[1].begin(), buffer[1].end(), 0.0f);
  967. write = 0;
  968. phase = 0.0;
  969. }
  970. void process (float* l, float* r, int n, const EffectParams& p, double) noexcept override
  971. {
  972. const auto ratio = std::pow (2.0, (pitch::semitones (p[0]) + pitch::cents (p[1]) / 100.0) / 12.0);
  973. const auto mix = std::clamp (p[2], 0.0f, 1.0f);
  974. const auto window = std::min (pitch::windowMs (p[3]) * 0.001 * sampleRate, (double) length - 4.0);
  975. const auto step = (1.0 - ratio) / window; // the delay grows (pitch down) or shrinks (pitch up)
  976. for (int i = 0; i < n; ++i)
  977. {
  978. float* io[2] = { l + i, r + i };
  979. buffer[0][(std::size_t) write] = *io[0];
  980. buffer[1][(std::size_t) write] = *io[1];
  981. const auto phaseB = phase + 0.5 >= 1.0 ? phase - 0.5 : phase + 0.5;
  982. const auto gainA = (float) std::sin (3.141592653589793 * phase);
  983. const auto gainB = (float) std::sin (3.141592653589793 * phaseB);
  984. for (int c = 0; c < 2; ++c)
  985. {
  986. const auto shifted = gainA * read (c, 1.0 + phase * window) + gainB * read (c, 1.0 + phaseB * window);
  987. *io[c] += (shifted - *io[c]) * mix;
  988. }
  989. phase += step;
  990. phase -= std::floor (phase);
  991. if (++write >= length)
  992. write = 0;
  993. }
  994. }
  995. private:
  996. float read (int c, double delay) const noexcept
  997. {
  998. auto position = (double) write - delay;
  999. while (position < 0.0)
  1000. position += length;
  1001. const auto i0 = (int) position;
  1002. const auto frac = (float) (position - i0);
  1003. const auto i1 = i0 + 1 >= length ? 0 : i0 + 1;
  1004. const auto& b = buffer[(std::size_t) c];
  1005. return b[(std::size_t) i0] + (b[(std::size_t) i1] - b[(std::size_t) i0]) * frac;
  1006. }
  1007. std::array<std::vector<float>, 2> buffer;
  1008. double sampleRate = 44100.0, phase = 0.0;
  1009. int length = 1, write = 0;
  1010. };
  1011. // Frequency shifter: the analytic signal (quadrature pair from two chains of 2nd-order allpasses
  1012. // in z², a ~90° "Hilbert transformer" over the useful range) multiplied by a complex oscillator.
  1013. // Parameters: shift (±2 kHz, quadratic curve around the center), mix, stereo spread
  1014. // (the right side shifts the opposite way).
  1015. namespace fshift
  1016. {
  1017. inline double hz (float v)
  1018. {
  1019. const auto x = (std::clamp ((double) v, 0.0, 1.0) - 0.5) * 2.0;
  1020. return 2000.0 * x * std::abs (x);
  1021. }
  1022. } // namespace fshift
  1023. // Lo-fi: holds each sample for 128·t³ + 1 samples and quantizes to 65536/(2048·b² + 1) levels
  1024. // (the laws of FL Effector's Lo-fi, REA_rodada18 §3.2); linear dry/wet mix.
  1025. namespace lofi
  1026. {
  1027. int holdSamples (float v) { return (int) (128.0f * v * v * v) + 1; }
  1028. double levels (float v) { return 65536.0 / (2048.0 * v * v + 1.0); }
  1029. } // namespace lofi
  1030. // Crossover (a band of FL's Frequency Splitter, REA_rodada17 §1.2): high-pass and/or low-pass with the
  1031. // structure of each slope — 6 dB: 1st order; 12: 1 biquad Q 0.5 (inverted HP); 18: Butterworth 3
  1032. // (in FL it is an undocumented all-pass structure: approximation); 24: 2× Q 0.707; 36: Q 0.5412/1.3066/
  1033. // 0.7070 (inverted HP); 48: Butterworth 4 squared; 72: Butterworth 6 squared; 96: Butterworth 8
  1034. // squared. Parameters: 0 HP on, 1 HP cutoff, 2 HP slope, 3 LP on, 4 LP cutoff, 5 LP slope.
  1035. namespace xover
  1036. {
  1037. double hz (float v) { return 30.0 * std::pow (2.0, 9.0589 * std::clamp (v, 0.0f, 1.0f)); }
  1038. int combo (float v) { return std::clamp ((int) std::lround (v * 7.0f), 0, 7); }
  1039. constexpr int dbPerOctave[8] { 6, 12, 18, 24, 36, 48, 72, 96 };
  1040. struct Design
  1041. {
  1042. std::vector<double> qs; // 2nd-order biquads
  1043. bool firstOrder = false;
  1044. bool invertHighPass = false;
  1045. };
  1046. Design design (int c)
  1047. {
  1048. switch (c)
  1049. {
  1050. case 0: return { {}, true, false };
  1051. case 1: return { { 0.5 }, false, true };
  1052. case 2: return { { 1.0 }, true, false };
  1053. case 3: return { { 0.7071, 0.7071 }, false, false };
  1054. case 4: return { { 0.5412, 1.3066, 0.7070 }, false, true };
  1055. case 5: return { { 0.5412, 1.3066, 0.5412, 1.3066 }, false, false };
  1056. case 6: return { { 0.5176, 0.7071, 1.9319, 0.5176, 0.7071, 1.9319 }, false, false };
  1057. default: return { { 0.5098, 0.6013, 0.9000, 2.5629, 0.5098, 0.6013, 0.9000, 2.5629 }, false, false };
  1058. }
  1059. }
  1060. } // namespace xover
  1061. class Crossover final : public Effect
  1062. {
  1063. public:
  1064. void prepare (double sr) noexcept override
  1065. {
  1066. sampleRate = sr;
  1067. last.fill (-1.0f);
  1068. reset();
  1069. }
  1070. void reset() noexcept override
  1071. {
  1072. for (auto& side : sides)
  1073. {
  1074. for (auto& b : side.biquads)
  1075. b.reset();
  1076. side.firstState[0] = side.firstState[1] = 0.0;
  1077. side.firstIn[0] = side.firstIn[1] = 0.0;
  1078. }
  1079. }
  1080. void process (float* l, float* r, int n, const EffectParams& p, double) noexcept override
  1081. {
  1082. if (p[0] != last[0] || p[1] != last[1] || p[2] != last[2] || p[3] != last[3] || p[4] != last[4] || p[5] != last[5])
  1083. {
  1084. for (int i = 0; i < 6; ++i)
  1085. last[(std::size_t) i] = p[(std::size_t) i];
  1086. configure (sides[0], p[0] > 0.5f, true, xover::hz (p[1]), xover::combo (p[2]));
  1087. configure (sides[1], p[3] > 0.5f, false, xover::hz (p[4]), xover::combo (p[5]));
  1088. }
  1089. for (auto& side : sides)
  1090. if (side.active)
  1091. for (int i = 0; i < n; ++i)
  1092. {
  1093. l[i] = (float) side.process (l[i], 0);
  1094. r[i] = (float) side.process (r[i], 1);
  1095. }
  1096. }
  1097. private:
  1098. struct Side
  1099. {
  1100. bool active = false, highPass = false, firstOrder = false;
  1101. double sign = 1.0;
  1102. std::array<Biquad, 8> biquads;
  1103. int count = 0;
  1104. double a = 0.0; // 1st order (bilinear transform)
  1105. double firstState[2] {}, firstIn[2] {};
  1106. double process (double x, int ch) noexcept
  1107. {
  1108. if (firstOrder)
  1109. {
  1110. // 1st-order low-pass: y = a·(x + x[n−1]) + (1 − 2a)·y[n−1]; the high-pass is the complement
  1111. const auto lp = a * (x + firstIn[ch]) + (1.0 - 2.0 * a) * firstState[ch];
  1112. firstIn[ch] = x;
  1113. firstState[ch] = lp;
  1114. x = highPass ? x - lp : lp;
  1115. }
  1116. for (int i = 0; i < count; ++i)
  1117. x = biquads[(std::size_t) i].process (x, ch);
  1118. return sign * x;
  1119. }
  1120. };
  1121. void configure (Side& side, bool on, bool highPass, double hz, int combo)
  1122. {
  1123. side.active = on;
  1124. if (! on)
  1125. return;
  1126. const auto d = xover::design (combo);
  1127. side.highPass = highPass;
  1128. side.firstOrder = d.firstOrder;
  1129. side.sign = highPass && d.invertHighPass ? -1.0 : 1.0;
  1130. side.count = (int) d.qs.size();
  1131. const auto f = std::clamp (hz, 10.0, 0.49 * sampleRate);
  1132. const auto k = std::tan (3.141592653589793 * f / sampleRate);
  1133. side.a = k / (1.0 + k);
  1134. for (int i = 0; i < side.count; ++i)
  1135. side.biquads[(std::size_t) i].filter (sampleRate, highPass ? 1 : 0, f, d.qs[(std::size_t) i]);
  1136. }
  1137. double sampleRate = 44100.0;
  1138. std::array<Side, 2> sides {};
  1139. std::array<float, 6> last {};
  1140. };
  1141. // Rhythmic envelope (REA_rodada20 §1.2/§1.3): period in beats, up to 12 points (position 0..1 in the period, level,
  1142. // tension); the value between two points follows the curve of the destination point. Parameters: 0 period/64 beats,
  1143. // 1 point count/12, then 3 per point (position, level, (tension + 1)/2).
  1144. namespace rhythm
  1145. {
  1146. constexpr int maxPoints = 12;
  1147. double curve (double x, double t) noexcept
  1148. {
  1149. if (std::abs (t) < 1e-6)
  1150. return x;
  1151. const auto q = std::pow (1000001.0, std::abs (t)) - 1.0;
  1152. return t > 0.0 ? 1.0 - (std::pow (1.0 + q, 1.0 - x) - 1.0) / q : (std::pow (1.0 + q, x) - 1.0) / q;
  1153. }
  1154. double valueAt (const EffectParams& p, double u) noexcept
  1155. {
  1156. const auto count = std::clamp ((int) std::lround (p[1] * maxPoints), 0, maxPoints);
  1157. if (count == 0)
  1158. return 1.0;
  1159. auto prevX = 0.0, prevY = (double) p[3];
  1160. for (int k = 0; k < count; ++k)
  1161. {
  1162. const auto x = (double) p[(std::size_t) (2 + 3 * k)], y = (double) p[(std::size_t) (3 + 3 * k)];
  1163. if (u < x)
  1164. {
  1165. const auto f = x > prevX ? (u - prevX) / (x - prevX) : 1.0;
  1166. return prevY + (y - prevY) * curve (f, 2.0 * p[(std::size_t) (4 + 3 * k)] - 1.0);
  1167. }
  1168. prevX = x;
  1169. prevY = y;
  1170. }
  1171. return prevY;
  1172. }
  1173. } // namespace rhythm
  1174. class RhythmGain final : public Effect
  1175. {
  1176. public:
  1177. void prepare (double sr) noexcept override { sampleRate = sr; }
  1178. void reset() noexcept override {}
  1179. void setSongPosition (double ticks) noexcept override { beats = ticks / 960.0; }
  1180. void process (float* l, float* r, int n, const EffectParams& p, double bpm) noexcept override
  1181. {
  1182. const auto period = std::max (1e-3, (double) p[0] * 64.0);
  1183. const auto step = std::max (bpm, 1.0) / 60.0 / sampleRate;
  1184. if (p[38] > 0.5f) // control only: the value becomes a live automation source, audio passes through untouched
  1185. {
  1186. const auto t = beats + step * n;
  1187. current = (float) rhythm::valueAt (p, (t - std::floor (t / period) * period) / period);
  1188. return;
  1189. }
  1190. for (int i = 0; i < n; ++i)
  1191. {
  1192. const auto t = beats + step * i;
  1193. const auto g = (float) rhythm::valueAt (p, (t - std::floor (t / period) * period) / period);
  1194. l[i] *= g;
  1195. r[i] *= g;
  1196. current = g;
  1197. }
  1198. }
  1199. float controlOutput (int) const noexcept override { return current; }
  1200. private:
  1201. double sampleRate = 44100.0, beats = 0.0;
  1202. float current = 1.0f;
  1203. };
  1204. // Auto-pan (REA_rodada20 §1.5): triangle (+1 at φ = 0, −1 at 0.5) with phase 0.75 + offset + beats/period.
  1205. // Parameters: 0 period/64 beats, 1 depth ((a + 1)/2, a = maximum pan excursion), 2 phase
  1206. // offset (cycles), 3 fixed pan ((p + 1)/2). Pan law: the utility's balance (FL's has not been decoded).
  1207. } // namespace
  1208. // FL's mode-0 pan law (REA_rodada27 §3.1): G_L = √2·cos((1 + pan)π/4), G_R = √2·sin((1 + pan)π/4) (unit volume),
  1209. // the near side keeps 1 − f/2 of its input and gets f/2 of the other, f = 1 − (far gain); no clamp of pan
  1210. void flPanMatrix (double pan, float& ll, float& rl, float& lr, float& rr) noexcept
  1211. {
  1212. const auto angle = (1.0 + pan) * 3.141592653589793 / 4.0;
  1213. const auto gl = std::sqrt (2.0) * std::cos (angle), gr = std::sqrt (2.0) * std::sin (angle);
  1214. ll = (float) gl, rr = (float) gr, rl = lr = 0.0f;
  1215. if (pan < 0.0)
  1216. {
  1217. const auto f = 1.0 - gr;
  1218. ll = (float) (gl * (1.0 - f / 2.0));
  1219. rl = (float) (gl * f / 2.0);
  1220. }
  1221. else if (pan > 0.0)
  1222. {
  1223. const auto f = 1.0 - gl;
  1224. rr = (float) (gr * (1.0 - f / 2.0));
  1225. lr = (float) (gr * f / 2.0);
  1226. }
  1227. }
  1228. namespace
  1229. {
  1230. // Fruity Squeeze (REA_rodada29 §2), float32 like FL: silence bypass per block → (filter, pre) → quantiser
  1231. // Lq = 32768^(1 − Steps/32768) → periodic gate Impact/Preserve (samples at 44.1 kHz × fs/44100) → (filter, post)
  1232. // → (dry·(128 − Mix) + wet·Mix)/128 × Volume/127. The SVF (2 passes per sample, LP/HP/BP/notch/peak) is always
  1233. // designed for 44.1 kHz, whatever the rate (as FL does). Parameters are FL's raw values divided by their maximum.
  1234. } // namespace
  1235. const std::array<float, 12> squeezeMax { 160, 128, 32768, 1, 4, 65536, 65536, 1, 3, 44100, 44100, 65536 };
  1236. namespace
  1237. {
  1238. class Squeeze final : public Effect
  1239. {
  1240. public:
  1241. void prepare (double sr) noexcept override
  1242. {
  1243. rate = (float) (sr / 44100.0);
  1244. reset();
  1245. }
  1246. void reset() noexcept override
  1247. {
  1248. for (auto& f : filters)
  1249. f.low = f.band = 0.0f;
  1250. counterA = counterB = 0.0f;
  1251. gateOn = false;
  1252. last.fill (-1.0f);
  1253. }
  1254. void process (float* l, float* r, int n, const EffectParams& p, double) noexcept override
  1255. {
  1256. bool changed = false;
  1257. for (std::size_t i = 0; i < 12; ++i)
  1258. if (p[i] != last[i])
  1259. last[i] = p[i], changed = true;
  1260. if (changed)
  1261. configure (p);
  1262. bool silent = true;
  1263. for (int i = 0; i < n && silent; ++i)
  1264. silent = std::abs (l[i]) <= 1e-6f && std::abs (r[i]) <= 1e-6f;
  1265. if (silent)
  1266. return; // FL leaves (near-)silent blocks untouched
  1267. for (int i = 0; i < n; ++i)
  1268. {
  1269. const float dryL = l[i], dryR = r[i];
  1270. float x[2] { l[i], r[i] };
  1271. if (! post && filterOn)
  1272. for (int c = 0; c < 2; ++c)
  1273. x[c] = filters[(std::size_t) c].tick (x[c], type, coefF, coefQ);
  1274. if (steps < 32768.0f)
  1275. for (auto& v : x)
  1276. v = (float) std::nearbyint (v * steps) / steps; // round half to even, like the DLL
  1277. if (impact > 0.0f)
  1278. {
  1279. float w0, w1;
  1280. if (! gateOn)
  1281. {
  1282. if (counterA <= preserve)
  1283. counterA += 1.0f, w1 = 0.0f, w0 = 1.0f;
  1284. else
  1285. {
  1286. gateOn = true;
  1287. const auto fr = counterA - preserve;
  1288. w1 = fr, w0 = 1.0f - fr, counterB = fr, counterA = 0.0f;
  1289. }
  1290. }
  1291. else if (counterB <= impact)
  1292. counterB += 1.0f, w1 = 1.0f, w0 = 0.0f;
  1293. else
  1294. {
  1295. gateOn = false;
  1296. const auto fr = counterB - impact;
  1297. w1 = 1.0f - fr, w0 = fr, counterB = 0.0f, counterA = fr;
  1298. }
  1299. const auto g = (float) (amountRaw * 1.52587890625e-05 * w1);
  1300. for (auto& v : x)
  1301. v = g * v + w0 * v;
  1302. }
  1303. if (post && filterOn)
  1304. for (int c = 0; c < 2; ++c)
  1305. x[c] = filters[(std::size_t) c].tick (x[c], type, coefF, coefQ);
  1306. l[i] = (dryL * dry + x[0] * wet) * gain;
  1307. r[i] = (dryR * dry + x[1] * wet) * gain;
  1308. }
  1309. }
  1310. private:
  1311. struct Svf
  1312. {
  1313. float low = 0.0f, band = 0.0f;
  1314. float tick (float in, int mode, float f, float q) noexcept
  1315. {
  1316. constexpr float tiny = 1.1754943508222875e-38f;
  1317. if (std::abs (in) < tiny)
  1318. in = 0.0f;
  1319. float acc[5] {};
  1320. for (int k = 0; k < 2; ++k)
  1321. {
  1322. auto t = in - q * band;
  1323. if (std::abs (t) < tiny)
  1324. t = 0.0f;
  1325. low = low + f * band;
  1326. const auto high = t - low;
  1327. band = f * high + band;
  1328. const float values[5] { low, band, high, t, low - high };
  1329. for (int i = 0; i < 5; ++i)
  1330. acc[i] += values[i] * 0.5f;
  1331. }
  1332. static constexpr int pick[5] { 0, 2, 1, 3, 4 }; // FL's types: LP, HP, BP, notch, peak
  1333. return acc[pick[std::clamp (mode, 0, 4)]];
  1334. }
  1335. };
  1336. int raw (const EffectParams& p, int k) const noexcept { return (int) std::lround (std::clamp (p[(std::size_t) k], 0.0f, 1.0f) * squeezeMax[(std::size_t) k]); }
  1337. void configure (const EffectParams& p) noexcept
  1338. {
  1339. gain = (float) raw (p, 0) * (1.0f / 127.0f);
  1340. const auto mix = (float) raw (p, 1);
  1341. dry = (128.0f - mix) / 128.0f;
  1342. wet = mix / 128.0f;
  1343. steps = std::pow (32768.0f, 1.0f - (float) raw (p, 2) / 32768.0f);
  1344. filterOn = raw (p, 3) != 0;
  1345. type = raw (p, 4);
  1346. post = raw (p, 7) == 1;
  1347. amountRaw = raw (p, 11);
  1348. auto gateLength = [this] (int v) { return (std::pow (44101.0f, (float) v / 44100.0f) - 1.0f) * rate; };
  1349. const auto preserveRaw = raw (p, 10);
  1350. auto impactRaw = raw (p, 9);
  1351. switch (raw (p, 8)) // Relation: Impact follows Preserve
  1352. {
  1353. case 1: impactRaw = preserveRaw; break;
  1354. case 2: impactRaw = preserveRaw * 2; break;
  1355. case 3: impactRaw = preserveRaw >> 1; break;
  1356. default: break;
  1357. }
  1358. impact = gateLength (impactRaw);
  1359. preserve = gateLength (preserveRaw);
  1360. // SVF at 44.1 kHz: cutoff exp-mapped between 50 Hz and 0.75·44100, q = min(2, 2/f − f/2, 2(1 − res^0.25))
  1361. const float fs = 44100.0f, lo = 50.0f, hi = fs * 0.75f;
  1362. const auto x = (float) raw (p, 6) / 65536.0f, res = (float) raw (p, 5) / 65536.0f;
  1363. auto hz = std::exp (x * (std::log (hi) - std::log (lo)) + std::log (lo));
  1364. hz = std::clamp (hz, lo, hi);
  1365. const auto ratio = std::min (hz / (fs * 2.0f), 0.25f);
  1366. coefF = (float) (std::sin (ratio * 3.141592653589793) * 2.0);
  1367. const auto a = (1.0f - std::pow (res, 0.25f)) * 2.0f;
  1368. coefQ = std::min (std::min (2.0f / coefF - coefF * 0.5f, 2.0f), a);
  1369. }
  1370. float rate = 1.0f, gain = 1.0f, dry = 0.5f, wet = 0.5f, steps = 32768.0f, impact = 0.0f, preserve = 0.0f;
  1371. float coefF = 0.5f, coefQ = 1.0f, counterA = 0.0f, counterB = 0.0f;
  1372. int type = 0, amountRaw = 0;
  1373. bool filterOn = false, post = false, gateOn = false;
  1374. std::array<Svf, 2> filters {};
  1375. std::array<float, 12> last {};
  1376. };
  1377. class AutoPan final : public Effect
  1378. {
  1379. public:
  1380. void prepare (double sr) noexcept override { sampleRate = sr; rhythm.prepare (sr); dcA = (float) std::exp (-2.0 * 3.14159265358979323846 * 8.0 / sr); }
  1381. void reset() noexcept override { rhythm.reset(); lfo = 0.0; smooth = 0.0; dcX[0] = dcX[1] = dcY[0] = dcY[1] = 0.0f; }
  1382. void setSongPosition (double ticks) noexcept override { beats = ticks / 960.0; }
  1383. void process (float* l, float* r, int n, const EffectParams& p, double bpm) noexcept override
  1384. {
  1385. constexpr int rb = autopan::count; // round 136's Rhythm voicing params follow round 135's panner params
  1386. if (p.size() > rb + 11 && p[rb] > 0.5f) // round 136: the Rhythm voicing (core/RhythmPan.h)
  1387. {
  1388. rhythmpan::Settings s;
  1389. s.rateHz = rhythmpan::rateHz (p[rb + 1]);
  1390. s.sync = p[rb + 2] > 0.5f;
  1391. s.beats = rhythmpan::beats (p[rb + 3]);
  1392. s.width = 210.0 * std::clamp ((double) p[rb + 4], 0.0, 1.0);
  1393. s.offset = -105.0 + 210.0 * std::clamp ((double) p[rb + 5], 0.0, 1.0);
  1394. s.smoothing = std::clamp ((double) p[rb + 6], 0.0, 1.0);
  1395. s.pattern = p[rb + 7] > 0.5f ? 1 : 0;
  1396. s.amount = std::clamp ((double) p[rb + 8], 0.0, 1.0);
  1397. s.phase = std::clamp ((double) p[rb + 9], 0.0, 1.0);
  1398. s.analog = p[rb + 10] < 0.25f ? 0 : (p[rb + 10] < 0.75f ? 1 : 2); // off / analog / hot
  1399. s.outputDb = -24.0 + 48.0 * std::clamp ((double) p[rb + 11], 0.0, 1.0);
  1400. if (! (s == rhythmSet))
  1401. {
  1402. rhythm.set (s);
  1403. rhythmSet = s;
  1404. }
  1405. rhythm.process (l, r, n, beats, bpm);
  1406. current = rhythm.currentPan();
  1407. position.store (current, std::memory_order_relaxed);
  1408. beats += n * std::max (bpm, 1.0) / 60.0 / sampleRate;
  1409. return;
  1410. }
  1411. if (autopan::sourceOf (p[autopan::source]) != autopan::Source::fl)
  1412. {
  1413. processPanner (l, r, n, p, bpm);
  1414. return;
  1415. }
  1416. const auto period = std::max (1e-3, (double) p[0] * 64.0);
  1417. const auto depth = 2.0 * p[1] - 1.0, fixed = 2.0 * p[3] - 1.0;
  1418. const auto step = std::max (bpm, 1.0) / 60.0 / sampleRate / period;
  1419. auto phase = 0.75 + p[2] + beats / period;
  1420. {
  1421. const auto f = phase + step * n - std::floor (phase + step * n);
  1422. current = (float) ((f < 0.5 ? 1.0 - 4.0 * f : -3.0 + 4.0 * f) + 1.0) * 0.5f; // wave in 0..1
  1423. }
  1424. position.store (0.5f * (float) (std::clamp (fixed + depth * (2.0 * current - 1.0), -1.0, 1.0) + 1.0), std::memory_order_relaxed);
  1425. if (p[4] > 0.5f) // control only (live automation source)
  1426. return;
  1427. // LFO tension (Love Philter, REA_rodada27 §3.3): applied to |w| with the sign kept, T = 256·(p6 − 0.5)
  1428. const auto tension = 256.0 * (p[6] - 0.5);
  1429. const auto q = tension == 0.0 ? 0.0 : (tension > 0.0 ? 1.0 : -1.0) * (std::pow (1e18, 0.05 * (std::pow (21.0, std::abs (tension) / 128.0) - 1.0)) - 1.0);
  1430. const auto flLaw = p[5] > 0.5f;
  1431. for (int i = 0; i < n; ++i, phase += step)
  1432. {
  1433. const auto f = phase - std::floor (phase);
  1434. auto w = f < 0.5 ? 1.0 - 4.0 * f : -3.0 + 4.0 * f;
  1435. if (q != 0.0)
  1436. {
  1437. const auto y = std::abs (w);
  1438. const auto shaped = q > 0.0 ? 1.0 - (std::pow (1.0 + q, 1.0 - y) - 1.0) / q : (std::pow (1.0 - q, y) - 1.0) / -q;
  1439. w = w < 0.0 ? -shaped : shaped;
  1440. }
  1441. if (flLaw) // FL's mode-0 pan law with the far side folded into the near one (REA_rodada27 §3.1)
  1442. {
  1443. float ll, rl, lr, rr;
  1444. flPanMatrix (fixed + depth * w, ll, rl, lr, rr);
  1445. const auto a = l[i], b = r[i];
  1446. l[i] = ll * a + rl * b;
  1447. r[i] = lr * a + rr * b;
  1448. continue;
  1449. }
  1450. const auto pan = std::clamp (fixed + depth * w, -1.0, 1.0);
  1451. l[i] *= (float) (pan > 0.0 ? 1.0 - pan : 1.0);
  1452. r[i] *= (float) (pan < 0.0 ? 1.0 + pan : 1.0);
  1453. }
  1454. }
  1455. // 0: the wave (0..1), 1: the pan position (0 = left, 0.5 = centre, 1 = right; round 135's display)
  1456. float controlOutput (int o) const noexcept override
  1457. {
  1458. switch (o)
  1459. {
  1460. case 1: return position.load (std::memory_order_relaxed);
  1461. case 2: return peakIn.load (std::memory_order_relaxed);
  1462. case 3: return peakOut.load (std::memory_order_relaxed);
  1463. default: return current;
  1464. }
  1465. }
  1466. private:
  1467. // round 135: the rhythmic panner's sources (the PanMan role), measured black-box on the official trial
  1468. // (docs/analise/REA_rodada135s.md §3): an equal-power balance (centre −3 dB per side, the far side silent at the
  1469. // extremes), a free LFO in Hz or steps on the beat grid swept back and forth or one way, Smoothing from a hard
  1470. // square / jump to a soft sine / glide, input and output gains and an "analog" stage (asymmetric soft saturation:
  1471. // H2 −36 dBc and H3 −54 dBc at −18 dBFS, H2 −25 / H3 −30 at −6 dBFS)
  1472. void processPanner (float* l, float* r, int n, const EffectParams& p, double bpm) noexcept
  1473. {
  1474. using namespace autopan;
  1475. const auto src = sourceOf (p[source]);
  1476. const auto dir = directionOf (p[direction]);
  1477. const auto soft = std::clamp ((double) p[smoothing], 0.0, 1.0);
  1478. const auto depth = 2.0 * p[1] - 1.0, fixed = 2.0 * p[3] - 1.0;
  1479. const auto gIn = (float) std::pow (10.0, inputDb (p[inputGain]) / 20.0);
  1480. const auto gOut = (float) std::pow (10.0, inputDb (p[outputGain]) / 20.0);
  1481. const auto analog = p[analogStage] >= 0.5f;
  1482. const auto k = 0.05 + 12.0 * (1.0 - soft) * (1.0 - soft); // the sine's hardness (soft = a sine, hard ≈ a square)
  1483. const auto tk = std::tanh (k);
  1484. const auto steps = stepCount (p[stepsParam]);
  1485. // the period of one cycle: the free rate (Hz), or the steps on the beat grid
  1486. double inc;
  1487. if (src == Source::lfo)
  1488. inc = rateHz (p[rate]) / sampleRate;
  1489. else
  1490. inc = std::max (bpm, 1.0) / 60.0 / sampleRate / (stepBeats (p[stepNote]) * (dir == Direction::both ? 2.0 * (steps - 1) : steps));
  1491. // rhythm steps follow the song position (like the FL source); the LFO runs freely
  1492. if (src == Source::steps && beats != syncedBeats) // a new song position: back on the grid
  1493. {
  1494. lfo = beats / (stepBeats (p[stepNote]) * (dir == Direction::both ? 2.0 * (steps - 1) : steps));
  1495. syncedBeats = beats;
  1496. }
  1497. // steps glide over up to a third of a step (Smoothing 100 %), or jump (0 %)
  1498. const auto stepSec = stepBeats (p[stepNote]) * 60.0 / std::max (bpm, 1.0);
  1499. const auto glide = 1.0 - std::exp (-1.0 / (sampleRate * (0.0005 + 0.35 * soft * stepSec)));
  1500. float pos = 0.0f, pin = 0.0f, pout = 0.0f;
  1501. for (int i = 0; i < n; ++i, lfo += inc)
  1502. {
  1503. const auto f = lfo - std::floor (lfo);
  1504. double w; // −1 … +1
  1505. if (src == Source::lfo)
  1506. {
  1507. if (dir == Direction::both)
  1508. w = std::tanh (k * std::sin (2.0 * 3.14159265358979323846 * f)) / tk;
  1509. else
  1510. w = dir == Direction::right ? 2.0 * f - 1.0 : 1.0 - 2.0 * f;
  1511. smooth = w;
  1512. }
  1513. else
  1514. {
  1515. int s;
  1516. if (dir == Direction::both)
  1517. {
  1518. const auto span = 2 * (steps - 1);
  1519. const auto at = (int) std::floor (f * span);
  1520. s = at < steps ? at : span - at;
  1521. }
  1522. else
  1523. {
  1524. s = std::min (steps - 1, (int) std::floor (f * steps));
  1525. if (dir == Direction::left) s = steps - 1 - s;
  1526. }
  1527. const auto target = steps > 1 ? -1.0 + 2.0 * s / (steps - 1) : 0.0;
  1528. smooth += glide * (target - smooth);
  1529. w = smooth;
  1530. }
  1531. const auto pan = std::clamp (fixed + depth * w, -1.0, 1.0);
  1532. const auto th = (pan + 1.0) * 0.25 * 3.14159265358979323846;
  1533. pin = std::max (pin, std::max (std::abs (l[i]), std::abs (r[i])));
  1534. float a = l[i] * gIn, b = r[i] * gIn;
  1535. if (analog)
  1536. {
  1537. a = analogCurve (a, 0);
  1538. b = analogCurve (b, 1);
  1539. }
  1540. l[i] = (float) (a * std::cos (th)) * gOut;
  1541. r[i] = (float) (b * std::sin (th)) * gOut;
  1542. pout = std::max (pout, std::max (std::abs (l[i]), std::abs (r[i])));
  1543. pos = (float) pan;
  1544. }
  1545. lfo -= std::floor (lfo);
  1546. current = (float) (0.5 * (smooth + 1.0));
  1547. position.store (0.5f * (pos + 1.0f), std::memory_order_relaxed);
  1548. peakIn.store (pin, std::memory_order_relaxed);
  1549. peakOut.store (pout, std::memory_order_relaxed);
  1550. }
  1551. float analogCurve (float x, int c) noexcept
  1552. {
  1553. const auto u = std::clamp (x, -1.2f, 1.2f);
  1554. const auto y = u + 0.25f * u * u - 0.45f * u * u * u; // fitted on the trial's harmonics; DC removed after it
  1555. dcY[c] = y - dcX[c] + dcA * dcY[c];
  1556. dcX[c] = y;
  1557. return dcY[c];
  1558. }
  1559. double sampleRate = 44100.0, beats = 0.0, lfo = 0.0, smooth = 0.0, syncedBeats = -1.0;
  1560. float current = 0.5f, dcA = 0.999f, dcX[2] {}, dcY[2] {};
  1561. std::atomic<float> position { 0.5f }, peakIn { 0.0f }, peakOut { 0.0f };
  1562. rhythmpan::Engine rhythm; // round 136
  1563. rhythmpan::Settings rhythmSet;
  1564. };
  1565. // Vocoder = FL's Fruity Vocoder, exact engine (core/FruityVocoder.h, REA_rodada70; laws first read in REA_rodada20
  1566. // §4.1). Parameters (0..1): 0 bands (4 << round(5v)), 1 order (1 + round(2v)), 2 listen (0 modulator, 1 carrier,
  1567. // 2 mix), 3 swap L/R, then FL's twelve controls as (raw − min) / (max − min): 4/5 FreqMin/Max (0…65536), 6 FreqScale
  1568. // (0…128), 7 invert, 8 Formant (−1200…1200 cents), 9 band width (5…200 %), 10/11 attack/release (10…1000 ms),
  1569. // 12 hold, 13/14/15 modulator/carrier/wet levels (0…160); 16 LYNX's side-input mode. The per-band levels of the
  1570. // analysis bank travel in EffectSlot::state (FL's saved state); they apply while the band count matches.
  1571. namespace vocoder
  1572. {
  1573. int bands (float v) { return 4 << std::clamp ((int) std::lround (v * 5.0f), 0, 5); }
  1574. int order (float v) { return 1 + std::clamp ((int) std::lround (v * 2.0f), 0, 2); }
  1575. int raw (const EffectParams& p, int control)
  1576. {
  1577. const auto lo = fvocoder::controlMin (control), hi = fvocoder::controlMax (control);
  1578. return lo + (int) std::lround (std::clamp (p[(std::size_t) (4 + control)], 0.0f, 1.0f) * (float) (hi - lo));
  1579. }
  1580. int raw (float v, int control)
  1581. {
  1582. const auto lo = fvocoder::controlMin (control), hi = fvocoder::controlMax (control);
  1583. return lo + (int) std::lround (std::clamp (v, 0.0f, 1.0f) * (float) (hi - lo));
  1584. }
  1585. } // namespace vocoder
  1586. class Vocoder final : public Effect
  1587. {
  1588. public:
  1589. explicit Vocoder (const std::vector<std::uint8_t>& state)
  1590. {
  1591. if (auto s = fvocoder::parse (state))
  1592. saved = *s;
  1593. last.fill (-1.0f);
  1594. }
  1595. void prepare (double sr) noexcept override
  1596. {
  1597. engine.prepare (sr);
  1598. reset();
  1599. }
  1600. void reset() noexcept override { engine.reset(); }
  1601. void process (float* l, float* r, int n, const EffectParams& p, double) noexcept override
  1602. {
  1603. bool changed = false;
  1604. for (std::size_t i = 0; i < 16; ++i)
  1605. if (p[i] != last[i])
  1606. {
  1607. last[i] = p[i];
  1608. changed = true;
  1609. }
  1610. if (changed)
  1611. {
  1612. auto s = engine.state();
  1613. s.bands = vocoder::bands (p[0]);
  1614. s.order = vocoder::order (p[1]);
  1615. s.listen = std::clamp ((int) std::lround (p[2] * 2.0f), 0, 2);
  1616. s.swap = p[3] > 0.5f;
  1617. for (int c = 0; c < fvocoder::controls; ++c)
  1618. s.c[(std::size_t) c] = fvocoder::rawFromKnob (p[(std::size_t) (4 + c)], c, saved.c[(std::size_t) c]);
  1619. if (s.bands == saved.bands)
  1620. s.levels = saved.levels;
  1621. else
  1622. s.levels.fill (1.0f);
  1623. engine.setState (s);
  1624. }
  1625. // "Side inputs" (Vocodex-style): modulator = side input 1 or the own input, carrier = side input 2 or the own
  1626. // input, each in mono (L + R)/2; a configured side input that is silent gives silence
  1627. const auto separate = p[16] > 0.5f;
  1628. const bool modSide = useSide[0], carSide = useSide[1];
  1629. useSide = { false, false };
  1630. if (! separate)
  1631. {
  1632. engine.processStereo (l, r, n);
  1633. return;
  1634. }
  1635. for (int done = 0; done < n;)
  1636. {
  1637. const auto len = std::min (n - done, fvocoder::blockFrames);
  1638. for (int i = 0; i < len; ++i)
  1639. {
  1640. const auto k = (std::size_t) i, j = (std::size_t) (done + i);
  1641. const auto own = 0.5f * (l[j] + r[j]);
  1642. mod[k] = modSide ? (side[0][0] != nullptr ? 0.5f * (side[0][0][j] + side[0][1][j]) : 0.0f) : own;
  1643. car[k] = carSide ? (side[1][0] != nullptr ? 0.5f * (side[1][0][j] + side[1][1][j]) : 0.0f) : own;
  1644. }
  1645. engine.process (mod.data(), car.data(), l + done, len);
  1646. std::copy (l + done, l + done + len, r + done);
  1647. done += len;
  1648. }
  1649. }
  1650. void setSidechain (const float* left, const float* right) noexcept override
  1651. {
  1652. side[0] = { left, right };
  1653. useSide[0] = true;
  1654. }
  1655. void setSidechain2 (const float* left, const float* right) noexcept override
  1656. {
  1657. side[1] = { left, right };
  1658. useSide[1] = true;
  1659. }
  1660. private:
  1661. fvocoder::Engine engine;
  1662. fvocoder::State saved;
  1663. std::array<float, 16> last {};
  1664. std::array<std::array<const float*, 2>, 2> side {};
  1665. std::array<bool, 2> useSide { false, false };
  1666. std::array<float, fvocoder::blockFrames> mod {}, car {};
  1667. };
  1668. // Pitch correction (FL's Pitcher; laws in REA_rodada15 §1, rodada19 §6 and rodada30 §2). Parameters: 0 Correction
  1669. // Speed, 1 Fine Tune, 2 Bypass All, 3 Note A Freq, 4 range (index/5: min f 220/170/110/80/55/25 Hz), 5…16 note
  1670. // mask C…B (1 = allowed), 17…28 Key Bypass C…B, 29 Formant, 30 Gender, 31 Pitch Reference (0 left, 0.5
  1671. // independent, 1 right), 32 Stereo, 33 Harmonize, 34 MIDI, 35 Octaves, 36 Replace/Mix, 37 Vel, 38…41 Voice 1…4 pan.
  1672. // The DSP is FL's (core/PitcherDsp.h). MIDI mode and Harmonize take held notes, but LYNX effects receive no MIDI:
  1673. // no note is ever held, so MIDI mode corrects nothing (only Fine applies) and Harmonize passes the voice-0 dry
  1674. // signal (Replace) or the dry input alone (Mix) — what FL does with nothing arriving on the Pitcher's MIDI port.
  1675. namespace pcorr
  1676. {
  1677. constexpr double minHz[6] { 220.0, 170.0, 110.0, 80.0, 55.0, 25.0 };
  1678. int range (float v) { return std::clamp ((int) std::lround (v * 5.0f), 0, 5); }
  1679. double noteA (float v) { return 55.0 * std::pow (2.0, (2.0 * v - 1.0) / 12.0); } // ×8 = A 440 at v = 0.5
  1680. } // namespace pcorr
  1681. class PitchCorrect final : public Effect
  1682. {
  1683. public:
  1684. PitchCorrect() { dsp.reserve (maxSampleRate); }
  1685. void prepare (double sr) noexcept override { dsp.prepare (sr); }
  1686. void reset() noexcept override { dsp.reset(); }
  1687. void process (float* l, float* r, int n, const EffectParams& p, double) noexcept override
  1688. {
  1689. auto on = [&p] (int i) { return p[(std::size_t) i] > 0.5f; };
  1690. pitcher::Params q;
  1691. q.speed = std::clamp (p[0], 0.0f, 1.0f);
  1692. q.fine = p[1];
  1693. q.bypassAll = on (2);
  1694. q.aRef = p[3];
  1695. q.range = pcorr::range (p[4]);
  1696. for (int k = 0; k < 12; ++k)
  1697. {
  1698. q.scale[(std::size_t) k] = on (5 + k);
  1699. q.keyBypass[(std::size_t) k] = on (17 + k);
  1700. }
  1701. q.formant = on (29);
  1702. q.gender = p[30];
  1703. q.pitchRef = p[31];
  1704. q.stereo = p[32];
  1705. q.harmonize = on (33);
  1706. q.midi = on (34);
  1707. q.octaves = on (35);
  1708. q.mix = on (36);
  1709. q.vel = on (37);
  1710. for (int j = 0; j < 4; ++j)
  1711. q.voicePan[(std::size_t) j] = p[(std::size_t) (38 + j)];
  1712. dsp.process (l, r, n, q);
  1713. latency.store (dsp.latency(), std::memory_order_relaxed);
  1714. }
  1715. // The DSP's own delay: 9 samples on the plain path, 257 on the formant path (its pass-through delay; voiced
  1716. // PSOLA grains are placed about one period + 70 samples back). FL's reported PDC latency is not confirmed.
  1717. int latencySamples() const noexcept override { return latency.load (std::memory_order_relaxed); }
  1718. private:
  1719. pitcher::Pitcher dsp;
  1720. std::atomic<int> latency { 9 };
  1721. };
  1722. class LoFi final : public Effect
  1723. {
  1724. public:
  1725. void prepare (double) noexcept override { reset(); }
  1726. void reset() noexcept override
  1727. {
  1728. held[0] = held[1] = 0.0f;
  1729. countdown = 0;
  1730. }
  1731. void process (float* l, float* r, int n, const EffectParams& params, double) noexcept override
  1732. {
  1733. const auto hold = lofi::holdSamples (params[0]);
  1734. const auto step = (float) (2.0 / lofi::levels (params[1]));
  1735. const auto mix = params[2];
  1736. auto quantize = [step] (float x) { return step * std::floor (x / step + 0.5f); };
  1737. for (int i = 0; i < n; ++i)
  1738. {
  1739. if (--countdown <= 0)
  1740. {
  1741. countdown = hold;
  1742. held[0] = quantize (l[i]);
  1743. held[1] = quantize (r[i]);
  1744. }
  1745. l[i] += mix * (held[0] - l[i]);
  1746. r[i] += mix * (held[1] - r[i]);
  1747. }
  1748. }
  1749. private:
  1750. float held[2] {};
  1751. int countdown = 0;
  1752. };
  1753. class FreqShift final : public Effect
  1754. {
  1755. public:
  1756. void prepare (double sr) noexcept override
  1757. {
  1758. sampleRate = sr;
  1759. reset();
  1760. }
  1761. void reset() noexcept override
  1762. {
  1763. for (auto& c : chains)
  1764. c = {};
  1765. phase = 0.0;
  1766. }
  1767. void process (float* l, float* r, int n, const EffectParams& p, double) noexcept override
  1768. {
  1769. const auto shift = fshift::hz (p[0]);
  1770. const auto mix = std::clamp (p[1], 0.0f, 1.0f);
  1771. const auto spread = std::clamp (p[2], 0.0f, 1.0f);
  1772. const auto step = shift / sampleRate;
  1773. for (int i = 0; i < n; ++i)
  1774. {
  1775. const auto angle = 2.0 * 3.141592653589793 * phase;
  1776. const auto cosA = (float) std::cos (angle), sinA = (float) std::sin (angle);
  1777. float* io[2] = { l + i, r + i };
  1778. for (int c = 0; c < 2; ++c)
  1779. {
  1780. float re = 0.0f, im = 0.0f;
  1781. chains[(std::size_t) c].analytic (*io[c], re, im);
  1782. // right side: between the same direction (0) and the opposite (1)
  1783. const auto sign = c == 0 ? 1.0f : 1.0f - 2.0f * spread;
  1784. const auto shifted = re * cosA + sign * im * sinA;
  1785. *io[c] += (shifted - *io[c]) * mix;
  1786. }
  1787. phase += step;
  1788. phase -= std::floor (phase);
  1789. }
  1790. }
  1791. private:
  1792. // 4 2nd-order allpasses in z² per branch; the real branch has 1 extra sample of delay
  1793. struct Chain
  1794. {
  1795. static constexpr float a[4] = { 0.6923878f, 0.9360654322959f, 0.9882295226860f, 0.9987488452737f };
  1796. static constexpr float b[4] = { 0.4021921162426f, 0.8561710882420f, 0.9722909545651f, 0.9952884791278f };
  1797. std::array<float, 4> ax1 {}, ax2 {}, ay1 {}, ay2 {}, bx1 {}, bx2 {}, by1 {}, by2 {};
  1798. float delayed = 0.0f;
  1799. static float stage (float k, float x, float& x1, float& x2, float& y1, float& y2) noexcept
  1800. {
  1801. const auto y = k * k * (x + y2) - x2;
  1802. x2 = x1;
  1803. x1 = x;
  1804. y2 = y1;
  1805. y1 = y;
  1806. return y;
  1807. }
  1808. void analytic (float x, float& re, float& im) noexcept
  1809. {
  1810. auto u = x, v = x;
  1811. for (std::size_t k = 0; k < 4; ++k)
  1812. {
  1813. u = stage (a[k], u, ax1[k], ax2[k], ay1[k], ay2[k]);
  1814. v = stage (b[k], v, bx1[k], bx2[k], by1[k], by2[k]);
  1815. }
  1816. re = delayed;
  1817. im = v;
  1818. delayed = u;
  1819. }
  1820. };
  1821. std::array<Chain, 2> chains {};
  1822. double sampleRate = 44100.0, phase = 0.0;
  1823. };
  1824. // Parallel-branch container (FL's Patcher): each branch processes a copy of the input through its
  1825. // chain of built-in effects and the output is the gain-weighted sum of the branches.
  1826. class ParallelEffect final : public Effect
  1827. {
  1828. public:
  1829. static constexpr int capacity = 4096; // samples per chunk (larger blocks are split)
  1830. explicit ParallelEffect (const EffectSlot& slot)
  1831. {
  1832. for (const auto& b : slot.branches)
  1833. {
  1834. Branch branch;
  1835. branch.gain = b.gain;
  1836. for (const auto& child : b.chain)
  1837. if (child.kind != EffectKind::plugin) // nested containers too (Patcher series-parallel graphs)
  1838. branch.chain.push_back ({ makeEffect (child), child });
  1839. branches.push_back (std::move (branch));
  1840. }
  1841. for (const auto& link : slot.links)
  1842. if (link.branch >= 0 && link.branch < (int) branches.size() && link.curve.size() >= 2)
  1843. {
  1844. const auto& chain = branches[(std::size_t) link.branch].chain;
  1845. if (link.source >= 0 && link.source < (int) chain.size() && link.target >= 0 && link.target < (int) chain.size()
  1846. && link.param >= 0 && link.param < maxEffectParams)
  1847. links.push_back (link);
  1848. }
  1849. for (auto& buffer : scratch)
  1850. buffer.assign ((std::size_t) capacity, 0.0f);
  1851. }
  1852. void prepare (double sr) noexcept override
  1853. {
  1854. for (auto& b : branches)
  1855. for (auto& c : b.chain)
  1856. c.effect->prepare (sr);
  1857. }
  1858. void reset() noexcept override
  1859. {
  1860. for (auto& b : branches)
  1861. for (auto& c : b.chain)
  1862. c.effect->reset();
  1863. }
  1864. void setSongPosition (double ticks) noexcept override
  1865. {
  1866. for (auto& b : branches)
  1867. for (auto& c : b.chain)
  1868. c.effect->setSongPosition (ticks);
  1869. }
  1870. void setPlaying (bool playing) noexcept override
  1871. {
  1872. for (auto& b : branches)
  1873. for (auto& c : b.chain)
  1874. c.effect->setPlaying (playing);
  1875. }
  1876. void setHeldNotes (const NoteMask* channels, int count) noexcept override
  1877. {
  1878. for (auto& b : branches)
  1879. for (auto& c : b.chain)
  1880. c.effect->setHeldNotes (channels, count);
  1881. }
  1882. void process (float* l, float* r, int n, const EffectParams&, double bpm) noexcept override
  1883. {
  1884. for (int done = 0; done < n; done += capacity)
  1885. processPiece (l + done, r + done, std::min (capacity, n - done), bpm);
  1886. }
  1887. // the longest branch's latency (the branches themselves are not aligned; FL's Patcher PDC is not confirmed)
  1888. int latencySamples() const noexcept override
  1889. {
  1890. int longest = 0;
  1891. for (const auto& b : branches)
  1892. {
  1893. int sum = 0;
  1894. for (const auto& c : b.chain)
  1895. if (c.slot.enabled && c.slot.mix > 0.0f)
  1896. sum += c.effect->latencySamples();
  1897. longest = std::max (longest, sum);
  1898. }
  1899. return longest;
  1900. }
  1901. private:
  1902. struct Child
  1903. {
  1904. std::unique_ptr<Effect> effect;
  1905. EffectSlot slot;
  1906. };
  1907. struct Branch
  1908. {
  1909. std::vector<Child> chain;
  1910. float gain = 1.0f;
  1911. };
  1912. void processPiece (float* l, float* r, int n, double bpm) noexcept
  1913. {
  1914. auto* inL = scratch[0].data();
  1915. auto* inR = scratch[1].data();
  1916. auto* sumL = scratch[2].data();
  1917. auto* sumR = scratch[3].data();
  1918. auto* wL = scratch[4].data();
  1919. auto* wR = scratch[5].data();
  1920. auto* dryL = scratch[6].data();
  1921. auto* dryR = scratch[7].data();
  1922. std::copy (l, l + n, inL);
  1923. std::copy (r, r + n, inR);
  1924. std::fill (sumL, sumL + n, 0.0f);
  1925. std::fill (sumR, sumR + n, 0.0f);
  1926. // inner links: the control child's latest output sets the target's parameter (one block of lag)
  1927. for (const auto& link : links)
  1928. {
  1929. auto& chain = branches[(std::size_t) link.branch].chain;
  1930. const auto x = std::clamp (chain[(std::size_t) link.source].effect->controlOutput (0), 0.0f, 1.0f) * (float) (link.curve.size() - 1);
  1931. const auto i = std::min ((std::size_t) x, link.curve.size() - 2);
  1932. const auto f = x - (float) i;
  1933. chain[(std::size_t) link.target].slot.params[(std::size_t) link.param] = link.curve[i] + (link.curve[i + 1] - link.curve[i]) * f;
  1934. }
  1935. for (auto& b : branches)
  1936. {
  1937. std::copy (inL, inL + n, wL);
  1938. std::copy (inR, inR + n, wR);
  1939. for (auto& c : b.chain)
  1940. {
  1941. if (! c.slot.enabled || c.slot.mix <= 0.0f)
  1942. continue;
  1943. const auto partial = c.slot.mix < 0.999f;
  1944. if (partial)
  1945. {
  1946. std::copy (wL, wL + n, dryL);
  1947. std::copy (wR, wR + n, dryR);
  1948. }
  1949. c.effect->process (wL, wR, n, c.slot.params, bpm);
  1950. if (partial)
  1951. for (int i = 0; i < n; ++i)
  1952. {
  1953. wL[i] = dryL[i] + (wL[i] - dryL[i]) * c.slot.mix;
  1954. wR[i] = dryR[i] + (wR[i] - dryR[i]) * c.slot.mix;
  1955. }
  1956. }
  1957. for (int i = 0; i < n; ++i)
  1958. {
  1959. sumL[i] += wL[i] * b.gain;
  1960. sumR[i] += wR[i] * b.gain;
  1961. }
  1962. }
  1963. std::copy (sumL, sumL + n, l);
  1964. std::copy (sumR, sumR + n, r);
  1965. }
  1966. std::vector<Branch> branches;
  1967. std::vector<EffectLink> links;
  1968. std::array<std::vector<float>, 8> scratch;
  1969. };
  1970. // Peak Controller (REA_rodada17 §5): audio passes straight through. Detector with instant attack (block peak)
  1971. // and LINEAR decay in musical time: (10001^(D/128) − 1)·0.0192 per quarter note. Peak output =
  1972. // base + a·shape(p) with a = ±0.4·(6^(|A|/256) − 1) and FL's tension; output 0 = Peak + LFO, 1 = Peak,
  1973. // 2 = LFO (its LFO is not generated yet: the LFO base is used). Parameters = FL raw values, normalized.
  1974. class PeakController final : public Effect
  1975. {
  1976. public:
  1977. void prepare (double sr) noexcept override { sampleRate = sr; }
  1978. void reset() noexcept override { detector = 0.0; }
  1979. void process (float* l, float* r, int n, const EffectParams& p, double bpm) noexcept override
  1980. {
  1981. const auto amountRaw = (std::clamp ((double) p[1], 0.0, 1.0) * 2.0 - 1.0) * 256.0;
  1982. const auto tensionRaw = (std::clamp ((double) p[2], 0.0, 1.0) * 2.0 - 1.0) * 128.0;
  1983. const auto decayRaw = 5.0 + 123.0 * std::clamp ((double) p[3], 0.0, 1.0);
  1984. const auto perBeat = (std::pow (10001.0, decayRaw / 128.0) - 1.0) * 0.0192;
  1985. float blockPeak = 0.0f;
  1986. for (int i = 0; i < n; ++i)
  1987. blockPeak = std::max ({ blockPeak, std::abs (l[i]), std::abs (r[i]) });
  1988. detector = std::max (0.0, detector - perBeat * std::max (1.0, bpm) / 60.0 * n / sampleRate);
  1989. detector = std::max (detector, (double) blockPeak);
  1990. const auto amount = (amountRaw < 0.0 ? -1.0 : 1.0) * (std::pow (6.0, std::abs (amountRaw) / 256.0) - 1.0) * 0.4;
  1991. double shaped = detector;
  1992. if (std::abs (tensionRaw) > 1e-9)
  1993. {
  1994. const auto k = (std::pow (1001.0, std::abs (tensionRaw) / 128.0) - 1.0) * 0.1;
  1995. const auto y = tensionRaw > 0.0 ? k - (std::pow (k + 1.0, 1.0 - detector) - 1.0) : std::pow (k + 1.0, detector) - 1.0;
  1996. shaped = y / k;
  1997. }
  1998. peakOut = (float) std::clamp (p[0] + amount * shaped, 0.0, 1.0);
  1999. lfoOut = std::clamp (p[4], 0.0f, 1.0f);
  2000. }
  2001. float controlOutput (int output) const noexcept override
  2002. {
  2003. return output == 1 ? peakOut : output == 2 ? lfoOut : std::clamp (peakOut + lfoOut, 0.0f, 1.0f);
  2004. }
  2005. private:
  2006. double sampleRate = 44100.0, detector = 0.0;
  2007. float peakOut = 0.0f, lfoOut = 0.0f;
  2008. };
  2009. class Utility final : public Effect
  2010. {
  2011. public:
  2012. void prepare (double) noexcept override {}
  2013. void reset() noexcept override {}
  2014. void process (float* l, float* r, int n, const EffectParams& p, double) noexcept override
  2015. {
  2016. if (p[0] != lastGainParam) // pow only when the parameter changes (Patchers have dozens of utilities)
  2017. {
  2018. lastGainParam = p[0];
  2019. cachedGain = p[0] <= 0.0f ? 0.0f : std::pow (10.0f, utilityGainDb (p[0]) / 20.0f); // at the bottom = mute
  2020. }
  2021. const auto gain = cachedGain;
  2022. const auto pan = std::clamp (p[1] * 2.0f - 1.0f, -1.0f, 1.0f);
  2023. const auto gl = gain * (pan > 0.0f ? 1.0f - pan : 1.0f); // balance: lowers the opposite side
  2024. const auto gr = gain * (pan < 0.0f ? 1.0f + pan : 1.0f);
  2025. const auto ll = utilityMatrix (p[2]), rl = utilityMatrix (p[3]), lr = utilityMatrix (p[4]), rr = utilityMatrix (p[5]);
  2026. // shortcuts: identity (common in Patchers' PanOMatic/Stereo Shaper) and mute
  2027. if (gl == 0.0f && gr == 0.0f)
  2028. {
  2029. std::fill (l, l + n, 0.0f);
  2030. std::fill (r, r + n, 0.0f);
  2031. return;
  2032. }
  2033. if (rl == 0.0f && lr == 0.0f)
  2034. {
  2035. const auto fl = ll * gl, fr = rr * gr;
  2036. if (fl == 1.0f && fr == 1.0f)
  2037. return;
  2038. for (int i = 0; i < n; ++i)
  2039. {
  2040. l[i] *= fl;
  2041. r[i] *= fr;
  2042. }
  2043. return;
  2044. }
  2045. for (int i = 0; i < n; ++i)
  2046. {
  2047. const auto a = l[i], b = r[i];
  2048. l[i] = (ll * a + rl * b) * gl;
  2049. r[i] = (lr * a + rr * b) * gr;
  2050. }
  2051. }
  2052. private:
  2053. float lastGainParam = -1.0f, cachedGain = 1.0f;
  2054. };
  2055. } // namespace
  2056. namespace peq
  2057. {
  2058. BandType type (float v) noexcept { return (BandType) std::clamp ((int) std::lround (v * (bandTypes - 1)), 0, bandTypes - 1); }
  2059. float typeValue (BandType t) noexcept { return (float) (int) t / (float) (bandTypes - 1); }
  2060. double hz (float v) noexcept { return 20.0 * std::pow (1000.0, std::clamp ((double) v, 0.0, 1.0)); }
  2061. float hzValue (double f) noexcept { return (float) std::clamp (std::log (std::max (f, 1.0) / 20.0) / std::log (1000.0), 0.0, 1.0); }
  2062. double gainDb (float v) noexcept { return (std::clamp ((double) v, 0.0, 1.0) - 0.5) * 36.0; }
  2063. float gainValue (double db) noexcept { return (float) std::clamp (db / 36.0 + 0.5, 0.0, 1.0); }
  2064. double q (float v) noexcept { return 0.1 * std::pow (180.0, std::clamp ((double) v, 0.0, 1.0)); }
  2065. float qValue (double value) noexcept { return (float) std::clamp (std::log (std::max (value, 0.01) / 0.1) / std::log (180.0), 0.0, 1.0); }
  2066. int slopeStages (float v) noexcept { return 1 + (int) std::lround (std::clamp (v, 0.0f, 1.0f) * 3.0f); }
  2067. float slopeValue (int stages) noexcept { return (float) (std::clamp (stages, 1, 4) - 1) / 3.0f; }
  2068. const char* typeName (BandType t) noexcept
  2069. {
  2070. static constexpr const char* names[] = { "Off", "Peak", "Low shelf", "High shelf", "Low cut",
  2071. "High cut", "Band-pass", "Notch" };
  2072. return names[(int) t];
  2073. }
  2074. double responseDb (const EffectParams& params, double sr, double f)
  2075. {
  2076. if (flLaw (params))
  2077. return peqfl::responseDb (peqfl::fromParams (params), sr, f);
  2078. // |H(e^jw)| of each stage, summed in dB
  2079. const auto w = 2.0 * pi * std::clamp (f, 1.0, sr * 0.499) / sr;
  2080. const std::complex<double> z1 = std::polar (1.0, -w), z2 = std::polar (1.0, -2.0 * w);
  2081. auto total = gainDb (params[outputParam]);
  2082. for (int b = 0; b < bands; ++b)
  2083. {
  2084. std::array<Biquad, 4> st;
  2085. const auto count = bandStages (params, b, sr, st);
  2086. for (int s = 0; s < count; ++s)
  2087. {
  2088. const auto& c = st[(std::size_t) s];
  2089. const auto h = (c.b0 + c.b1 * z1 + c.b2 * z2) / (1.0 + c.a1 * z1 + c.a2 * z2);
  2090. const auto magnitude = std::abs (h);
  2091. if (std::isfinite (magnitude)) // (the editor draws this: never NaN)
  2092. total += 20.0 * std::log10 (std::max (magnitude, 1.0e-9));
  2093. }
  2094. }
  2095. return total;
  2096. }
  2097. bool flLaw (const EffectParams& params) noexcept { return peqfl::lawOf (params) != peqfl::Law::lynx; }
  2098. std::string orderText (const EffectParams& params, int band)
  2099. {
  2100. const auto v = params[(std::size_t) (slopeParam + band)];
  2101. if (! flLaw (params))
  2102. return std::to_string (12 * slopeStages (v)) + " dB/oct";
  2103. if (peqfl::lawOf (params) == peqfl::Law::peq1)
  2104. return "12 dB/oct";
  2105. // FL's order texts, −3…+3 (REA_rodada7 §1.4)
  2106. static constexpr const char* names[7] = { "Steep 8", "Steep 6", "Steep 4", "2", "Gentle 4", "Gentle 6", "Gentle 8" };
  2107. return names[std::clamp ((int) std::lround (v * 6.0f), 0, 6)];
  2108. }
  2109. std::string widthText (const EffectParams& params, int band)
  2110. {
  2111. const auto v = params[(std::size_t) param (band, 3)];
  2112. char text[32];
  2113. if (flLaw (params))
  2114. std::snprintf (text, sizeof (text), "BW %.0f%%", (double) v * 100.0);
  2115. else
  2116. std::snprintf (text, sizeof (text), "Q %.2f", q (v));
  2117. return text;
  2118. }
  2119. } // namespace peq
  2120. namespace autopan
  2121. {
  2122. Source sourceOf (float v) noexcept { return (Source) std::clamp ((int) std::lround (std::clamp (v, 0.0f, 1.0f) * 2.0f), 0, 2); }
  2123. Direction directionOf (float v) noexcept { return (Direction) std::clamp ((int) std::lround (std::clamp (v, 0.0f, 1.0f) * 2.0f), 0, 2); }
  2124. double rateHz (float v) noexcept { return 0.01 * std::pow (1000.0, (double) std::clamp (v, 0.0f, 1.0f)); }
  2125. float rateValue (double hz) noexcept { return (float) std::clamp (std::log (std::max (hz, 1e-6) / 0.01) / std::log (1000.0), 0.0, 1.0); }
  2126. int stepCount (float v) noexcept { return 2 + std::clamp ((int) std::lround (std::clamp (v, 0.0f, 1.0f) * 6.0f), 0, 6); }
  2127. double stepBeats (float v) noexcept { return 4.0 / (double) (1 << std::clamp ((int) std::lround (std::clamp (v, 0.0f, 1.0f) * 5.0f), 0, 5)); }
  2128. double inputDb (float v) noexcept { return -24.0 + 48.0 * (double) std::clamp (v, 0.0f, 1.0f); }
  2129. std::string paramText (int param, float v)
  2130. {
  2131. char t[32];
  2132. switch (param)
  2133. {
  2134. case source: { static const char* const n[3] { "FL LFO", "LFO", "Rhythm steps" }; return n[(int) sourceOf (v)]; }
  2135. case rate:
  2136. {
  2137. const auto hz = rateHz (v);
  2138. if (hz < 1.0) std::snprintf (t, sizeof t, "%.1f s", 1.0 / hz);
  2139. else std::snprintf (t, sizeof t, "%.2f Hz", hz);
  2140. return t;
  2141. }
  2142. case direction: { static const char* const n[3] { "Back and forth", "Left to right", "Right to left" }; return n[(int) directionOf (v)]; }
  2143. case smoothing: std::snprintf (t, sizeof t, "%.0f%%", 100.0 * std::clamp (v, 0.0f, 1.0f)); return t;
  2144. case stepsParam: return std::to_string (stepCount (v));
  2145. case stepNote: { static const char* const n[6] { "1/1", "1/2", "1/4", "1/8", "1/16", "1/32" }; return n[std::clamp ((int) std::lround (std::clamp (v, 0.0f, 1.0f) * 5.0f), 0, 5)]; }
  2146. case inputGain:
  2147. case outputGain: std::snprintf (t, sizeof t, "%+.1f dB", inputDb (v)); return t;
  2148. case analogStage: return v >= 0.5f ? "Analog" : "Digital";
  2149. default: std::snprintf (t, sizeof t, "%.2f", (double) v); return t;
  2150. }
  2151. }
  2152. } // namespace autopan
  2153. const EffectInfo& effectInfo (EffectKind kind)
  2154. {
  2155. static const EffectInfo eq { "EQ", { { "Low", 0.5f }, { "Mid", 0.5f }, { "Mid freq.", 0.5f }, { "High", 0.5f }, { "Output", 0.5f } } };
  2156. static const EffectInfo comp { "Compressor", { { "Threshold", 0.7f }, { "Ratio", 3.0f / 19.0f }, { "Attack", 0.67f }, { "Release", 0.54f }, { "Makeup", 0.0f }, { "Auto gain", 0.0f },
  2157. { "Mix", 1.0f }, { "Trim", 0.5f }, { "Voicing", 0.0f },
  2158. // round 135w: the RComp role's switches (the vintage voicing's ARC / Electro / Warm
  2159. // by default, as fitted) and its 0 dBFS output limiter (off: older projects unchanged)
  2160. { "Release mode", 0.0f }, { "Release curve", 0.0f }, { "Character", 0.0f }, { "Limiter", 0.0f } } };
  2161. static const EffectInfo delay { "Delay", { { "Time", 0.3f }, { "Feedback", 0.42f }, { "Mix", 0.3f }, { "Ping-pong", 0.0f }, { "Damping", 0.3f } } };
  2162. static const EffectInfo reverb { "Reverb", { { "Room", 0.6f }, { "Damping", 0.5f }, { "Width", 1.0f }, { "Mix", 0.25f }, { "Dry", 1.0f },
  2163. { "Low cut", 0.0f }, { "High cut", 1.0f }, { "Predelay", 0.0f } } };
  2164. static const EffectInfo plugin { "Plugin", {} };
  2165. static const EffectInfo limiter { "Limiter", { { "Ceiling", 0.975f }, { "Gain", 0.0f }, { "Release", 0.5f } } };
  2166. static const EffectInfo filter { "Filter", { { "Type", 0.0f }, { "Cutoff", 0.75f }, { "Reso.", 0.2f }, { "Mix", 1.0f } } };
  2167. static const EffectInfo distortion { "Distortion", { { "Drive", 0.4f }, { "Tone", 0.7f }, { "Mix", 1.0f }, { "Output", 0.5f } } };
  2168. static const EffectInfo chorus { "Chorus", { { "Rate", 0.45f }, { "Depth", 0.4f }, { "Mix", 0.5f }, { "Feedback", 0.0f } } };
  2169. static const EffectInfo utility { "Utility", { { "Gain", 0.5f }, { "Balance", 0.5f }, { "L -> L", 0.75f }, { "R -> L", 0.5f },
  2170. { "L -> R", 0.5f }, { "R -> R", 0.75f } } };
  2171. static const EffectInfo volumeGate = [] {
  2172. static const char* names[] = { "Step 1", "Step 2", "Step 3", "Step 4", "Step 5", "Step 6", "Step 7", "Step 8",
  2173. "Step 9", "Step 10", "Step 11", "Step 12", "Step 13", "Step 14", "Step 15", "Step 16",
  2174. "Step 17", "Step 18", "Step 19", "Step 20", "Step 21", "Step 22", "Step 23", "Step 24",
  2175. "Step 25", "Step 26", "Step 27", "Step 28", "Step 29", "Step 30", "Step 31", "Step 32" };
  2176. EffectInfo info { "Volume gate", {} };
  2177. for (int i = 0; i < gate::steps; ++i)
  2178. info.params.push_back ({ names[i], (i % 8) < 4 ? 1.0f : 0.0f }); // default: half a beat on, half off
  2179. info.params.push_back ({ "Mix", 1.0f });
  2180. info.params.push_back ({ "Attack", 0.1765f }); // ~2 ms
  2181. info.params.push_back ({ "Release", 0.5f }); // ~43 ms
  2182. return info;
  2183. }();
  2184. static const EffectInfo pitchShift { "Pitch shift", { { "Semitones", 0.5f }, { "Cents", 0.5f }, { "Mix", 1.0f }, { "Window", 0.4f } } };
  2185. static const EffectInfo freqShift { "Frequency shifter", { { "Shift", 0.5f }, { "Mix", 1.0f }, { "Stereo", 0.0f } } };
  2186. static const EffectInfo parallelInfo { "Patcher (parallel)", {} };
  2187. static const EffectInfo patcherInfo { "Patcher", {} };
  2188. static const EffectInfo crossoverInfo { "Crossover", { { "High-pass", 0.0f }, { "HP cutoff", 0.3f }, { "HP slope", 3.0f / 7.0f },
  2189. { "Low-pass", 0.0f }, { "LP cutoff", 0.7f }, { "LP slope", 3.0f / 7.0f } } };
  2190. static const EffectInfo rhythmInfo = [] {
  2191. EffectInfo info { "Rhythmic envelope", { { "Period", 1.0f / 64.0f }, { "Points", 0.0f } } };
  2192. static const char* names[] = { "P1 pos", "P1 level", "P1 tension", "P2 pos", "P2 level", "P2 tension", "P3 pos", "P3 level", "P3 tension",
  2193. "P4 pos", "P4 level", "P4 tension", "P5 pos", "P5 level", "P5 tension", "P6 pos", "P6 level", "P6 tension",
  2194. "P7 pos", "P7 level", "P7 tension", "P8 pos", "P8 level", "P8 tension", "P9 pos", "P9 level", "P9 tension",
  2195. "P10 pos", "P10 level", "P10 tension", "P11 pos", "P11 level", "P11 tension", "P12 pos", "P12 level", "P12 tension" };
  2196. for (int i = 0; i < 36; ++i)
  2197. info.params.push_back ({ names[i], i % 3 == 2 ? 0.5f : 1.0f });
  2198. info.params.push_back ({ "Control only", 0.0f });
  2199. return info;
  2200. }();
  2201. static const EffectInfo autoPanInfo { "Auto-pan", { { "Period", 1.0f / 64.0f }, { "Depth", 0.75f }, { "Phase", 0.0f }, { "Pan", 0.5f }, { "Control only", 0.0f },
  2202. { "FL pan law", 0.0f }, { "Tension", 0.5f },
  2203. // round 135 (the PanMan role; the FL source stays the default)
  2204. { "Source", 0.0f }, { "Rate", 0.46598f }, { "Direction", 0.0f }, { "Smoothing", 1.0f },
  2205. { "Steps", 1.0f / 6.0f }, { "Step note", 0.4f }, { "Input", 0.5f }, { "Output", 0.5f },
  2206. { "Analog", 0.0f },
  2207. // round 136: the Rhythm voicing (core/RhythmPan.h, measured), off = the engines above
  2208. { "Voicing", 0.0f }, { "Rhythm rate", 0.4659f /* 0.25 Hz */ }, { "Sync", 0.0f },
  2209. { "Beats", 0.4f /* 1 beat */ }, { "Width", 180.0f / 210.0f }, { "Offset", 0.5f },
  2210. { "Rhythm smoothing", 1.0f }, { "Pattern", 0.0f }, { "Amount", 1.0f }, { "Start phase", 0.0f },
  2211. { "Rhythm analog", 0.5f }, { "Rhythm output", 0.5f } } };
  2212. static const EffectInfo vocoderInfo { "Vocoder", { { "Bands", 0.4f }, { "Order", 0.5f }, { "Listen", 1.0f }, { "Swap L/R", 0.0f },
  2213. { "Min freq.", 0.0f }, { "Max freq.", 1.0f }, { "Scale", 0.5f }, { "Invert", 0.0f },
  2214. { "Formant", 0.5f }, { "Width", 45.0f / 195.0f }, { "Attack", 10.0f / 990.0f },
  2215. { "Release", 90.0f / 990.0f }, { "Hold", 0.0f }, { "Modulator", 0.0f },
  2216. { "Carrier", 0.0f }, { "Wet", 0.8f }, { "Side inputs", 0.0f } } };
  2217. static const EffectInfo vocodexInfo { "Vocodex", {} }; // everything comes from FL's raw state (EffectSlot::state)
  2218. static const EffectInfo maximusInfo { "Maximus", {} }; // the engine's state travels in EffectSlot::state (core/MaximusFx.h)
  2219. // Distructor: each module's input volume, mix and output volume (FL's 0…10000 / 10000), the final clipper; the
  2220. // modules themselves come from FL's state (core/DistructorFx.h)
  2221. static const EffectInfo distructorInfo { "Distructor", { { "M1 In", 0.5f }, { "M1 Mix", 1.0f }, { "M1 Out", 0.5f },
  2222. { "M2 In", 0.5f }, { "M2 Mix", 1.0f }, { "M2 Out", 0.5f },
  2223. { "M3 In", 0.5f }, { "M3 Mix", 1.0f }, { "M3 Out", 0.5f },
  2224. { "M4 In", 0.5f }, { "M4 Mix", 1.0f }, { "M4 Out", 0.5f },
  2225. { "Clipper", 1.0f } } };
  2226. // Multiband Delay: FL's twelve global controls (raw − min) / range; the banks come from FL's state (core/MultibandDelayFx.h)
  2227. static const EffectInfo multibandDelayInfo = [] {
  2228. EffectParams p {};
  2229. mbdelay::toParams (mbdelay::State {}, p);
  2230. EffectInfo info { "Multiband Delay", {} };
  2231. const char* const names[mbdelay::numGlobals] = { "Delay scale", "Delay x0.1", "Feedback", "Smoothing", "Filter mode", "Keep pitch",
  2232. "Morph", "Mix", "Harmonic scale", "Weighting", "High pass", "Saturation" };
  2233. for (int i = 0; i < mbdelay::numGlobals; ++i)
  2234. info.params.push_back ({ names[i], p[(std::size_t) i] });
  2235. return info;
  2236. }();
  2237. // EQUO: FL's knobs (raw − min) / range and options; the bands come from FL's state (core/EquoFx.h)
  2238. static const EffectInfo equoInfo { "EQUO", { { "Band shift", 0.5f }, { "Band mix", 1.0f }, { "Morph", 0.0f },
  2239. { "Smoothness", 170.0f / 1024.0f }, { "Volume", 0.5f },
  2240. { "Bandwidth", 70.0f / 420.0f }, { "Oversample", 0.0f }, { "Add mode", 0.0f },
  2241. { "Send only", 0.0f } } };
  2242. // FL's Pitch Shifter: its 13 knobs (raw − min) / range, then engine, detector, tempo sync; defaults = a new FL instance
  2243. static const EffectInfo flPitchShifterInfo = [] {
  2244. EffectParams p {};
  2245. psfl::toParams (psfl::State {}, p);
  2246. EffectInfo info { "Pitch Shifter", {} };
  2247. const char* const names[psfl::numParams] = { "Pitch", "Formant", "Channel", "Mix", "Duration", "Density", "Jitter",
  2248. "Random", "Delay", "Feedback", "Delay mode", "Formant correction",
  2249. "Pitch mode", "Granular", "Accurate detector", "Tempo sync" };
  2250. for (int i = 0; i < psfl::numParams; ++i)
  2251. info.params.push_back ({ names[i], p[(std::size_t) i] });
  2252. return info;
  2253. }();
  2254. // FL's raw controls normalised over their ranges (core/FruityDynamics.h); defaults = a new FL instance
  2255. static const EffectInfo fruityLimiterInfo = [] {
  2256. EffectInfo info { "Fruity Limiter", {} };
  2257. for (int i = 0; i < fldyn::limiterControls; ++i)
  2258. info.params.push_back ({ fldyn::limiterParamName (i), fldyn::normalised (fldyn::limiterDefault[(std::size_t) i], fldyn::limiterMin[(std::size_t) i], fldyn::limiterMax[(std::size_t) i]) });
  2259. info.params.push_back ({ fldyn::limiterParamName (fldyn::limiterControls), 0.0f });
  2260. return info;
  2261. }();
  2262. static const EffectInfo fruityCompressorInfo = [] {
  2263. EffectInfo info { "Fruity Compressor", {} };
  2264. for (int i = 0; i < fldyn::compressorControls; ++i)
  2265. info.params.push_back ({ fldyn::compressorParamName (i), fldyn::normalised (fldyn::compressorDefault[(std::size_t) i], fldyn::compressorMin[(std::size_t) i], fldyn::compressorMax[(std::size_t) i]) });
  2266. info.params.push_back ({ fldyn::compressorParamName (fldyn::compressorControls), 1.0f });
  2267. return info;
  2268. }();
  2269. // FL's controls over their ranges (core/FruityShapers.h); defaults = a new FL instance; the curve is in EffectSlot::state
  2270. static const EffectInfo waveShaperInfo { "Fruity WaveShaper", { { "Pre amp", 0.5f }, { "Mix", 1.0f }, { "Post gain", 1.0f },
  2271. { "Oversampling", 0.0f }, { "HQ", 0.0f }, { "Smooth", 0.0f },
  2272. { "Center", 0.0f }, { "Unipolar", 0.0f } } };
  2273. static const EffectInfo softClipperInfo { "Fruity Soft Clipper", { { "Threshold", 99.0f / 126.0f }, { "Post", 128.0f / 160.0f } } };
  2274. // FL's controls over their ranges (core/FruityBasicFx.h); defaults = a new FL instance
  2275. static const EffectInfo panOMaticInfo { "Fruity PanOMatic", { { "Pan", 0.5f }, { "Volume", 0.8f }, { "LFO shape", 0.0f },
  2276. { "LFO target", 0.0f }, { "LFO amount", 0.5f }, { "LFO speed", 0.5f } } };
  2277. static const EffectInfo balanceInfo { "Fruity Balance", { { "Balance", 0.5f }, { "Volume", 0.8f } } };
  2278. static const EffectInfo bloodOverdriveInfo { "Fruity Blood Overdrive", { { "Pre band", 0.0f }, { "Color", 0.5f }, { "Pre amp", 0.0f },
  2279. { "x100", 0.0f }, { "Post filter", 0.0f }, { "Post gain", 1.0f } } };
  2280. // FL's controls as (raw − min) / range (core/Reeverb2.h); defaults = FL's
  2281. static const EffectInfo reeverb2Info = [] {
  2282. EffectInfo info { "Reeverb 2", { { "Low cut", 0 }, { "High cut", 0 }, { "Predelay", 0 }, { "Room size", 0 }, { "Diffusion", 0 },
  2283. { "Decay", 0 }, { "High damping", 0 }, { "Bass mult.", 0 }, { "Crossover", 0 }, { "Stereo sep.", 0 },
  2284. { "Dry", 0 }, { "Early ref.", 0 }, { "Wet", 0 }, { "Mod speed", 0 }, { "Mod depth", 0 },
  2285. { "Tempo predelay", 0 }, { "Mid/side input", 0 } } };
  2286. EffectParams p {};
  2287. reeverb2::toParams (reeverb2::Settings {}, p);
  2288. for (std::size_t i = 0; i < info.params.size(); ++i)
  2289. info.params[i].defaultValue = p[i];
  2290. return info;
  2291. }();
  2292. // FL's 49 controls as (raw − min) / range + the 4 sync switches (core/LuxeVerb.h); defaults = a new FL instance
  2293. static const EffectInfo luxeVerbInfo = [] {
  2294. EffectInfo info { "LuxeVerb", {} };
  2295. EffectParams p {};
  2296. luxeverb::toParams (luxeverb::Settings {}, p);
  2297. for (std::size_t i = 0; i < (std::size_t) luxeVerbParamCount; ++i)
  2298. info.params.push_back ({ luxeverb::names[i], p[i] });
  2299. return info;
  2300. }();
  2301. // FL's 4 automatable controls as (raw − min) / range (core/ConvolverFx.h); the impulse response is in the slot's state
  2302. static const EffectInfo convolverInfo { "Fruity Convolver", { { "Dry", 1.0f }, { "Wet", 1.0f }, { "Input separation", 0.5f },
  2303. { "Wet separation", 0.5f } } };
  2304. // FL's controls as raw / max (core/Reeverb2.h); defaults = the plugin's own (1250, 10800, 0, 26000, 65536, 20, 4700,
  2305. // 10800, 65536, 13120)
  2306. static const EffectInfo reeverb1Info { "Reeverb", { { "Low cut", 1250.0f / 65536 }, { "High cut", 10800.0f / 65536 }, { "Predelay", 0.0f },
  2307. { "Room size", 26000.0f / 65536 }, { "Diffusion", 1.0f }, { "Color", 0.5f },
  2308. { "Decay", 4700.0f / 65536 }, { "High damping", 10800.0f / 65536 }, { "Dry", 1.0f },
  2309. { "Wet", 13120.0f / 65536 } } };
  2310. // FL's raw controls normalised over their ranges (core/FruityDelay.h); defaults = FL's "Default" presets
  2311. static const EffectInfo fruityDelay2Info = [] {
  2312. EffectInfo info { "Fruity Delay 2", {} };
  2313. for (int i = 0; i < fldelay::delay2Controls; ++i)
  2314. info.params.push_back ({ fldelay::delay2ParamName (i), (float) (fldelay::delay2Default[(std::size_t) i] - fldelay::delay2Min[(std::size_t) i])
  2315. / (float) (fldelay::delay2Max[(std::size_t) i] - fldelay::delay2Min[(std::size_t) i]) });
  2316. return info;
  2317. }();
  2318. static const EffectInfo fruityDelay3Info = [] {
  2319. EffectInfo info { "Fruity Delay 3", {} };
  2320. for (int i = 0; i < fldelay::delay3Controls; ++i)
  2321. info.params.push_back ({ fldelay::delay3ParamName (i), (float) (fldelay::delay3Default[(std::size_t) i] - fldelay::delay3Min[(std::size_t) i])
  2322. / (float) (fldelay::delay3Max[(std::size_t) i] - fldelay::delay3Min[(std::size_t) i]) });
  2323. return info;
  2324. }();
  2325. // FL's controls over their ranges (core/StereoFx.h); defaults = a new FL instance
  2326. static const EffectInfo stereoShaperInfo { "Stereo Shaper", { { "R > L", 0.5f }, { "Left", 0.75f }, { "Right", 0.75f }, { "L > R", 0.5f },
  2327. { "Delay", 0.5f }, { "Phase", 0.5f }, { "Effects post", 0.0f },
  2328. { "Difference", 0.0f } } };
  2329. static const EffectInfo stereoEnhancerInfo { "Stereo Enhancer", { { "Pan", 0.5f }, { "Volume", 0.8f }, { "Separation", 0.5f },
  2330. { "Phase offset", 0.5f }, { "Effects post", 1.0f }, { "Invert", 0.0f } } };
  2331. static const EffectInfo transientProcessorInfo { "Transient Processor", { { "Attack", 0.5f }, { "Drive", 0.0f }, { "Release", 0.5f },
  2332. { "Gain", 0.5f }, { "Attack shape", 0.5f }, { "Release shape", 0.5f },
  2333. { "Split freq.", 0.5f }, { "Split balance", 0.5f }, { "On", 1.0f } } };
  2334. static const EffectInfo spreaderInfo { "Spreader", { { "Width", 0.5f }, { "Separation", 0.5f }, { "Low bypass", 9990.0f / 999000.0f },
  2335. { "Mono bass", 0.0f }, { "Enable", 1.0f } } };
  2336. // FL's controls over their ranges (core/FruityFilters.h); defaults = a new FL instance
  2337. static const EffectInfo fastLPInfo { "Fruity Fast LP", { { "Cutoff", 1.0f }, { "Resonance", 0.0f } } };
  2338. static const EffectInfo freeFilterInfo { "Fruity Free Filter", { { "Type", 0.0f }, { "Frequency", 0.5f }, { "Q", 169.0f / 1024.0f },
  2339. { "Gain", 676.0f / 1024.0f }, { "Center", 0.0f } } };
  2340. // FL's Newtone / Newtime: the sample and its edits travel in EffectSlot::state / samplePath (core/NewtoneFx.h)
  2341. static const EffectInfo newtoneInfo { "Newtone", { { "Slave to host playback", 0.0f } } };
  2342. static const EffectInfo newtimeInfo { "Newtime", { { "Slave to host playback", 0.0f } } };
  2343. static const EffectInfo fruityFilterInfo { "Fruity Filter", { { "Cutoff", 1.0f }, { "Resonance", 205.0f / 1024.0f }, { "Low pass", 1.0f },
  2344. { "Band pass", 0.0f }, { "High pass", 0.5f }, { "x2", 0.0f }, { "Center", 0.0f } } };
  2345. // FL's eight Gross Beat parameters (core/GrossBeat.h); the slots' envelopes travel in EffectSlot::state
  2346. static const EffectInfo grossBeatInfo { "Gross Beat", { { "Time slot", 0.0f }, { "Volume slot", 0.0f }, { "Time mix", 1.0f },
  2347. { "Volume mix", 1.0f }, { "Attack", 0.1765f }, { "Release", 0.5f },
  2348. { "Tension", 0.5f }, { "Hold", 0.0f } } };
  2349. // FL's state travels in EffectSlot::state; the four global controls are the editable parameters (raw / 128)
  2350. static const EffectInfo fruityDelayBankInfo { "Fruity Delay Bank", { { "Dry", 1.0f }, { "Output", 1.0f }, { "Input", 1.0f }, { "Feedback", 1.0f } } };
  2351. // FL's raw controls normalised over their ranges (core/FruityMultiband.h); defaults = a new FL instance
  2352. static const EffectInfo fruityMultibandInfo = [] {
  2353. EffectInfo info { "Fruity Multiband Compressor", {} };
  2354. for (int i = 0; i < flmb::controls; ++i)
  2355. info.params.push_back ({ flmb::paramName (i), flmb::normalised (flmb::controlDefault[(std::size_t) i], flmb::controlMin[(std::size_t) i], flmb::controlMax[(std::size_t) i]) });
  2356. return info;
  2357. }();
  2358. // FL's controls over their ranges (core/FlangusFastDist.h); defaults = a new FL instance
  2359. static const EffectInfo fastDistInfo { "Fruity Fast Dist", { { "Pre amp", 0.5f }, { "Threshold", 1.0f }, { "Type", 0.0f },
  2360. { "Mix", 1.0f }, { "Post gain", 1.0f } } };
  2361. static const EffectInfo flangusInfo { "Fruity Flangus", { { "Order", 3.0f / 8.0f }, { "Depth", 0.5f }, { "Speed", 0.75f },
  2362. { "Delay", 8.0f / 128.0f }, { "Spread", 1.0f }, { "Cross", 96.0f / 256.0f },
  2363. { "Dry", 224.0f / 256.0f }, { "Wet", 224.0f / 256.0f } } };
  2364. static const EffectInfo flangerInfo { "Fruity Flanger", { { "Delay", 0.0f }, { "Depth", 0.4f }, { "Rate", 0.4f }, { "Phase", 118.0f / 360.0f },
  2365. { "Damp", 0.0f }, { "Shape", 0.0f }, { "Feed", 0.23f }, { "Invert feed", 0.0f },
  2366. { "Invert wet", 1.0f }, { "Dry", 0.7f }, { "Wet", 0.6f }, { "Cross", 0.5f } } };
  2367. // raw FL values / max (the names are FL's controls, REA_rodada29 §2.1)
  2368. static const EffectInfo squeezeInfo { "Squeeze", { { "Volume", 127.0f / 160.0f }, { "Mix", 0.5f }, { "Steps", 1.0f / 32768.0f },
  2369. { "Filter", 0.0f }, { "Filter type", 0.0f }, { "Resonance", 0.5f },
  2370. { "Cutoff", 0.5f }, { "Filter post", 0.0f }, { "Relation", 0.0f },
  2371. { "Impact", 0.0f }, { "Preserve", 7500.0f / 44100.0f }, { "Amount", 0.0f } } };
  2372. // the engine's normalised values in core order (VST 22/23 swapped); defaults = the front-end's new instance
  2373. static const EffectInfo vintagePhaserInfo { "Vintage Phaser", {
  2374. { "Min freq.", 0.4375f }, { "Max freq.", 0.7758789f }, { "Feedback", 0.5f }, { "Manual", 0.0f }, { "Manual freq.", 0.0f },
  2375. { "HQ", 0.0f }, { "LFO speed", 0.0f }, { "Tempo sync", 0.0f }, { "Sine", 0.0f }, { "Tension", 0.0f }, { "Start phase", 0.0f },
  2376. { "L/R phase", 0.0f }, { "Delay", 0.0f }, { "Keep pitch", 0.0f }, { "Delay mix", 0.0f }, { "Delay stereo", 0.5f },
  2377. { "Delay time", 0.0f }, { "Delay sync", 0.0f }, { "Delay fdbk", 0.0f }, { "Delay LP", 0.0f }, { "Delay HP", 0.0f },
  2378. { "Mix", 0.5f }, { "Noise", 0.0f }, { "Mono input", 0.0f }, { "Gate", 0.0f }, { "Colour gain", 0.0f }, { "Colour freq.", 0.0f },
  2379. { "Input HP", 0.0f }, { "Fdbk HP", 0.0f }, { "Rate 1", 0.0f }, { "Rate 2", 1.0f }, { "Depth scale", 1.0f },
  2380. { "Pull-down", 0.0f }, { "Engine V2", 1.0f }, { "Drive", 0.0f }, { "Invert fdbk", 0.0f } } };
  2381. static const EffectInfo pitchCorrectInfo = [] {
  2382. EffectInfo info { "Pitch correction", { { "Speed", 1.0f }, { "Fine", 0.5f }, { "Bypass all", 0.0f }, { "A freq.", 0.5f },
  2383. { "Range", 0.4f } } };
  2384. static const char* names[] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
  2385. for (const auto* name : names)
  2386. info.params.push_back ({ name, 1.0f });
  2387. static const char* bypass[] = { "C off", "C# off", "D off", "D# off", "E off", "F off", "F# off", "G off", "G# off", "A off", "A# off", "B off" };
  2388. for (const auto* name : bypass)
  2389. info.params.push_back ({ name, 0.0f });
  2390. // added later (REA round 30); the defaults keep older projects as they were: plain shifter, no harmony
  2391. info.params.insert (info.params.end(), { { "Formant", 0.0f }, { "Gender", 0.5f }, { "Pitch ref.", 0.0f }, { "Stereo", 1.0f },
  2392. { "Harmonize", 0.0f }, { "MIDI", 0.0f }, { "Octaves", 0.0f }, { "Mix", 0.0f },
  2393. { "Vel", 0.0f }, { "Voice 1 pan", 0.5f }, { "Voice 2 pan", 0.5f },
  2394. { "Voice 3 pan", 0.5f }, { "Voice 4 pan", 0.5f } });
  2395. return info;
  2396. }();
  2397. static const EffectInfo lofiInfo { "Lo-fi", { { "Rate", 0.0f }, { "Bits", 0.0f }, { "Mix", 1.0f } } };
  2398. // FL's Fruity Phaser: its nine raw controls / max (core/FruityPhaser.h); defaults = a new FL instance
  2399. static const EffectInfo fruityPhaserInfo = [] {
  2400. EffectInfo info { "Fruity Phaser", {} };
  2401. float p[phaserfx::params] {};
  2402. phaserfx::toParams (phaserfx::defaults, p);
  2403. for (int i = 0; i < phaserfx::params; ++i)
  2404. info.params.push_back ({ phaserfx::paramName (i), p[i] });
  2405. return info;
  2406. }();
  2407. // FL's Fruity Send: pan, volume, dry over their ranges and the insert it sends to (core/FruityBasicFx.h)
  2408. static const EffectInfo fruitySendInfo { "Fruity Send", { { "Pan", 0.5f }, { "Volume", 0.8f }, { "Dry", 1.0f }, { "Send to", 0.0f } } };
  2409. static const EffectInfo effectorInfo { "Effector", { { "Type", 0.0f }, { "Bypass", 0.0f }, { "Wet", 1.0f }, { "X", 0.5f }, { "Y", 0.5f },
  2410. { "Mod rate", 0.5f }, { "Tempo red.", 0.0f }, { "Mod X", 0.5f }, { "Mod Y", 0.5f },
  2411. { "LFO shape", 0.0f }, { "Input", 1.0f }, { "Output", 0.5f } } };
  2412. static const EffectInfo formulaControllerInfo { "Formula Controller", { { "a", 0.0f }, { "b", 0.0f }, { "c", 0.0f } } };
  2413. static const EffectInfo peakController { "Peak Controller", { { "Base", 0.0f }, { "Amount", 0.8496f }, { "Tension", 0.5f },
  2414. { "Decay", 0.4959f }, { "LFO base", 0.0f } } };
  2415. static const EffectInfo parametric = [] {
  2416. // bands as in a mixing EQ: low shelf, 5 peaks and high shelf, all at 0 dB
  2417. constexpr peq::BandType types[] = { peq::BandType::lowShelf, peq::BandType::peak, peq::BandType::peak, peq::BandType::peak,
  2418. peq::BandType::peak, peq::BandType::peak, peq::BandType::highShelf };
  2419. constexpr double freqs[] = { 80.0, 200.0, 500.0, 1200.0, 3000.0, 6000.0, 12000.0 };
  2420. static const char* names[peq::bands][4] = {
  2421. { "B1 type", "B1 freq.", "B1 gain", "B1 Q" }, { "B2 type", "B2 freq.", "B2 gain", "B2 Q" },
  2422. { "B3 type", "B3 freq.", "B3 gain", "B3 Q" }, { "B4 type", "B4 freq.", "B4 gain", "B4 Q" },
  2423. { "B5 type", "B5 freq.", "B5 gain", "B5 Q" }, { "B6 type", "B6 freq.", "B6 gain", "B6 Q" },
  2424. { "B7 type", "B7 freq.", "B7 gain", "B7 Q" } };
  2425. static const char* slopes[peq::bands] = { "B1 slope", "B2 slope", "B3 slope", "B4 slope", "B5 slope", "B6 slope", "B7 slope" };
  2426. EffectInfo info { "Parametric EQ", {} };
  2427. for (int b = 0; b < peq::bands; ++b)
  2428. {
  2429. info.params.push_back ({ names[b][0], peq::typeValue (types[b]) });
  2430. info.params.push_back ({ names[b][1], peq::hzValue (freqs[b]) });
  2431. info.params.push_back ({ names[b][2], 0.5f });
  2432. // Q 1.0 on shelves = shelf slope S 1; on cuts, 0.707 = Butterworth
  2433. info.params.push_back ({ names[b][3], peq::qValue (types[b] == peq::BandType::lowCut || types[b] == peq::BandType::highCut ? 0.70710678 : 1.0) });
  2434. }
  2435. info.params.push_back ({ "Output", 0.5f });
  2436. for (int b = 0; b < peq::bands; ++b)
  2437. info.params.push_back ({ slopes[b], 0.0f });
  2438. return info;
  2439. }();
  2440. switch (kind)
  2441. {
  2442. case EffectKind::eq: return eq;
  2443. case EffectKind::compressor: return comp;
  2444. case EffectKind::delay: return delay;
  2445. case EffectKind::reverb: return reverb;
  2446. case EffectKind::plugin: return plugin;
  2447. case EffectKind::limiter: return limiter;
  2448. case EffectKind::filter: return filter;
  2449. case EffectKind::distortion: return distortion;
  2450. case EffectKind::chorus: return chorus;
  2451. case EffectKind::parametricEq: return parametric;
  2452. case EffectKind::utility: return utility;
  2453. case EffectKind::volumeGate: return volumeGate;
  2454. case EffectKind::peakController: return peakController;
  2455. case EffectKind::pitchShift: return pitchShift;
  2456. case EffectKind::freqShift: return freqShift;
  2457. case EffectKind::parallel: return parallelInfo;
  2458. case EffectKind::patcher: return patcherInfo;
  2459. case EffectKind::lofi: return lofiInfo;
  2460. case EffectKind::effector: return effectorInfo;
  2461. case EffectKind::crossover: return crossoverInfo;
  2462. case EffectKind::rhythmGain: return rhythmInfo;
  2463. case EffectKind::autoPan: return autoPanInfo;
  2464. case EffectKind::vocoder: return vocoderInfo;
  2465. case EffectKind::pitchCorrect: return pitchCorrectInfo;
  2466. case EffectKind::squeeze: return squeezeInfo;
  2467. case EffectKind::vintagePhaser: return vintagePhaserInfo;
  2468. case EffectKind::vocodex: return vocodexInfo;
  2469. case EffectKind::maximus: return maximusInfo;
  2470. case EffectKind::fruityLimiter: return fruityLimiterInfo;
  2471. case EffectKind::fruityCompressor: return fruityCompressorInfo;
  2472. case EffectKind::fruityWaveShaper: return waveShaperInfo;
  2473. case EffectKind::fruitySoftClipper: return softClipperInfo;
  2474. case EffectKind::fruityPanOMatic: return panOMaticInfo;
  2475. case EffectKind::fruityBalance: return balanceInfo;
  2476. case EffectKind::fruityBloodOverdrive: return bloodOverdriveInfo;
  2477. case EffectKind::reeverb2: return reeverb2Info;
  2478. case EffectKind::reeverb1: return reeverb1Info;
  2479. case EffectKind::fruityDelay2: return fruityDelay2Info;
  2480. case EffectKind::fruityDelay3: return fruityDelay3Info;
  2481. case EffectKind::stereoShaper: return stereoShaperInfo;
  2482. case EffectKind::stereoEnhancer: return stereoEnhancerInfo;
  2483. case EffectKind::transientProcessor: return transientProcessorInfo;
  2484. case EffectKind::spreader: return spreaderInfo;
  2485. case EffectKind::fruityChorus: return fruitychorusfx::info();
  2486. case EffectKind::hyperChorus: return hyperchorusfx::info();
  2487. case EffectKind::vintageChorus: return vintagechorusfx::info();
  2488. case EffectKind::grossBeat: return grossBeatInfo;
  2489. case EffectKind::lovePhilter: return philter::info();
  2490. case EffectKind::luxeVerb: return luxeVerbInfo;
  2491. case EffectKind::convolver: return convolverInfo;
  2492. case EffectKind::fruityDelayBank: return fruityDelayBankInfo;
  2493. case EffectKind::fruityMultiband: return fruityMultibandInfo;
  2494. case EffectKind::fruityFastDist: return fastDistInfo;
  2495. case EffectKind::fruityFlangus: return flangusInfo;
  2496. case EffectKind::fruityFlanger: return flangerInfo;
  2497. case EffectKind::equo: return equoInfo;
  2498. case EffectKind::flPitchShifter: return flPitchShifterInfo;
  2499. case EffectKind::multibandDelay: return multibandDelayInfo;
  2500. case EffectKind::frequencySplitter: return fsplit::info();
  2501. case EffectKind::fruityFastLP: return fastLPInfo;
  2502. case EffectKind::fruityFreeFilter: return freeFilterInfo;
  2503. case EffectKind::fruityFilter: return fruityFilterInfo;
  2504. case EffectKind::hardcore: return hardcore::info();
  2505. case EffectKind::distructor: return distructorInfo;
  2506. case EffectKind::newtone: return newtoneInfo;
  2507. case EffectKind::newtime: return newtimeInfo;
  2508. case EffectKind::facetEq: return facet::info();
  2509. case EffectKind::apexLimiter: return apex::info();
  2510. case EffectKind::ridgeStrip: return mixsuite::ridgeInfo();
  2511. case EffectKind::glowLeveler: return mixsuite::glowInfo();
  2512. case EffectKind::hushDeEsser: return mixsuite::hushInfo();
  2513. case EffectKind::aether: return mixsuite::aetherInfo();
  2514. case EffectKind::ember: return mixsuite::emberInfo();
  2515. case EffectKind::lynxTune: return lynxtune::info();
  2516. case EffectKind::fruityPhaser: return fruityPhaserInfo;
  2517. case EffectKind::epochVerb:
  2518. case EffectKind::atrium:
  2519. case EffectKind::foilPlate:
  2520. case EffectKind::nebula:
  2521. case EffectKind::halo:
  2522. case EffectKind::horizon: return verbs::info (kind);
  2523. case EffectKind::echoform: return echosuite::echoformInfo();
  2524. case EffectKind::spiralEcho: return echosuite::spiralInfo();
  2525. case EffectKind::orbit: return echosuite::orbitInfo();
  2526. case EffectKind::latticeMod: return echosuite::latticeInfo();
  2527. case EffectKind::fruitySend: return fruitySendInfo;
  2528. case EffectKind::crestCompressor: return dyn::crestInfo();
  2529. case EffectKind::prismMultiband: return dyn::prismInfo();
  2530. case EffectKind::sentryGate: return dyn::sentryInfo();
  2531. case EffectKind::quellDenoiser: return voicetools::quellInfo();
  2532. case EffectKind::geminiDoubler: return voicetools::geminiInfo();
  2533. case EffectKind::formulaController: return formulaControllerInfo;
  2534. case EffectKind::voiceShift: return voiceshift::info();
  2535. }
  2536. return eq;
  2537. }
  2538. std::string formatEffectParam (EffectKind kind, int param, float v, double bpm, const EffectParams& context)
  2539. {
  2540. if (kind == EffectKind::ridgeStrip && mixsuite::ridge::eVoicing (context)) // round 123: the console's own scales
  2541. return mixsuite::ridge::eParamText (param, v);
  2542. if (kind == EffectKind::glowLeveler && mixsuite::glow::classic (context))
  2543. return mixsuite::glow::classicParamText (param, v);
  2544. if (kind == EffectKind::hushDeEsser && mixsuite::hush::classic (context))
  2545. return mixsuite::hush::classicParamText (param, v);
  2546. if (kind == EffectKind::fruityPhaser && param == 0) // the sweep rate follows the frequency range switch
  2547. return phaserfx::sweepText (v, context[3] > 0.5f);
  2548. if (kind == EffectKind::parametricEq && peq::flLaw (context) && param >= 0 && param < peq::slopeParam + peq::bands)
  2549. {
  2550. auto p = context;
  2551. p[(std::size_t) param] = v;
  2552. if (param > peq::outputParam)
  2553. return peq::orderText (p, param - peq::slopeParam);
  2554. if (param < peq::outputParam && param % 4 == 3)
  2555. return peq::widthText (p, param / 4);
  2556. }
  2557. return formatEffectParam (kind, param, v, bpm);
  2558. }
  2559. std::string formatEffectParam (EffectKind kind, int param, float v, double bpm)
  2560. {
  2561. char text[48];
  2562. switch (kind)
  2563. {
  2564. case EffectKind::eq:
  2565. if (param == 2)
  2566. std::snprintf (text, sizeof (text), "%.0f Hz", eqMidHz (v));
  2567. else
  2568. std::snprintf (text, sizeof (text), "%+.1f dB", eqGainDb (v));
  2569. return text;
  2570. case EffectKind::compressor:
  2571. switch (param)
  2572. {
  2573. case 0: std::snprintf (text, sizeof (text), "%.1f dB", compThresholdDb (v)); break;
  2574. case 1: std::snprintf (text, sizeof (text), "%.1f:1", compRatio (v)); break;
  2575. case 2: std::snprintf (text, sizeof (text), "%.1f ms", compAttackMs (v)); break;
  2576. case 3: std::snprintf (text, sizeof (text), "%.0f ms", compReleaseMs (v)); break;
  2577. case 5: return v >= 0.5f ? "on" : "off";
  2578. case 6: std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f); break;
  2579. case 7: std::snprintf (text, sizeof (text), "%+.1f dB", -18.0f + 36.0f * v); break;
  2580. case 8: return v >= 0.5f ? "vintage program" : "classic";
  2581. case 9: return v >= 0.5f ? "manual" : "ARC";
  2582. case 10: return v >= 0.5f ? "opto" : "electro";
  2583. case 11: return v >= 0.5f ? "smooth" : "warm";
  2584. case 12: return v >= 0.5f ? "on" : "off";
  2585. default: std::snprintf (text, sizeof (text), "+%.1f dB", compMakeupDb (v)); break;
  2586. }
  2587. return text;
  2588. case EffectKind::delay:
  2589. if (param == 0)
  2590. {
  2591. const auto index = delayIndex (v);
  2592. std::snprintf (text, sizeof (text), "%s (%.0f ms)", delayNames[(std::size_t) index],
  2593. delayDivisions[(std::size_t) index] * 60000.0 / std::max (bpm, 20.0));
  2594. return text;
  2595. }
  2596. if (param == 3)
  2597. return v > 0.5f ? "on" : "off";
  2598. std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f);
  2599. return text;
  2600. case EffectKind::reverb:
  2601. if (param == 5)
  2602. return v <= 0.001f ? std::string ("off") : (std::snprintf (text, sizeof (text), "%.0f Hz", reverbLowCutHz (v)), std::string (text));
  2603. if (param == 6)
  2604. return v >= 0.999f ? std::string ("off") : (std::snprintf (text, sizeof (text), "%.1f kHz", reverbHighCutHz (v) / 1000.0f), std::string (text));
  2605. if (param == 7)
  2606. std::snprintf (text, sizeof (text), "%.0f ms", v * 1000.0f);
  2607. else
  2608. std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f);
  2609. return text;
  2610. case EffectKind::limiter:
  2611. switch (param)
  2612. {
  2613. case 0: std::snprintf (text, sizeof (text), "%.1f dB", limiterCeilingDb (v)); break;
  2614. case 1: std::snprintf (text, sizeof (text), "+%.1f dB", limiterGainDb (v)); break;
  2615. default: std::snprintf (text, sizeof (text), "%.0f ms", limiterReleaseMs (v)); break;
  2616. }
  2617. return text;
  2618. case EffectKind::filter:
  2619. switch (param)
  2620. {
  2621. case 0: return filterNames[(std::size_t) filterType (v)];
  2622. case 1: std::snprintf (text, sizeof (text), "%.0f Hz", filterHz (v)); break;
  2623. case 2: std::snprintf (text, sizeof (text), "Q %.2f", filterQ (v)); break;
  2624. default: std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f); break;
  2625. }
  2626. return text;
  2627. case EffectKind::distortion:
  2628. switch (param)
  2629. {
  2630. case 0: std::snprintf (text, sizeof (text), "+%.1f dB", distortionDriveDb (v)); break;
  2631. case 1: std::snprintf (text, sizeof (text), "%.0f Hz", distortionToneHz (v)); break;
  2632. case 2: std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f); break;
  2633. default: std::snprintf (text, sizeof (text), "%+.1f dB", (v - 0.5f) * 24.0f); break;
  2634. }
  2635. return text;
  2636. case EffectKind::chorus:
  2637. switch (param)
  2638. {
  2639. case 0: std::snprintf (text, sizeof (text), "%.2f Hz", chorusRateHz (v)); break;
  2640. case 1: std::snprintf (text, sizeof (text), "%.1f ms", chorusDepthMs (v)); break;
  2641. default: std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f); break;
  2642. }
  2643. return text;
  2644. case EffectKind::parametricEq:
  2645. {
  2646. if (param == peq::outputParam)
  2647. std::snprintf (text, sizeof (text), "%+.1f dB", peq::gainDb (v));
  2648. else if (param > peq::outputParam)
  2649. std::snprintf (text, sizeof (text), "%d dB/oct", 12 * peq::slopeStages (v));
  2650. else
  2651. switch (param % 4)
  2652. {
  2653. case 0: return peq::typeName (peq::type (v));
  2654. case 1:
  2655. {
  2656. const auto f = peq::hz (v);
  2657. if (f >= 1000.0)
  2658. std::snprintf (text, sizeof (text), "%.2f kHz", f / 1000.0);
  2659. else
  2660. std::snprintf (text, sizeof (text), "%.0f Hz", f);
  2661. break;
  2662. }
  2663. case 2: std::snprintf (text, sizeof (text), "%+.1f dB", peq::gainDb (v)); break;
  2664. default: std::snprintf (text, sizeof (text), "Q %.2f", peq::q (v)); break;
  2665. }
  2666. return text;
  2667. }
  2668. case EffectKind::utility:
  2669. if (param == 0)
  2670. {
  2671. if (v <= 0.0f)
  2672. return "mute";
  2673. std::snprintf (text, sizeof (text), "%+.1f dB", utilityGainDb (v));
  2674. }
  2675. else if (param == 1)
  2676. {
  2677. const auto pan = v * 2.0f - 1.0f;
  2678. if (std::abs (pan) < 0.005f)
  2679. return "center";
  2680. std::snprintf (text, sizeof (text), "%.0f%% %s", std::abs (pan) * 100.0f, pan < 0.0f ? "L" : "R");
  2681. }
  2682. else
  2683. std::snprintf (text, sizeof (text), "%.2f", utilityMatrix (v));
  2684. return text;
  2685. case EffectKind::volumeGate:
  2686. if (param < gate::steps || param == gate::mixParam)
  2687. std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f);
  2688. else
  2689. std::snprintf (text, sizeof (text), "%.1f ms", param == gate::attackParam ? gate::attackMs (v) : gate::releaseMs (v));
  2690. return text;
  2691. case EffectKind::pitchShift:
  2692. switch (param)
  2693. {
  2694. case 0: std::snprintf (text, sizeof (text), "%+.0f st", pitch::semitones (v)); break;
  2695. case 1: std::snprintf (text, sizeof (text), "%+.0f ct", pitch::cents (v)); break;
  2696. case 3: std::snprintf (text, sizeof (text), "%.0f ms", pitch::windowMs (v)); break;
  2697. default: std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f); break;
  2698. }
  2699. return text;
  2700. case EffectKind::freqShift:
  2701. if (param == 0)
  2702. std::snprintf (text, sizeof (text), "%+.1f Hz", fshift::hz (v));
  2703. else
  2704. std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f);
  2705. return text;
  2706. case EffectKind::peakController:
  2707. if (param == 1)
  2708. {
  2709. const auto raw = (v * 2.0 - 1.0) * 256.0;
  2710. std::snprintf (text, sizeof (text), "%+.0f%%", (raw < 0.0 ? -1.0 : 1.0) * (std::pow (6.0, std::abs (raw) / 256.0) - 1.0) * 40.0);
  2711. }
  2712. else if (param == 3)
  2713. std::snprintf (text, sizeof (text), "%.2f / beat", (std::pow (10001.0, (5.0 + 123.0 * v) / 128.0) - 1.0) * 0.0192);
  2714. else if (param == 2)
  2715. std::snprintf (text, sizeof (text), "%+.0f", (v * 2.0f - 1.0f) * 128.0f);
  2716. else
  2717. std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f);
  2718. return text;
  2719. case EffectKind::lofi:
  2720. if (param == 0)
  2721. std::snprintf (text, sizeof (text), "%.0f Hz", 44100.0 / lofi::holdSamples (v));
  2722. else if (param == 1)
  2723. std::snprintf (text, sizeof (text), "%.1f bits", std::log2 (lofi::levels (v)));
  2724. else
  2725. std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f);
  2726. return text;
  2727. case EffectKind::effector:
  2728. return effector::formatParam (param, v, bpm);
  2729. case EffectKind::pitchCorrect:
  2730. switch (param)
  2731. {
  2732. case 0:
  2733. {
  2734. const auto u = 1.0 - v;
  2735. if (u < 0.01)
  2736. return "instant";
  2737. std::snprintf (text, sizeof (text), "%.1f ms", (3.0 * u * u * u + 0.001) / 8.82 * 1000.0);
  2738. break;
  2739. }
  2740. case 1: std::snprintf (text, sizeof (text), "%+.0f ct", (2.0f * v - 1.0f) * 100.0f); break;
  2741. case 3: std::snprintf (text, sizeof (text), "%.1f Hz", pcorr::noteA (v) * 8.0); break;
  2742. case 4: std::snprintf (text, sizeof (text), "%.0f Hz min.", pcorr::minHz[pcorr::range (v)]); break;
  2743. case 30: std::snprintf (text, sizeof (text), "x%.2f", std::pow (2.0, 2.0 * v - 1.0)); break;
  2744. case 31: return (int) (v + v) == 0 ? "left" : ((int) (v + v) == 1 ? "independent" : "right");
  2745. case 32: std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f); break;
  2746. case 36: return v > 0.5f ? "mix" : "replace";
  2747. case 38: case 39: case 40: case 41:
  2748. std::snprintf (text, sizeof (text), "%+.0f%%", (2.0f * v - 1.0f) * 100.0f);
  2749. break;
  2750. default:
  2751. if (param >= 29)
  2752. return v > 0.5f ? "on" : "off";
  2753. return v > 0.5f ? (param >= 17 ? "bypassed" : "yes") : (param >= 17 ? "-" : "no");
  2754. }
  2755. return text;
  2756. case EffectKind::squeeze:
  2757. std::snprintf (text, sizeof (text), "%d", (int) std::lround (v * squeezeMax[(std::size_t) std::clamp (param, 0, 11)]));
  2758. return text;
  2759. case EffectKind::reeverb2: return reeverb2ParamText (param, v);
  2760. case EffectKind::luxeVerb: return luxeVerbParamText (param, v);
  2761. case EffectKind::convolver: return convolverParamText (param, v);
  2762. case EffectKind::reeverb1: return reeverb1ParamText (param, v);
  2763. case EffectKind::fruityChorus: return fruitychorusfx::paramText (param, v);
  2764. case EffectKind::hyperChorus: return hyperchorusfx::paramText (param, v);
  2765. case EffectKind::vintageChorus: return vintagechorusfx::paramText (param, v);
  2766. case EffectKind::vintagePhaser:
  2767. switch (param)
  2768. {
  2769. case 0: case 1: case 4: std::snprintf (text, sizeof (text), "%.0f Hz", 1.25 * std::pow (2.0, 14.0 * v)); break;
  2770. case 3: case 5: case 7: case 12: case 13: case 17: case 23: case 24: case 33: case 35: return v >= 0.5f ? "on" : "off";
  2771. case 8: return v >= 0.5f ? "sine" : "triangle";
  2772. case 25: std::snprintf (text, sizeof (text), "%.1f dB", 30.0f * v); break;
  2773. case 26: std::snprintf (text, sizeof (text), "%.0f Hz", 50.0f + 600.0f * v); break;
  2774. case 27: case 28: std::snprintf (text, sizeof (text), "%.0f Hz", 195.0f * v * v * v + 5.0f); break;
  2775. case 34: std::snprintf (text, sizeof (text), "%+.1f dB", 30.0f * v - 15.0f); break;
  2776. default: std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f); break;
  2777. }
  2778. return text;
  2779. case EffectKind::vocoder:
  2780. switch (param)
  2781. {
  2782. case 0: std::snprintf (text, sizeof (text), "%d", vocoder::bands (v)); break;
  2783. case 1: std::snprintf (text, sizeof (text), "%d", vocoder::order (v)); break;
  2784. case 2: return std::array<const char*, 3> { "modulator", "carrier", "mix" }[(std::size_t) std::clamp ((int) std::lround (v * 2.0f), 0, 2)];
  2785. case 3: case 7: case 12: case 16: return v > 0.5f ? "on" : "off";
  2786. case 4: case 5: std::snprintf (text, sizeof (text), "%.0f Hz", (double) fvocoder::edgeHz (vocoder::raw (v, param - 4))); break;
  2787. case 8: std::snprintf (text, sizeof (text), "%+.0f ct", v * 2400.0f - 1200.0f); break;
  2788. case 9: std::snprintf (text, sizeof (text), "%.0f%%", 5.0f + 195.0f * v); break;
  2789. case 10: case 11: std::snprintf (text, sizeof (text), "%d ms", vocoder::raw (v, param - 4)); break;
  2790. case 13: case 14: case 15: std::snprintf (text, sizeof (text), "%.2f", (double) fvocoder::mixLevel (vocoder::raw (v, param - 4))); break;
  2791. default: std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f); break;
  2792. }
  2793. return text;
  2794. case EffectKind::autoPan:
  2795. if (param >= autopan::source && param < autopan::count)
  2796. return autopan::paramText (param, v);
  2797. [[fallthrough]];
  2798. case EffectKind::rhythmGain:
  2799. if (param == 0)
  2800. std::snprintf (text, sizeof (text), "%.3g beats", v * 64.0f);
  2801. else if (kind == EffectKind::rhythmGain && param == 1)
  2802. std::snprintf (text, sizeof (text), "%d", (int) std::lround (v * rhythm::maxPoints));
  2803. else if (kind == EffectKind::autoPan && (param == 1 || param == 3))
  2804. std::snprintf (text, sizeof (text), "%+.0f%%", (2.0f * v - 1.0f) * 100.0f);
  2805. else if (kind == EffectKind::autoPan && param >= autopan::count) // round 136: the Rhythm voicing (after round 135's panner)
  2806. {
  2807. switch (param - autopan::count + 7)
  2808. {
  2809. case 7: return v > 0.5f ? "Rhythm" : "Classic";
  2810. case 8: std::snprintf (text, sizeof (text), "%.2f Hz", rhythmpan::rateHz (v)); break;
  2811. case 9: return v > 0.5f ? "beats" : "Hz";
  2812. case 10: std::snprintf (text, sizeof (text), "%.3g beats", rhythmpan::beats (v)); break;
  2813. case 11: std::snprintf (text, sizeof (text), "%.1f deg", 210.0f * v); break;
  2814. case 12: std::snprintf (text, sizeof (text), "%+.1f deg", -105.0f + 210.0f * v); break;
  2815. case 14: return v > 0.5f ? "8 steps" : "left / right";
  2816. case 17: return v < 0.25f ? "digital" : (v < 0.75f ? "analog" : "analog (hot)");
  2817. case 18: std::snprintf (text, sizeof (text), "%+.1f dB", -24.0f + 48.0f * v); break;
  2818. default: std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f); break;
  2819. }
  2820. }
  2821. else
  2822. std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f);
  2823. return text;
  2824. case EffectKind::fruityFastDist:
  2825. return fastdistfx::paramText (param, v);
  2826. case EffectKind::fruityFlangus:
  2827. return flangusfx::paramText (param, v);
  2828. case EffectKind::fruityFlanger:
  2829. return flangerfx::paramText (param, v);
  2830. case EffectKind::crossover:
  2831. if (param == 0 || param == 3)
  2832. return v > 0.5f ? "on" : "off";
  2833. if (param == 1 || param == 4)
  2834. std::snprintf (text, sizeof (text), "%.0f Hz", xover::hz (v));
  2835. else
  2836. std::snprintf (text, sizeof (text), "%d dB/oct", xover::dbPerOctave[xover::combo (v)]);
  2837. return text;
  2838. case EffectKind::fruityLimiter:
  2839. return fldyn::limiterParamText (param, v);
  2840. case EffectKind::fruityCompressor:
  2841. return fldyn::compressorParamText (param, v);
  2842. case EffectKind::fruityWaveShaper:
  2843. return flshape::waveShaperParamText (param, v);
  2844. case EffectKind::fruitySoftClipper:
  2845. return flshape::softClipperParamText (param, v);
  2846. case EffectKind::stereoShaper:
  2847. return stereofx::stereoShaperParamText (param, v);
  2848. case EffectKind::stereoEnhancer:
  2849. return stereofx::stereoEnhancerParamText (param, v);
  2850. case EffectKind::transientProcessor:
  2851. return stereofx::transientProcessorParamText (param, v);
  2852. case EffectKind::spreader:
  2853. return stereofx::spreaderParamText (param, v);
  2854. case EffectKind::fruityDelayBank:
  2855. return fldbank::globalText (param, v);
  2856. case EffectKind::fruityMultiband:
  2857. return flmb::paramText (param, v);
  2858. case EffectKind::frequencySplitter:
  2859. return fsplit::paramText (param, v);
  2860. case EffectKind::hardcore:
  2861. return hardcore::paramText (param, v);
  2862. case EffectKind::fruityPanOMatic:
  2863. return flbasic::panOMaticParamText (param, v);
  2864. case EffectKind::fruityBalance:
  2865. return flbasic::balanceParamText (param, v);
  2866. case EffectKind::fruitySend:
  2867. return flbasic::sendParamText (param, v);
  2868. case EffectKind::fruityBloodOverdrive:
  2869. return flbasic::bloodOverdriveParamText (param, v);
  2870. case EffectKind::equo:
  2871. return equofx::paramText (param, v);
  2872. case EffectKind::distructor:
  2873. return distructor::paramText (param, v);
  2874. case EffectKind::flPitchShifter:
  2875. return psfl::paramText (param, v);
  2876. case EffectKind::fruityFastLP:
  2877. return flfilter::fastLPParamText (param, v);
  2878. case EffectKind::fruityFreeFilter:
  2879. return flfilter::freeFilterParamText (param, v);
  2880. case EffectKind::fruityFilter:
  2881. return flfilter::filterParamText (param, v);
  2882. case EffectKind::multibandDelay:
  2883. return mbdelay::paramText (param, v);
  2884. case EffectKind::newtone:
  2885. case EffectKind::newtime:
  2886. return newtonefx::paramText (param, v);
  2887. case EffectKind::facetEq:
  2888. return facet::paramText (param, v);
  2889. case EffectKind::apexLimiter:
  2890. return apex::paramText (param, v);
  2891. case EffectKind::ridgeStrip:
  2892. case EffectKind::glowLeveler:
  2893. case EffectKind::hushDeEsser:
  2894. case EffectKind::aether:
  2895. case EffectKind::ember:
  2896. return mixsuite::paramText (kind, param, v);
  2897. case EffectKind::lynxTune:
  2898. return lynxtune::paramText (param, v);
  2899. case EffectKind::fruityPhaser:
  2900. return phaserfx::paramText (param, v);
  2901. case EffectKind::epochVerb:
  2902. case EffectKind::atrium:
  2903. case EffectKind::foilPlate:
  2904. case EffectKind::nebula:
  2905. case EffectKind::halo:
  2906. case EffectKind::horizon:
  2907. return verbs::paramText (kind, param, v, bpm);
  2908. case EffectKind::echoform:
  2909. case EffectKind::spiralEcho:
  2910. case EffectKind::orbit:
  2911. case EffectKind::latticeMod:
  2912. return echosuite::paramText (kind, param, v);
  2913. case EffectKind::crestCompressor:
  2914. case EffectKind::prismMultiband:
  2915. case EffectKind::sentryGate:
  2916. return dyn::paramText (kind, param, v);
  2917. case EffectKind::quellDenoiser:
  2918. case EffectKind::geminiDoubler:
  2919. return voicetools::paramText (kind, param, v);
  2920. case EffectKind::voiceShift:
  2921. return voiceshift::paramText (param, v);
  2922. case EffectKind::fruityDelay2:
  2923. return fldelay::delay2ParamText (param, v);
  2924. case EffectKind::fruityDelay3:
  2925. return fldelay::delay3ParamText (param, v, bpm);
  2926. case EffectKind::lovePhilter:
  2927. return philter::paramText (param, v);
  2928. case EffectKind::grossBeat:
  2929. {
  2930. const auto raw = grossbeat::rawFromParam (param, v);
  2931. if (param < 2)
  2932. std::snprintf (text, sizeof (text), "slot %d", raw + 1);
  2933. else if (param == 2 || param == 3)
  2934. std::snprintf (text, sizeof (text), "%.0f%%", raw / 2.56);
  2935. else if (param == 4 || param == 5) // 0…500 ms attack, 0…1000 ms release (REA_rodada14 §2.2)
  2936. std::snprintf (text, sizeof (text), "%.1f ms", (std::pow (501.0, raw / 10000.0) - 1.0) * (param == 5 ? 2.0 : 1.0));
  2937. else if (param == 6)
  2938. std::snprintf (text, sizeof (text), "%.0f%%", raw / 2.56);
  2939. else
  2940. return raw != 0 ? "on" : "off";
  2941. return text;
  2942. }
  2943. case EffectKind::formulaController: // the knobs a, b, c as the formula sees them
  2944. std::snprintf (text, sizeof (text), "%.3f", v);
  2945. return text;
  2946. case EffectKind::plugin:
  2947. case EffectKind::parallel:
  2948. case EffectKind::patcher:
  2949. case EffectKind::vocodex:
  2950. case EffectKind::maximus:
  2951. break;
  2952. }
  2953. return {};
  2954. }
  2955. EffectSlot makeEffectSlot (EffectKind kind)
  2956. {
  2957. EffectSlot slot;
  2958. slot.kind = kind;
  2959. const auto& info = effectInfo (kind);
  2960. for (std::size_t i = 0; i < info.params.size() && i < slot.params.size(); ++i)
  2961. slot.params[i] = info.params[i].defaultValue;
  2962. if (kind == EffectKind::patcher) // a new Patcher passes its input through, as FL's
  2963. slot.patcher.wires.push_back ({});
  2964. return slot;
  2965. }
  2966. void upgradeLoadedEffectParams (EffectSlot& slot, std::size_t savedCount) noexcept
  2967. {
  2968. // round 147: Prism Multiband saved before its measured Dynamic phase engine keeps the round-108 construction
  2969. if (slot.kind == EffectKind::prismMultiband && savedCount <= (std::size_t) dyn::prism::dynamicEngine)
  2970. slot.params[(std::size_t) dyn::prism::dynamicEngine] = 0.0f;
  2971. }
  2972. std::unique_ptr<Effect> makeParallelEffect (const EffectSlot& slot)
  2973. {
  2974. return std::make_unique<ParallelEffect> (slot);
  2975. }
  2976. std::unique_ptr<Effect> makeEffect (const EffectSlot& slot)
  2977. {
  2978. if (slot.kind == EffectKind::parallel)
  2979. return makeParallelEffect (slot);
  2980. if (slot.kind == EffectKind::patcher) // built-in nodes only; the rack builds it with its plugins (core/Patcher.h)
  2981. {
  2982. return patcher::makeEffect (slot, 44100.0, patcher::builtInFactories (44100.0));
  2983. }
  2984. if (slot.kind == EffectKind::formulaController)
  2985. return formula::makeEffect (slot.state);
  2986. if (slot.kind == EffectKind::vocodex)
  2987. return vocodex::make (slot.state);
  2988. if (slot.kind == EffectKind::maximus)
  2989. return maximusfx::make (slot.state);
  2990. if (slot.kind == EffectKind::multibandDelay)
  2991. return mbdelay::make (slot.state);
  2992. if (slot.kind == EffectKind::vocoder)
  2993. return std::make_unique<Vocoder> (slot.state);
  2994. if (slot.kind == EffectKind::equo)
  2995. return equofx::make (slot.state);
  2996. if (slot.kind == EffectKind::hardcore)
  2997. return hardcore::make (slot);
  2998. if (slot.kind == EffectKind::distructor)
  2999. return distructor::make (slot.state);
  3000. if (slot.kind == EffectKind::fruityWaveShaper)
  3001. return flshape::makeWaveShaper (slot.state);
  3002. if (slot.kind == EffectKind::parametricEq && peq::flLaw (slot.params))
  3003. return std::make_unique<ParametricEq> (slot.params);
  3004. if (slot.kind == EffectKind::frequencySplitter)
  3005. return fsplit::make (slot.params);
  3006. if (slot.kind == EffectKind::hushDeEsser) // its look-ahead (latency) known before the first block (round 128)
  3007. return mixsuite::makeHush (&slot.params);
  3008. if (slot.kind == EffectKind::facetEq) // its phase mode (latency) known before the first block
  3009. return facet::make (&slot.params);
  3010. if (dyn::isDynKind (slot.kind)) // their look-ahead / oversampling latency known before the first block
  3011. return dyn::make (slot.kind, &slot.params);
  3012. if (slot.kind == EffectKind::apexLimiter) // round 135: the oversampling latency known before the first block
  3013. return apex::make (&slot.params);
  3014. if (slot.kind == EffectKind::hyperChorus)
  3015. return hyperchorusfx::make (hyperchorusfx::instanceOf (slot.state));
  3016. if (slot.kind == EffectKind::vintageChorus)
  3017. return vintagechorusfx::make (hyperchorusfx::instanceOf (slot.state));
  3018. if (slot.kind == EffectKind::grossBeat)
  3019. return grossbeat::make (slot.state);
  3020. if (slot.kind == EffectKind::lovePhilter)
  3021. return philter::make (slot);
  3022. if (slot.kind == EffectKind::convolver)
  3023. return makeConvolver (slot.state);
  3024. if (slot.kind == EffectKind::fruityDelayBank)
  3025. return fldbank::make (slot.state);
  3026. if (slot.kind == EffectKind::fruityMultiband)
  3027. return slot.state.empty() ? flmb::make() : flmb::make (slot.state);
  3028. return makeEffect (slot.kind);
  3029. }
  3030. std::unique_ptr<Effect> makeEffect (EffectKind kind)
  3031. {
  3032. switch (kind)
  3033. {
  3034. case EffectKind::eq: return std::make_unique<Eq>();
  3035. case EffectKind::compressor: return std::make_unique<Compressor>();
  3036. case EffectKind::delay: return std::make_unique<Delay>();
  3037. case EffectKind::reverb: return std::make_unique<Reverb>();
  3038. case EffectKind::limiter: return std::make_unique<Limiter>();
  3039. case EffectKind::filter: return std::make_unique<Filter>();
  3040. case EffectKind::distortion: return std::make_unique<Distortion>();
  3041. case EffectKind::chorus: return std::make_unique<Chorus>();
  3042. case EffectKind::parametricEq: return std::make_unique<ParametricEq>();
  3043. case EffectKind::utility: return std::make_unique<Utility>();
  3044. case EffectKind::volumeGate: return std::make_unique<VolumeGate>();
  3045. case EffectKind::peakController: return std::make_unique<PeakController>();
  3046. case EffectKind::pitchShift: return std::make_unique<PitchShift>();
  3047. case EffectKind::freqShift: return std::make_unique<FreqShift>();
  3048. case EffectKind::parallel: return std::make_unique<ParallelEffect> (EffectSlot {}); // empty: use makeParallelEffect
  3049. case EffectKind::patcher: return makeEffect (makeEffectSlot (EffectKind::patcher)); // empty graph: silence
  3050. case EffectKind::lofi: return std::make_unique<LoFi>();
  3051. case EffectKind::effector: return effector::make();
  3052. case EffectKind::crossover: return std::make_unique<Crossover>();
  3053. case EffectKind::rhythmGain: return std::make_unique<RhythmGain>();
  3054. case EffectKind::autoPan: return std::make_unique<AutoPan>();
  3055. case EffectKind::vocoder: return std::make_unique<Vocoder> (std::vector<std::uint8_t> {}); // use makeEffect (slot) for the band levels
  3056. case EffectKind::squeeze: return std::make_unique<Squeeze>();
  3057. case EffectKind::vintagePhaser: return makeVintagePhaser();
  3058. case EffectKind::vocodex: return vocodex::make ({}); // without a state: passes the signal; use makeEffect (slot)
  3059. case EffectKind::maximus: return maximusfx::make ({}); // without a state: passes the signal; use makeEffect (slot)
  3060. case EffectKind::fruityLimiter: return fldyn::makeLimiter();
  3061. case EffectKind::fruityCompressor: return fldyn::makeCompressor();
  3062. case EffectKind::fruityWaveShaper: return flshape::makeWaveShaper ({}); // FL's default curve; use makeEffect (slot)
  3063. case EffectKind::fruitySoftClipper: return flshape::makeSoftClipper();
  3064. case EffectKind::fruityPanOMatic: return flbasic::makePanOMatic();
  3065. case EffectKind::fruityBalance: return flbasic::makeBalance();
  3066. case EffectKind::fruitySend: return flbasic::makeSend(); // FL's Fruity Send (REA_rodada105_send)
  3067. case EffectKind::fruityBloodOverdrive: return flbasic::makeBloodOverdrive();
  3068. case EffectKind::fruityFastLP: return flfilter::makeFastLP();
  3069. case EffectKind::fruityFreeFilter: return flfilter::makeFreeFilter();
  3070. case EffectKind::fruityFilter: return flfilter::makeFilter();
  3071. case EffectKind::reeverb2: return makeReeverb2();
  3072. case EffectKind::luxeVerb: return makeLuxeVerb();
  3073. case EffectKind::convolver: return makeConvolver(); // no impulse response: dry only; use makeEffect (slot)
  3074. case EffectKind::reeverb1: return makeReeverb1();
  3075. case EffectKind::fruityDelay2: return fldelay::makeDelay2();
  3076. case EffectKind::fruityDelay3: return fldelay::makeDelay3();
  3077. case EffectKind::stereoShaper: return stereofx::makeStereoShaper();
  3078. case EffectKind::stereoEnhancer: return stereofx::makeStereoEnhancer();
  3079. case EffectKind::transientProcessor: return stereofx::makeTransientProcessor();
  3080. case EffectKind::spreader: return stereofx::makeSpreader();
  3081. case EffectKind::fruityChorus: return fruitychorusfx::make();
  3082. case EffectKind::hyperChorus: return hyperchorusfx::make();
  3083. case EffectKind::vintageChorus: return vintagechorusfx::make();
  3084. case EffectKind::grossBeat: return grossbeat::make ({}); // without a state: passes the signal; use makeEffect (slot)
  3085. case EffectKind::lovePhilter: return philter::make (EffectSlot {}); // without a state: passes the signal
  3086. case EffectKind::fruityDelayBank: return fldbank::make ({}); // a new FL instance; use makeEffect (slot) for a state
  3087. case EffectKind::fruityMultiband: return flmb::make();
  3088. case EffectKind::equo: return equofx::make ({}); // FL's default EQUO; use makeEffect (slot)
  3089. case EffectKind::flPitchShifter: return psfl::make();
  3090. case EffectKind::frequencySplitter: return fsplit::make();
  3091. case EffectKind::hardcore: return hardcore::make (makeEffectSlot (EffectKind::hardcore)); // no cabinet impulses; use makeEffect (slot)
  3092. case EffectKind::distructor: return distructor::make ({}); // without a state: passes the signal; use makeEffect (slot)
  3093. case EffectKind::multibandDelay: return mbdelay::make ({}); // FL's default Multiband Delay; use makeEffect (slot)
  3094. case EffectKind::pitchCorrect: return std::make_unique<PitchCorrect>();
  3095. case EffectKind::fruityFastDist: return fastdistfx::make();
  3096. case EffectKind::fruityFlangus: return flangusfx::make();
  3097. case EffectKind::fruityFlanger: return flangerfx::make();
  3098. case EffectKind::newtone:
  3099. case EffectKind::newtime: return newtonefx::make (nullptr); // without its sample: a pass-through
  3100. case EffectKind::facetEq: return facet::make();
  3101. case EffectKind::apexLimiter: return apex::make();
  3102. case EffectKind::ridgeStrip:
  3103. case EffectKind::glowLeveler:
  3104. case EffectKind::hushDeEsser:
  3105. case EffectKind::aether:
  3106. case EffectKind::ember: return mixsuite::make (kind); // LYNX's own mixing suite (REA_rodada96)
  3107. case EffectKind::lynxTune: return lynxtune::make(); // LYNX's own pitch corrector (REA_rodada95)
  3108. case EffectKind::fruityPhaser: return phaserfx::make(); // FL's Fruity Phaser, exact (REA_rodada105_phaser)
  3109. case EffectKind::epochVerb:
  3110. case EffectKind::atrium:
  3111. case EffectKind::foilPlate:
  3112. case EffectKind::nebula:
  3113. case EffectKind::halo:
  3114. case EffectKind::horizon: return verbs::make (kind); // LYNX's own reverbs (REA_rodada100)
  3115. case EffectKind::echoform:
  3116. case EffectKind::spiralEcho:
  3117. case EffectKind::orbit:
  3118. case EffectKind::latticeMod: return echosuite::make (kind); // LYNX's delay / modulation suite (REA_rodada101)
  3119. case EffectKind::crestCompressor:
  3120. case EffectKind::prismMultiband:
  3121. case EffectKind::sentryGate: return dyn::make (kind); // LYNX's dynamics suite (REA_rodada108)
  3122. case EffectKind::quellDenoiser:
  3123. case EffectKind::geminiDoubler: return voicetools::make (kind); // LYNX's voice tools (REA_rodada119)
  3124. case EffectKind::formulaController: return formula::makeEffect ({});
  3125. case EffectKind::voiceShift: return voiceshift::make(); // round 135
  3126. case EffectKind::plugin: break; // created by the app (RackState::Factories)
  3127. }
  3128. return std::make_unique<Eq>();
  3129. }
  3130. } // namespace lynx