Просмотр исходного кода

Hardcore: wire the exact engine into import, mixer effects, project files and tests; AVX cabinet convolution (REA round 71)

Ka1-S 1 месяц назад
Родитель
Сommit
cf76b5be1b

+ 1 - 0
CMakeLists.txt

@@ -77,6 +77,7 @@ add_library(lynx_core STATIC
     src/core/FlPatcher.cpp
     src/core/ThreeOsc.cpp
     src/core/Plucked.cpp
+    src/core/HardcoreFx.cpp
     src/core/BeepMap.cpp
     src/core/Sawer.cpp
     src/core/Inflate.cpp

+ 2 - 0
scripts/build-local.sh

@@ -28,6 +28,8 @@ CORE="$CORE src/core/ThreeOsc.cpp"
 CORE="$CORE src/core/WaveAnalysis.cpp"
 # FL's Plucked!, Sawer and BeepMap engines (REA round 65)
 CORE="$CORE src/core/Plucked.cpp src/core/BeepMap.cpp src/core/Sawer.cpp"
+# FL's Hardcore (REA round 71)
+CORE="$CORE src/core/HardcoreFx.cpp"
 # WavPack decoder (C)
 if [[ -z "${CC:-}" ]]; then
     case "$CXX" in

+ 2 - 0
scripts/build-windows-zig.sh

@@ -100,6 +100,8 @@ APP_SOURCES+=(src/core/ThreeOsc.cpp)
 APP_SOURCES+=(src/core/WaveAnalysis.cpp src/ui/WaveformView.cpp)
 # FL's Plucked!, Sawer and BeepMap engines (REA round 65)
 APP_SOURCES+=(src/core/Plucked.cpp src/core/BeepMap.cpp src/core/Sawer.cpp)
+# FL's Hardcore (REA round 71)
+APP_SOURCES+=(src/core/HardcoreFx.cpp)
 
 echo "WavPack (decoder, C)..."
 mkdir -p "$OUT/wavpack"

+ 8 - 0
src/core/Effects.cpp

@@ -16,6 +16,7 @@
 #include "core/FruityBasicFx.h"
 #include "core/FruityDelay.h"
 #include "core/FrequencySplitter.h"
+#include "core/HardcoreFx.h"
 #include "core/StereoFx.h"
 #include "core/ChorusFx.h"
 #include "core/GrossBeat.h"
@@ -2470,6 +2471,7 @@ const EffectInfo& effectInfo (EffectKind kind)
         case EffectKind::equo: return equoInfo;
         case EffectKind::flPitchShifter: return flPitchShifterInfo;
         case EffectKind::frequencySplitter: return fsplit::info();
+        case EffectKind::hardcore: return hardcore::info();
     }
     return eq;
 }
@@ -2797,6 +2799,9 @@ std::string formatEffectParam (EffectKind kind, int param, float v, double bpm)
         case EffectKind::frequencySplitter:
             return fsplit::paramText (param, v);
 
+        case EffectKind::hardcore:
+            return hardcore::paramText (param, v);
+
         case EffectKind::fruityPanOMatic:
             return flbasic::panOMaticParamText (param, v);
 
@@ -2870,6 +2875,8 @@ std::unique_ptr<Effect> makeEffect (const EffectSlot& slot)
         return maximusfx::make (slot.state);
     if (slot.kind == EffectKind::equo)
         return equofx::make (slot.state);
+    if (slot.kind == EffectKind::hardcore)
+        return hardcore::make (slot);
     if (slot.kind == EffectKind::fruityWaveShaper)
         return flshape::makeWaveShaper (slot.state);
     if (slot.kind == EffectKind::parametricEq && peq::flLaw (slot.params))
@@ -2944,6 +2951,7 @@ std::unique_ptr<Effect> makeEffect (EffectKind kind)
         case EffectKind::equo: return equofx::make ({}); // FL's default EQUO; use makeEffect (slot)
         case EffectKind::flPitchShifter: return psfl::make();
         case EffectKind::frequencySplitter: return fsplit::make();
+        case EffectKind::hardcore: return hardcore::make (makeEffectSlot (EffectKind::hardcore)); // no cabinet impulses; use makeEffect (slot)
         case EffectKind::pitchCorrect: return std::make_unique<PitchCorrect>();
         case EffectKind::fruityFastDist: return fastdistfx::make();
         case EffectKind::fruityFlangus: return flangusfx::make();

+ 11 - 0
src/core/FlEffects.cpp

@@ -6,6 +6,7 @@
 #include "core/Vocodex.h"
 #include "core/MaximusFx.h"
 #include "core/EquoFx.h"
+#include "core/HardcoreFx.h"
 #include "core/PitchShifterFl.h"
 #include "core/ParametricEqFl.h"
 #include "core/FruityDynamics.h"
@@ -945,6 +946,9 @@ std::optional<EffectSlot> effectFromFl (const std::string& pluginName, const std
     if (pluginName == "Fruity Convolver" && data) // impulse response file of the installation (REA_rodada60)
         if (auto exact = convolverFromFl (state, data))
             return exact;
+    if (pluginName == "Hardcore" && data) // the exact engine with the installation's cabinet impulses (REA_rodada71)
+        if (auto exact = hardcore::fromFl (state, data))
+            return exact;
     if (pluginName == "Soundgoodizer" && data)
         if (const auto path = soundgoodizerPresetPath (state); ! path.empty())
             if (auto exact = soundgoodizerExact (state, data (path)))
@@ -1164,6 +1168,9 @@ std::optional<EffectSlot> effectFromFl (const std::string& pluginName, const std
             psfl::toParams (ps, slot.params);
             return slot;
         }
+    if (pluginName == "Hardcore") // the exact engine without the cabinet impulses (REA_rodada71)
+        if (auto exact = hardcore::fromFl (state, {}))
+            return exact;
     if (pluginName == "EQUO") // the exact engine (REA_rodada61); a flat parametric EQ otherwise
         if (const auto s = equofx::parse (state))
         {
@@ -1381,6 +1388,7 @@ std::vector<std::string> flPluginsForEffect (EffectKind kind)
         case EffectKind::fruityDelayBank: return { "Fruity Delay Bank" };
         case EffectKind::fruityMultiband: return { "Fruity Multiband Compressor" };
         case EffectKind::equo: return { "EQUO" };
+        case EffectKind::hardcore: return { "Hardcore" };
         case EffectKind::flPitchShifter: return { "Pitch Shifter" };
         default: return {};
     }
@@ -1402,6 +1410,9 @@ std::optional<FlParamMap> effectParamFromFl (const std::string& pluginName, int
         || (is ("Fruity Balance") && k >= 0 && k < flbasic::balanceParams)
         || (is ("Fruity Blood Overdrive") && k >= 0 && k < flbasic::bloodOverdriveParams))
         return FlParamMap { k, [] (float v) { return std::clamp (v, 0.0f, 1.0f); } };
+    // Hardcore's 50 parameters: FL sends 0…1 for all of them (the box types and the cabinet as raw numbers, REA_rodada71)
+    if (is ("Hardcore") && k >= 0 && k < hardcore::numParams)
+        return FlParamMap { k, [k] (float v) { return hardcore::toSlot (k, std::clamp (v, 0.0f, 1.0f)); } };
     // EQUO's five knobs (shift, mix, morph, smoothness, volume) over their ranges; band automation is not mapped
     if (is ("EQUO") && k >= 0 && k < 5)
         return FlParamMap { k, [] (float v) { return std::clamp (v, 0.0f, 1.0f); } };

+ 8 - 0
src/core/FlpImport.cpp

@@ -1,4 +1,5 @@
 #include "core/FlpImport.h"
+#include "core/HardcoreFx.h"
 #include "core/GrossBeat.h"
 #include "core/DrumSynthLive.h"
 #include "core/Gms.h"
@@ -122,6 +123,7 @@ std::optional<EffectKind> effectForFlPlugin (const std::string& name)
         { "Emphasis", EffectKind::limiter },          { "Low Lifter", EffectKind::parametricEq },
         { "Fruity Send", EffectKind::utility },       { "Transporter", EffectKind::utility },
         { "Vintage Phaser", EffectKind::vintagePhaser },     { "Fruity Squeeze", EffectKind::squeeze },
+        { "Hardcore", EffectKind::hardcore },
     };
 
     // old presets (FL 3) store the name with different casing ("Fruity delay 2")
@@ -1552,6 +1554,12 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
                  || (plugin == "Fruity Flangus" && fx.kind != EffectKind::fruityFlangus)
                  || (plugin == "Fruity Flanger" && fx.kind != EffectKind::fruityFlanger))
             ++options.report->droppedEffects[plugin + " (state not readable: approximated)"];
+        else if (plugin == "Hardcore" && fx.kind == EffectKind::hardcore
+                 && ! hardcore::hasCabinet (fx, (int) hardcore::fromSlot (hardcore::pCabinet, fx.params[(std::size_t) hardcore::pCabinet])))
+        {
+            if (hardcore::fromSlot (hardcore::pCabinet, fx.params[(std::size_t) hardcore::pCabinet]) > 0.0f)
+                ++options.report->droppedEffects["Hardcore (cabinet impulse not found: cabinet off)"];
+        }
     };
 
     for (const auto& insert : project.mixer)

+ 134 - 9
src/core/HardcoreFx.cpp

@@ -15,6 +15,9 @@
 #include <cstring>
 #include <optional>
 
+#include <cpuid.h>
+#include <immintrin.h>
+
 #if defined(__clang__)
 #pragma clang fp contract(off)
 #elif defined(__GNUC__)
@@ -37,6 +40,8 @@ struct HcCrt
     static float sinf (float x) noexcept { return ildsp::sinf_ (x); }
     static float cosf (float x) noexcept { return ildsp::cosf_ (x); }
     static void sincosf (float x, float& s, float& c) noexcept { ildsp::sincosf_ (x, s, c); }
+    static float expf (float x) noexcept { return ildsp::expf_ (x); }
+    static float tanf (float x) noexcept { return tanfCrt (x); } // no FMA path in this routine
 };
 using LpBiquad = LpBiquadT<HcCrt>;
 using EqBand = EqBandT<HcCrt>;
@@ -776,6 +781,7 @@ struct Phaser final : PedalFx
         for (int k = 0; k < 6; ++k)
             sL[k] = sR[k] = 0.0f;
         fbL = fbR = 0.0f;
+        ph = 0.0f; // the plug-in clears the LFO phase with the right channel's feedback (one 8-byte store)
         sfrq = smix = -1.0f;
     }
     void setParam (int k, float v) noexcept override
@@ -835,13 +841,37 @@ struct Phaser final : PedalFx
     }
 };
 
-// type 5: not decoded yet — passes the signal
+// type 5: the plate reverb of Toxic Biohazard's rack (class fxReverb) driven by three knobs (FUN_18002dfc0 …)
 struct ReverbPedal final : PedalFx
 {
-    void setRate (double) override {}
-    void reset() noexcept override {}
-    void setParam (int, float) noexcept override {}
-    void process (float*, float*, int) noexcept override {}
+    ReverbT<HcCrt> rev;
+
+    ReverbPedal()
+    {
+        rev.allTaps = true;
+        rev.construct();
+    }
+    void setRate (double fs) override
+    {
+        rev.setRate ((float) fs);
+        reset();
+    }
+    void reset() noexcept override
+    {
+        rev.reset();
+        rev.setp (2, 1.0f);
+        rev.setp (5, 1.0f);
+    }
+    void setParam (int k, float v) noexcept override
+    {
+        if (k == 0)
+            rev.setp (8, (float) ((double) ((v * v) * v) * 0.59999999999999998));
+        else if (k == 1)
+            rev.setp (9, std::fabs (1.0f - v));
+        else if (k == 2)
+            rev.setp (12, (float) ((double) (v * 0.999000013f) + 0.001));
+    }
+    void process (float* L, float* R, int n) noexcept override { rev.process (L, R, n); }
 };
 
 std::unique_ptr<PedalFx> makePedal (int type)
@@ -864,6 +894,41 @@ std::unique_ptr<PedalFx> makePedal (int type)
 }
 
 // ------------------------------------------------------------------------------------------------ cabinet
+// acc[j] += x·h[j] (a product then a sum, as the plug-in's SSE loop: any vector width gives the same floats)
+bool cpuHasAvx()
+{
+    static const bool f = [] {
+        unsigned a = 0, b = 0, c = 0, d = 0;
+        if (! __get_cpuid (1, &a, &b, &c, &d))
+            return false;
+        if ((c & (1u << 27)) == 0 || (c & (1u << 28)) == 0)
+            return false;
+        unsigned lo = 0, hi = 0;
+        asm volatile ("xgetbv" : "=a"(lo), "=d"(hi) : "c"(0));
+        return (lo & 6u) == 6u;
+    }();
+    return f;
+}
+__attribute__ ((target ("avx"))) void macAvx (float* acc, const float* h, float x, std::size_t n) noexcept
+{
+    const auto vx = _mm256_set1_ps (x);
+    std::size_t j = 0;
+    for (; j + 8 <= n; j += 8)
+        _mm256_storeu_ps (acc + j, _mm256_add_ps (_mm256_mul_ps (vx, _mm256_loadu_ps (h + j)), _mm256_loadu_ps (acc + j)));
+    for (; j < n; ++j)
+        acc[j] = x * h[j] + acc[j];
+}
+void mac (float* acc, const float* h, float x, std::size_t n) noexcept
+{
+    if (cpuHasAvx())
+    {
+        macAvx (acc, h, x, n);
+        return;
+    }
+    for (std::size_t j = 0; j < n; ++j)
+        acc[j] = x * h[j] + acc[j];
+}
+
 // impulse resampled to the rate by linear interpolation, ×0.2, run as a direct convolution whose sums add the oldest
 // input first (FUN_180026f00 / FUN_180027260)
 // the plug-in's RIFF/WAVE reader (FUN_18001c890): integer PCM 16/24/32 bits or float32, planar; its integer scales are
@@ -1019,10 +1084,8 @@ struct Cabinet
             float* ar = accR.data() + pos;
             const float* h0 = hl.data();
             const float* h1 = hr.data();
-            for (std::size_t j = 0; j < T; ++j)
-                al[j] = xl * h0[j] + al[j];
-            for (std::size_t j = 0; j < T; ++j)
-                ar[j] = xr * h1[j] + ar[j];
+            mac (al, h0, xl, T);
+            mac (ar, h1, xr, T);
             L[i] = al[0];
             R[i] = ar[0];
             ++pos;
@@ -1430,4 +1493,66 @@ private:
 } // namespace
 
 std::unique_ptr<Effect> make (const EffectSlot& slot) { return std::make_unique<HardcoreEffect> (slot.state); }
+
+const EffectInfo& info()
+{
+    static const std::vector<std::string> names = [] {
+        std::vector<std::string> n;
+        for (int i = 0; i < numParams; ++i)
+            n.push_back (paramName (i));
+        return n;
+    }();
+    static const EffectInfo i = [] {
+        EffectInfo e { "Hardcore", {} };
+        const auto d = defaultValues();
+        for (int k = 0; k < numParams; ++k)
+            e.params.push_back ({ names[(std::size_t) k].c_str(), toSlot (k, d[(std::size_t) k]) });
+        return e;
+    }();
+    return i;
+}
+
+std::vector<std::uint8_t> packCabinets (const std::vector<std::pair<int, std::vector<std::uint8_t>>>& files)
+{
+    std::vector<std::uint8_t> out { 'L', 'X', 'H', 'C' };
+    auto put = [&] (std::uint32_t x) {
+        for (int b = 0; b < 4; ++b)
+            out.push_back ((std::uint8_t) (x >> (8 * b)));
+    };
+    put ((std::uint32_t) files.size());
+    for (const auto& [idx, bytes] : files)
+    {
+        put ((std::uint32_t) idx);
+        put ((std::uint32_t) bytes.size());
+        out.insert (out.end(), bytes.begin(), bytes.end());
+    }
+    return out;
+}
+
+bool hasCabinet (const EffectSlot& slot, int cabinet)
+{
+    for (const auto& f : unpackFiles (slot.state))
+        if (f.first == cabinet && ! f.second.empty())
+            return true;
+    return false;
+}
+
+std::optional<EffectSlot> fromFl (const std::vector<std::uint8_t>& state, const FileReader& read)
+{
+    const auto s = parse (state);
+    if (! s)
+        return std::nullopt;
+    EffectSlot slot;
+    slot.kind = EffectKind::hardcore;
+    toParams (*s, slot.params);
+    // every impulse of the installation travels with the slot (about 290 kB) so the cabinet stays switchable
+    std::vector<std::pair<int, std::vector<std::uint8_t>>> files;
+    if (read)
+        for (int c = 1; c <= numCabinets; ++c)
+            if (auto b = read (cabinetPath (c)); ! b.empty() && readWav (b))
+                files.emplace_back (c, std::move (b));
+    if (! files.empty())
+        slot.state = packCabinets (files);
+    return slot;
+}
 } // namespace lynx::hardcore

+ 12 - 0
src/core/HardcoreFx.h

@@ -13,6 +13,7 @@
 
 #include <array>
 #include <cstdint>
+#include <functional>
 #include <memory>
 #include <optional>
 #include <string>
@@ -23,6 +24,7 @@
 namespace lynx
 {
 class Effect;
+struct EffectInfo;
 }
 
 namespace lynx::hardcore
@@ -86,5 +88,15 @@ private:
     std::unique_ptr<Impl> impl;
 };
 
+// the slot's parameter list for the generic editor (FL's 50 parameters)
+const EffectInfo& info();
+// an imported slot from FL's state: params from the state, EffectSlot::state = the cabinet impulse files the reader
+// returns (relative path → bytes; empty reader = no cabinet). nullopt = not a Hardcore state
+using FileReader = std::function<std::vector<std::uint8_t> (const std::string& relativePath)>;
+std::optional<EffectSlot> fromFl (const std::vector<std::uint8_t>& state, const FileReader& read);
+// EffectSlot::state packing of cabinet files (index 1…20 → WAV bytes)
+std::vector<std::uint8_t> packCabinets (const std::vector<std::pair<int, std::vector<std::uint8_t>>>& files);
+bool hasCabinet (const EffectSlot& slot, int cabinet);
+
 std::unique_ptr<Effect> make (const EffectSlot& slot);
 } // namespace lynx::hardcore

+ 314 - 1
src/core/IlFxKit.h

@@ -75,7 +75,7 @@ struct CrtTables
             exp2[(std::size_t) i] = std::exp2 (i / 64.0);
     }
 };
-const CrtTables& crt()
+inline const CrtTables& crt()
 {
     static const CrtTables t;
     return t;
@@ -292,6 +292,8 @@ struct PlainCrt
     static float sinf (float x) noexcept { return sinfCrt (x); }
     static float cosf (float x) noexcept { return cosfCrt (x); }
     static void sincosf (float x, float& s, float& c) noexcept { sinCosK (x, s, c); }
+    static float expf (float x) noexcept { return expfCrt (x); }
+    static float tanf (float x) noexcept { return tanfCrt (x); }
 };
 
 // low-pass biquad of the lo-fi effect (FUN_18001c3a0 design, skipped when unchanged; FUN_18001c4a0 tick)
@@ -591,6 +593,317 @@ struct EqBandT
         return y;
     }
 };
+
+// ------------------------------------------------------------------------------------------------ reverb
+// class fxReverb (the plate of GMS's reverb slot, REA_rodada39 §1.13) with its early-reflection tap active, processing
+// in place (REA_rodada45 §FX.5; Hardcore's reverb pedal is the same class, REA_rodada71).
+template <class Crt>
+struct ReverbT
+{
+    static constexpr double qa[18][2] = { { 421.0, -360.5 }, { 2981.0, 19.5 }, { 216.0, 5.5 }, { 250.0, 0.5 }, { 99.0, 1.5 }, { 100.0, 0.5 },
+                                          { 28.0, 2.5 }, { 1975.0, 25.5 }, { 199.0, 1.5 }, { 216.0, 5.5 }, { 421.0, -360.5 }, { 421.0, -360.5 },
+                                          { 421.0, -360.5 }, { 200.0, 0.5 }, { 1.0, 0.5 }, { 1.0, 0.5 }, { 1.0, 0.5 }, { 1.0, 0.5 } };
+    static constexpr int lines[12] = { 142, 107, 379, 277, 672, 4453, 1800, 3720, 908, 4217, 2656, 3163 };
+    static constexpr int taps0[14] = { 266, 2974, 1913, 2496, 1690, 187, 1566, 353, 3627, 1728, 3173, 1811, 335, 621 };
+    static constexpr int erTapL = 1102, erTapR = 837; // first entries of the early-reflection tables (the only taps with gain ≠ 0)
+    // the whole early-reflection tables (Hardcore's build gives every tap a gain and sums 7 left / 8 right taps)
+    static constexpr int erTabL[8] = { 1102, 2904, 3784, 4873, 5878, 7470, 9062, 9263 };
+    static constexpr int erTabR[8] = { 837, 1423, 2865, 3938, 5278, 5978, 7532, 9263 };
+    bool allTaps = false;
+    int erTL[8] {}, erTR[8] {};
+    float erGL[8] {}, erGR[8] {};
+    static constexpr float tiny = 1e-30f;
+
+    float fs = 44100.0f;
+    int pi[18] {};
+    std::vector<float> buf[12], pre, er;
+    int len[12] {}, pos[12] {}, prepos = 0, prelen = 1, lastsize = 0, erSize = 2, erPos = 0, erTl = 0, erTr = 0;
+    int taps[14] {};
+    bool dirty = true;
+    float lp = 0, hpx = 0, hpy = 0, dL0 = 0, dL1 = 0, dR0 = 0, dR1 = 0, tL = 0, tR = 0, lev = -1000.0f;
+    float gin = 0, hpk = 0, lpk = 1, ap1 = 0, ap2 = 0, tap1 = 0, tap2 = 0, decay = 0, shelf = 0, shk = 0, damp = 1, dry = 0;
+    float erLev = 0, tank = 0, erGl = 0, erGr = 0;
+
+    static int floorI (float x) noexcept
+    {
+        auto i = (int) x;
+        if ((double) i != (double) x && x < 0.0f)
+            --i;
+        return i;
+    }
+    static int cdiv (long long a, long long b) noexcept { return (int) (a / b); }
+    static float db (int i) noexcept // FUN_18002c200
+    {
+        if (i <= -361)
+            return 0.0f;
+        return Crt::powf (10.0f, (float) i * 0.004999999888241291f);
+    }
+
+    void construct()
+    {
+        static constexpr float preset[18] = { 0.8574821949005127f, 0.018785642459988594f, 0.16203702986240387f, 0.0f, 0.49494948983192444f, 1.0f,
+                                              0.2857142984867096f, 0.2405063360929489f, 0.07035175710916519f, 0.16203702986240387f,
+                                              0.8574821949005127f, 0.7743467688560486f, 0.5724465847015381f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f };
+        lastsize = 0;
+        setRate (44100.0f);
+        for (int i = 0; i < 18; ++i)
+            setp (i, preset[i]);
+        reset();
+    }
+    void setRate (float rate) // FUN_18002a7d0 / FUN_18002a7e0
+    {
+        fs = rate;
+        const auto fsi = (int) fs;
+        for (int k = 0; k < 12; ++k)
+        {
+            const auto n = cdiv ((long long) fsi * lines[k], 20000);
+            buf[k].assign ((std::size_t) std::max (1, n), tiny);
+            len[k] = std::max (1, n);
+            pos[k] = 0;
+        }
+        prelen = cdiv ((long long) fsi * 250, 1000);
+        pre.assign ((std::size_t) std::max (1, prelen), tiny);
+        prelen = std::max (1, prelen);
+        prepos = 0;
+        auto u = (unsigned) (fsi * 0.31632653061224492);
+        int bitsN = 0;
+        while (u != 0)
+            ++bitsN, u >>= 1;
+        erSize = 1 << (bitsN + 1);
+        er.assign ((std::size_t) erSize, tiny);
+        erPos = 0;
+        for (int t = 0; t < 14; ++t)
+            taps[t] = cdiv ((long long) fsi * taps0[t], 20000);
+    }
+    void setp (int i, float v) noexcept // FUN_18002b380
+    {
+        const auto b = (float) qa[i][1];
+        const auto x = b >= 0.0f ? v * (float) qa[i][0] + b : v * (float) qa[i][0] - (-b);
+        pi[i] = floorI (x);
+        dirty = true;
+    }
+    void reset() noexcept // FUN_18002b170 (positions are kept)
+    {
+        for (auto& b : buf)
+            std::fill (b.begin(), b.end(), tiny);
+        std::fill (pre.begin(), pre.end(), tiny);
+        std::fill (er.begin(), er.end(), tiny);
+        lp = hpx = hpy = 0.0f;
+        dL0 = dL1 = dR0 = dR1 = 0.0f;
+        tL = tR = 0.0f;
+        lev = -1000.0f;
+    }
+    float onePole (int p) const noexcept
+    {
+        if ((float) p < 221.0f)
+        {
+            const auto c = Crt::cosf (((float) p * 628.3185424804688f) / fs);
+            const auto t = 2.0f - c;
+            const auto s = std::sqrt ((t * t) - 1.0f);
+            return 1.0f - (t - s);
+        }
+        return 1.0f;
+    }
+    void recalc() noexcept // FUN_18002c230
+    {
+        const auto fsi = (int) fs;
+        const auto* p = pi;
+        const auto one = 1.0f;
+        gin = p[14] == 0 ? db (p[0]) : 0.0f;
+        if ((float) p[1] > 19.0f)
+        {
+            const auto x = (std::min (fs * 0.5f, (float) p[1]) * 3.1415927410125732f) / fs;
+            const auto e = Crt::tanf (x);
+            hpk = (e - one) / (e + one);
+        }
+        else
+            hpk = 0.0f;
+        lpk = onePole (p[2]);
+        prelen = std::max (1, cdiv ((long long) fsi * p[3], 1000));
+        prelen = std::min (prelen, (int) pre.size());
+        prepos %= prelen;
+        const auto base = cdiv ((long long) (p[4] + 15) * fsi, 115);
+        for (int k = 0; k < 12; ++k)
+        {
+            len[k] = std::max (1, cdiv ((long long) base * lines[k], 20000));
+            len[k] = std::min (len[k], (int) buf[k].size());
+            pos[k] %= len[k];
+        }
+        for (int t = 0; t < 14; ++t)
+            taps[t] = cdiv ((long long) base * taps0[t], 20000);
+        const auto sc = (float) cdiv ((long long) (p[4] + 3) * fsi, 103);
+        erTl = (int) (((float) erTapL * 3.4013603e-05f) * sc);
+        erTr = (int) (((float) erTapR * 3.4013603e-05f) * sc);
+        const auto m = erTl < erTr ? (float) erTl : (float) erTr;
+        erGl = (m * 0.5f) / (float) erTl;
+        if (allTaps)
+            for (int k = 0; k < 8; ++k)
+            {
+                erTL[k] = (int) (((float) erTabL[k] * 3.4013603e-05f) * sc);
+                erTR[k] = (int) (((float) erTabR[k] * 3.4013603e-05f) * sc);
+                erGL[k] = (m * 0.5f) / (float) erTL[k];
+                erGR[k] = (m * 0.36000001430511475f) / (float) erTR[k];
+            }
+        erGr = (m * 0.36000001430511475f) / (float) erTr;
+        if (p[4] != lastsize)
+        {
+            lastsize = p[4];
+            for (int k = 0; k < 12; ++k)
+                std::fill (buf[k].begin(), buf[k].begin() + len[k], 0.0f);
+            std::fill (er.begin(), er.end(), 0.0f);
+        }
+        const auto diff = (float) p[5] * 0.01f;
+        const auto inv = one / fs;
+        if (diff != 0.0f)
+        {
+            ap1 = Crt::expf (((float) (len[0] + len[1]) * (-49.34111022949219f / diff)) * inv);
+            ap2 = Crt::expf (((-31.398887634277344f / diff) * (float) (len[2] + len[3])) * inv);
+            auto x = (((float) (len[4] + len[8]) * -3.4538776874542236f) / fs) * (2.857142925262451f / diff);
+            tap1 = Crt::expf (x);
+            x = ((-3.4538776874542236f / fs) * (float) (len[6] + len[10])) * (1.9607843160629272f / diff);
+            tap2 = Crt::expf (x);
+        }
+        else
+            ap1 = ap2 = tap1 = tap2 = 0.0f;
+        const auto tsum = ((float) (len[9] + len[7] + len[5] + len[11]) / fs) * -6.907755374908447f;
+        const auto t60 = (float) p[8] * 0.10000000149011612f;
+        decay = Crt::powf (Crt::expf (tsum / t60), 0.25f);
+        auto rr = Crt::powf (Crt::expf ((10.0f / ((float) p[6] * t60)) * tsum), 0.25f);
+        rr = rr / decay;
+        shelf = (rr - one) * 0.5f;
+        const auto rm = std::min (rr, one);
+        const auto e = Crt::tanf (((float) p[7] * 3.1415927410125732f) / fs);
+        shk = (e - rm) / (rm + e);
+        damp = onePole (p[9]);
+        dry = p[15] == 0 ? db (p[10]) : 0.0f;
+        erLev = p[16] == 0 ? db (p[11]) * 0.5f : 0.0f;
+        tank = p[17] == 0 ? db (p[12]) * 0.30000001192092896f : 0.0f;
+        dirty = false;
+    }
+    float ap (int k, float x, float c1, float c2) noexcept
+    {
+        auto& b = buf[k];
+        const auto i = pos[k];
+        const auto t = b[(std::size_t) i] - (c1 * x);
+        b[(std::size_t) i] = (c2 * t) + x;
+        pos[k] = i > 0 ? i - 1 : len[k] - 1;
+        return t;
+    }
+    static int wrap (int i, int n) noexcept { return i >= n ? i - n : i; }
+    void process (float* outL, float* outR, int n) noexcept // FUN_18002dda0, in place
+    {
+        if (dirty)
+            recalc();
+        const auto d = decay, one = 1.0f, half = 0.5f, dd = one - d;
+        const auto g41 = (dd * 0.6000000238418579f) + d, g42 = (dd * 0.25f) + d, g43 = (dd * 0.699999988079071f) + d;
+        const auto g56 = (dd * 0.20000000298023224f) + d, g44 = (dd * half) + d;
+        const auto width = (float) pi[13] * 0.009999999776482582f;
+        const auto erm = erSize - 1;
+        auto* B = buf;
+        auto* L = len;
+        auto* P = pos;
+        const auto* T = taps;
+        for (int s = 0; s < n; ++s)
+        {
+            const auto xl = gin * outL[s], xr = gin * outR[s];
+            const auto m = ((xr + xl) * half) + tiny;
+            auto l = ((m - lp) * lpk) + lp;
+            lp = l;
+            const auto h = ((l - hpx) * hpk) + hpy;
+            hpy = l;
+            hpx = h;
+            if (hpk != 0.0f)
+                l = ((l - h) * half) + tiny;
+            float erl = 0.0f, err = 0.0f;
+            if (erLev != 0.0f)
+            {
+                if (allTaps)
+                {
+                    auto e = [&] (int tap) { return er[(std::size_t) ((tap + erPos) & erm)]; };
+                    erl = e (erTL[0]) * erGL[0] + e (erTL[1]) * erGL[1];
+                    erl = erl - e (erTL[2]) * erGL[2];
+                    erl = e (erTL[3]) * erGL[3] + erl;
+                    erl = erl + e (erTL[4]) * erGL[4];
+                    erl = erl + e (erTL[5]) * erGL[5];
+                    erl = erl + e (erTL[6]) * erGL[6];
+                    err = e (erTR[0]) * erGR[0] - e (erTR[1]) * erGR[1];
+                    err = err + e (erTR[2]) * erGR[2];
+                    err = err + e (erTR[3]) * erGR[3];
+                    err = err - e (erTR[4]) * erGR[4];
+                    err = err + e (erTR[5]) * erGR[5];
+                    err = err + e (erTR[6]) * erGR[6];
+                    err = err - e (erTR[7]) * erGR[7];
+                }
+                else
+                {
+                    erl = er[(std::size_t) ((erTl + erPos) & erm)] * erGl;
+                    err = er[(std::size_t) ((erTr + erPos) & erm)] * erGr;
+                }
+            }
+            auto t = ap (0, l, ap1, ap1);
+            auto u = ap (1, t, ap2, ap1);
+            er[(std::size_t) erPos] = t;
+            erPos = erPos > 0 ? erPos - 1 : erm;
+            t = ap (2, u, ap1, ap1);
+            u = ap (3, t, ap2, ap1);
+            const auto pv = pre[(std::size_t) prepos];
+            pre[(std::size_t) prepos] = u;
+            prepos = prepos > 0 ? prepos - 1 : prelen - 1;
+            const auto tin = pv + 9.99999968e-21f;
+            auto v = B[11][(std::size_t) P[11]] * d;
+            auto s2 = ((v - dL1) * shk) + dL0;
+            dL0 = v, dL1 = s2;
+            auto w = (((((s2 + v) * shelf) + v) + tin) - tL) * damp;
+            w = w + tL;
+            tL = w;
+            u = ap (4, w, tap1, tap1);
+            auto i = P[5];
+            auto o = B[5][(std::size_t) i];
+            B[5][(std::size_t) i] = u;
+            P[5] = i > 0 ? i - 1 : L[5] - 1;
+            o = o * d;
+            u = ap (6, o, tap2, tap2);
+            i = P[7];
+            B[7][(std::size_t) i] = u;
+            i = i > 0 ? i - 1 : L[7] - 1;
+            P[7] = i;
+            v = B[7][(std::size_t) i] * d;
+            s2 = ((v - dR1) * shk) + dR0;
+            dR0 = v, dR1 = s2;
+            w = (((((s2 + v) * shelf) + v) + tin) - tR) * damp;
+            w = w + tR;
+            tR = w;
+            u = ap (8, w, tap1, tap1);
+            i = P[9];
+            o = B[9][(std::size_t) i];
+            B[9][(std::size_t) i] = u;
+            P[9] = i > 0 ? i - 1 : L[9] - 1;
+            o = o * d;
+            u = ap (10, o, tap2, tap2);
+            i = P[11];
+            B[11][(std::size_t) i] = u;
+            P[11] = i > 0 ? i - 1 : L[11] - 1;
+            auto at = [&] (int line, int tap) { return B[line][(std::size_t) wrap (tap + P[line], L[line])]; };
+            const auto fA = at (9, T[0]), fB = at (9, T[1]), fC = at (10, T[2]), fD = at (11, T[3]);
+            const auto fE = at (5, T[4]), fF = at (6, T[5]), fG = at (7, T[6]);
+            const auto f7 = at (5, T[8]), f8 = at (5, T[7]), f9 = at (6, T[9]), f10 = at (7, T[10]), f11 = at (9, T[11]);
+            const auto f12 = at (10, T[12]), f13 = at (11, T[13]);
+            auto tl = (((fA - (g42 * fB)) - (g43 * fC)) - (g56 * fD)) + (g41 * fE);
+            tl = (tl + fF) + (g44 * fG);
+            auto tr = ((((g42 * f7) + f8) - (g43 * f9)) - (g56 * f10)) - (g41 * f11);
+            tr = (tr + f12) + (g44 * f13);
+            if (lev < -99.0f)
+                lev = tank;
+            lev = ((tank - lev) * 0.0010000000474974513f) + lev;
+            const auto a = (lev * tl) + (erLev * erl), b = (lev * tr) + (erLev * err);
+            const auto sm = b + a, df = (a - b) * width;
+            outL[s] = (xl * dry) + (df + sm);
+            outR[s] = (xr * dry) + (sm - df);
+        }
+    }
+};
+
 using LpBiquad = LpBiquadT<PlainCrt>;
+using Reverb = ReverbT<PlainCrt>;
 using EqBand = EqBandT<PlainCrt>;
 } // namespace lynx::ilfx

+ 2 - 1
src/core/Song.h

@@ -331,7 +331,8 @@ enum class EffectKind : std::uint8_t
     convolver,    // FL's Fruity Convolver, exact (REA_rodada60, core/ConvolverFx.h): FL's 4 controls as (raw − min) / range; impulse response, knobs and envelopes in EffectSlot::state
     equo,         // FL's EQUO, exact (REA_rodada61, core/EquoFx.h): FL's state in EffectSlot::state, knobs (raw − min) / range
     flPitchShifter, // FL's Pitch Shifter, exact (REA_rodada61, core/PitchShifterFl.h): FL's 13 knobs (raw − min) / range + 3 options
-    frequencySplitter // FL's Frequency Splitter, exact (REA_rodada62, core/FrequencySplitter.h): 26 engine values + output bands
+    frequencySplitter, // FL's Frequency Splitter, exact (REA_rodada62, core/FrequencySplitter.h): 26 engine values + output bands
+    hardcore      // FL's Hardcore, exact (REA_rodada71, core/HardcoreFx.h): FL's 50 parameters (cabinet / 20, types / 11); impulses in EffectSlot::state
 };
 
 constexpr int maxEffectParams = 64; // LuxeVerb uses 53 (FL's 49 controls + 4 sync switches)

+ 0 - 274
src/core/ToxicFx.cpp

@@ -28,280 +28,6 @@ constexpr float th5 = 9.99999975e-06f; // 1e-5f
 constexpr float fade = 0.004999999888241291f;
 using namespace ilfx;
 
-// ------------------------------------------------------------------------------------------------ reverb
-// class fxReverb (the plate of GMS's reverb slot, REA_rodada39 §1.13) with its early-reflection tap active, processing
-// in place (REA_rodada45 §FX.5).
-struct Reverb
-{
-    static constexpr double qa[18][2] = { { 421.0, -360.5 }, { 2981.0, 19.5 }, { 216.0, 5.5 }, { 250.0, 0.5 }, { 99.0, 1.5 }, { 100.0, 0.5 },
-                                          { 28.0, 2.5 }, { 1975.0, 25.5 }, { 199.0, 1.5 }, { 216.0, 5.5 }, { 421.0, -360.5 }, { 421.0, -360.5 },
-                                          { 421.0, -360.5 }, { 200.0, 0.5 }, { 1.0, 0.5 }, { 1.0, 0.5 }, { 1.0, 0.5 }, { 1.0, 0.5 } };
-    static constexpr int lines[12] = { 142, 107, 379, 277, 672, 4453, 1800, 3720, 908, 4217, 2656, 3163 };
-    static constexpr int taps0[14] = { 266, 2974, 1913, 2496, 1690, 187, 1566, 353, 3627, 1728, 3173, 1811, 335, 621 };
-    static constexpr int erTapL = 1102, erTapR = 837; // first entries of the early-reflection tables (the only taps with gain ≠ 0)
-    static constexpr float tiny = 1e-30f;
-
-    float fs = 44100.0f;
-    int pi[18] {};
-    std::vector<float> buf[12], pre, er;
-    int len[12] {}, pos[12] {}, prepos = 0, prelen = 1, lastsize = 0, erSize = 2, erPos = 0, erTl = 0, erTr = 0;
-    int taps[14] {};
-    bool dirty = true;
-    float lp = 0, hpx = 0, hpy = 0, dL0 = 0, dL1 = 0, dR0 = 0, dR1 = 0, tL = 0, tR = 0, lev = -1000.0f;
-    float gin = 0, hpk = 0, lpk = 1, ap1 = 0, ap2 = 0, tap1 = 0, tap2 = 0, decay = 0, shelf = 0, shk = 0, damp = 1, dry = 0;
-    float erLev = 0, tank = 0, erGl = 0, erGr = 0;
-
-    static int floorI (float x) noexcept
-    {
-        auto i = (int) x;
-        if ((double) i != (double) x && x < 0.0f)
-            --i;
-        return i;
-    }
-    static int cdiv (long long a, long long b) noexcept { return (int) (a / b); }
-    static float db (int i) noexcept // FUN_18002c200
-    {
-        if (i <= -361)
-            return 0.0f;
-        return powfCrt (10.0f, (float) i * 0.004999999888241291f);
-    }
-
-    void construct()
-    {
-        static constexpr float preset[18] = { 0.8574821949005127f, 0.018785642459988594f, 0.16203702986240387f, 0.0f, 0.49494948983192444f, 1.0f,
-                                              0.2857142984867096f, 0.2405063360929489f, 0.07035175710916519f, 0.16203702986240387f,
-                                              0.8574821949005127f, 0.7743467688560486f, 0.5724465847015381f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f };
-        lastsize = 0;
-        setRate (44100.0f);
-        for (int i = 0; i < 18; ++i)
-            setp (i, preset[i]);
-        reset();
-    }
-    void setRate (float rate) // FUN_18002a7d0 / FUN_18002a7e0
-    {
-        fs = rate;
-        const auto fsi = (int) fs;
-        for (int k = 0; k < 12; ++k)
-        {
-            const auto n = cdiv ((long long) fsi * lines[k], 20000);
-            buf[k].assign ((std::size_t) std::max (1, n), tiny);
-            len[k] = std::max (1, n);
-            pos[k] = 0;
-        }
-        prelen = cdiv ((long long) fsi * 250, 1000);
-        pre.assign ((std::size_t) std::max (1, prelen), tiny);
-        prelen = std::max (1, prelen);
-        prepos = 0;
-        auto u = (unsigned) (fsi * 0.31632653061224492);
-        int bitsN = 0;
-        while (u != 0)
-            ++bitsN, u >>= 1;
-        erSize = 1 << (bitsN + 1);
-        er.assign ((std::size_t) erSize, tiny);
-        erPos = 0;
-        for (int t = 0; t < 14; ++t)
-            taps[t] = cdiv ((long long) fsi * taps0[t], 20000);
-    }
-    void setp (int i, float v) noexcept // FUN_18002b380
-    {
-        const auto b = (float) qa[i][1];
-        const auto x = b >= 0.0f ? v * (float) qa[i][0] + b : v * (float) qa[i][0] - (-b);
-        pi[i] = floorI (x);
-        dirty = true;
-    }
-    void reset() noexcept // FUN_18002b170 (positions are kept)
-    {
-        for (auto& b : buf)
-            std::fill (b.begin(), b.end(), tiny);
-        std::fill (pre.begin(), pre.end(), tiny);
-        std::fill (er.begin(), er.end(), tiny);
-        lp = hpx = hpy = 0.0f;
-        dL0 = dL1 = dR0 = dR1 = 0.0f;
-        tL = tR = 0.0f;
-        lev = -1000.0f;
-    }
-    float onePole (int p) const noexcept
-    {
-        if ((float) p < 221.0f)
-        {
-            const auto c = cosfCrt (((float) p * 628.3185424804688f) / fs);
-            const auto t = 2.0f - c;
-            const auto s = std::sqrt ((t * t) - 1.0f);
-            return 1.0f - (t - s);
-        }
-        return 1.0f;
-    }
-    void recalc() noexcept // FUN_18002c230
-    {
-        const auto fsi = (int) fs;
-        const auto* p = pi;
-        const auto one = 1.0f;
-        gin = p[14] == 0 ? db (p[0]) : 0.0f;
-        if ((float) p[1] > 19.0f)
-        {
-            const auto x = (std::min (fs * 0.5f, (float) p[1]) * 3.1415927410125732f) / fs;
-            const auto e = tanfCrt (x);
-            hpk = (e - one) / (e + one);
-        }
-        else
-            hpk = 0.0f;
-        lpk = onePole (p[2]);
-        prelen = std::max (1, cdiv ((long long) fsi * p[3], 1000));
-        prelen = std::min (prelen, (int) pre.size());
-        prepos %= prelen;
-        const auto base = cdiv ((long long) (p[4] + 15) * fsi, 115);
-        for (int k = 0; k < 12; ++k)
-        {
-            len[k] = std::max (1, cdiv ((long long) base * lines[k], 20000));
-            len[k] = std::min (len[k], (int) buf[k].size());
-            pos[k] %= len[k];
-        }
-        for (int t = 0; t < 14; ++t)
-            taps[t] = cdiv ((long long) base * taps0[t], 20000);
-        const auto sc = (float) cdiv ((long long) (p[4] + 3) * fsi, 103);
-        erTl = (int) (((float) erTapL * 3.4013603e-05f) * sc);
-        erTr = (int) (((float) erTapR * 3.4013603e-05f) * sc);
-        const auto m = erTl < erTr ? (float) erTl : (float) erTr;
-        erGl = (m * 0.5f) / (float) erTl;
-        erGr = (m * 0.36000001430511475f) / (float) erTr;
-        if (p[4] != lastsize)
-        {
-            lastsize = p[4];
-            for (int k = 0; k < 12; ++k)
-                std::fill (buf[k].begin(), buf[k].begin() + len[k], 0.0f);
-            std::fill (er.begin(), er.end(), 0.0f);
-        }
-        const auto diff = (float) p[5] * 0.01f;
-        const auto inv = one / fs;
-        if (diff != 0.0f)
-        {
-            ap1 = expfCrt (((float) (len[0] + len[1]) * (-49.34111022949219f / diff)) * inv);
-            ap2 = expfCrt (((-31.398887634277344f / diff) * (float) (len[2] + len[3])) * inv);
-            auto x = (((float) (len[4] + len[8]) * -3.4538776874542236f) / fs) * (2.857142925262451f / diff);
-            tap1 = expfCrt (x);
-            x = ((-3.4538776874542236f / fs) * (float) (len[6] + len[10])) * (1.9607843160629272f / diff);
-            tap2 = expfCrt (x);
-        }
-        else
-            ap1 = ap2 = tap1 = tap2 = 0.0f;
-        const auto tsum = ((float) (len[9] + len[7] + len[5] + len[11]) / fs) * -6.907755374908447f;
-        const auto t60 = (float) p[8] * 0.10000000149011612f;
-        decay = powfCrt (expfCrt (tsum / t60), 0.25f);
-        auto rr = powfCrt (expfCrt ((10.0f / ((float) p[6] * t60)) * tsum), 0.25f);
-        rr = rr / decay;
-        shelf = (rr - one) * 0.5f;
-        const auto rm = std::min (rr, one);
-        const auto e = tanfCrt (((float) p[7] * 3.1415927410125732f) / fs);
-        shk = (e - rm) / (rm + e);
-        damp = onePole (p[9]);
-        dry = p[15] == 0 ? db (p[10]) : 0.0f;
-        erLev = p[16] == 0 ? db (p[11]) * 0.5f : 0.0f;
-        tank = p[17] == 0 ? db (p[12]) * 0.30000001192092896f : 0.0f;
-        dirty = false;
-    }
-    float ap (int k, float x, float c1, float c2) noexcept
-    {
-        auto& b = buf[k];
-        const auto i = pos[k];
-        const auto t = b[(std::size_t) i] - (c1 * x);
-        b[(std::size_t) i] = (c2 * t) + x;
-        pos[k] = i > 0 ? i - 1 : len[k] - 1;
-        return t;
-    }
-    static int wrap (int i, int n) noexcept { return i >= n ? i - n : i; }
-    void process (float* outL, float* outR, int n) noexcept // FUN_18002dda0, in place
-    {
-        if (dirty)
-            recalc();
-        const auto d = decay, one = 1.0f, half = 0.5f, dd = one - d;
-        const auto g41 = (dd * 0.6000000238418579f) + d, g42 = (dd * 0.25f) + d, g43 = (dd * 0.699999988079071f) + d;
-        const auto g56 = (dd * 0.20000000298023224f) + d, g44 = (dd * half) + d;
-        const auto width = (float) pi[13] * 0.009999999776482582f;
-        const auto erm = erSize - 1;
-        auto* B = buf;
-        auto* L = len;
-        auto* P = pos;
-        const auto* T = taps;
-        for (int s = 0; s < n; ++s)
-        {
-            const auto xl = gin * outL[s], xr = gin * outR[s];
-            const auto m = ((xr + xl) * half) + tiny;
-            auto l = ((m - lp) * lpk) + lp;
-            lp = l;
-            const auto h = ((l - hpx) * hpk) + hpy;
-            hpy = l;
-            hpx = h;
-            if (hpk != 0.0f)
-                l = ((l - h) * half) + tiny;
-            float erl = 0.0f, err = 0.0f;
-            if (erLev != 0.0f)
-            {
-                erl = er[(std::size_t) ((erTl + erPos) & erm)] * erGl;
-                err = er[(std::size_t) ((erTr + erPos) & erm)] * erGr;
-            }
-            auto t = ap (0, l, ap1, ap1);
-            auto u = ap (1, t, ap2, ap1);
-            er[(std::size_t) erPos] = t;
-            erPos = erPos > 0 ? erPos - 1 : erm;
-            t = ap (2, u, ap1, ap1);
-            u = ap (3, t, ap2, ap1);
-            const auto pv = pre[(std::size_t) prepos];
-            pre[(std::size_t) prepos] = u;
-            prepos = prepos > 0 ? prepos - 1 : prelen - 1;
-            const auto tin = pv + 9.99999968e-21f;
-            auto v = B[11][(std::size_t) P[11]] * d;
-            auto s2 = ((v - dL1) * shk) + dL0;
-            dL0 = v, dL1 = s2;
-            auto w = (((((s2 + v) * shelf) + v) + tin) - tL) * damp;
-            w = w + tL;
-            tL = w;
-            u = ap (4, w, tap1, tap1);
-            auto i = P[5];
-            auto o = B[5][(std::size_t) i];
-            B[5][(std::size_t) i] = u;
-            P[5] = i > 0 ? i - 1 : L[5] - 1;
-            o = o * d;
-            u = ap (6, o, tap2, tap2);
-            i = P[7];
-            B[7][(std::size_t) i] = u;
-            i = i > 0 ? i - 1 : L[7] - 1;
-            P[7] = i;
-            v = B[7][(std::size_t) i] * d;
-            s2 = ((v - dR1) * shk) + dR0;
-            dR0 = v, dR1 = s2;
-            w = (((((s2 + v) * shelf) + v) + tin) - tR) * damp;
-            w = w + tR;
-            tR = w;
-            u = ap (8, w, tap1, tap1);
-            i = P[9];
-            o = B[9][(std::size_t) i];
-            B[9][(std::size_t) i] = u;
-            P[9] = i > 0 ? i - 1 : L[9] - 1;
-            o = o * d;
-            u = ap (10, o, tap2, tap2);
-            i = P[11];
-            B[11][(std::size_t) i] = u;
-            P[11] = i > 0 ? i - 1 : L[11] - 1;
-            auto at = [&] (int line, int tap) { return B[line][(std::size_t) wrap (tap + P[line], L[line])]; };
-            const auto fA = at (9, T[0]), fB = at (9, T[1]), fC = at (10, T[2]), fD = at (11, T[3]);
-            const auto fE = at (5, T[4]), fF = at (6, T[5]), fG = at (7, T[6]);
-            const auto f7 = at (5, T[8]), f8 = at (5, T[7]), f9 = at (6, T[9]), f10 = at (7, T[10]), f11 = at (9, T[11]);
-            const auto f12 = at (10, T[12]), f13 = at (11, T[13]);
-            auto tl = (((fA - (g42 * fB)) - (g43 * fC)) - (g56 * fD)) + (g41 * fE);
-            tl = (tl + fF) + (g44 * fG);
-            auto tr = ((((g42 * f7) + f8) - (g43 * f9)) - (g56 * f10)) - (g41 * f11);
-            tr = (tr + f12) + (g44 * f13);
-            if (lev < -99.0f)
-                lev = tank;
-            lev = ((tank - lev) * 0.0010000000474974513f) + lev;
-            const auto a = (lev * tl) + (erLev * erl), b = (lev * tr) + (erLev * err);
-            const auto sm = b + a, df = (a - b) * width;
-            outL[s] = (xl * dry) + (df + sm);
-            outR[s] = (xr * dry) + (sm - df);
-        }
-    }
-};
-
 // ------------------------------------------------------------------------------------------------ effect slot
 // one slot (REA_rodada45 §FX.2–FX.7): 0 delay, 1 chorus, 2 reverb, 3 flanger, 4 phaser, 5 lo-fi
 constexpr double syncFactor[10] = { 0.0, 0.066666666666666666, 0.033333333333333333, 0.022222222222222223, 0.016666666666666666,

+ 2 - 1
src/engine/ProjectFile.cpp

@@ -184,6 +184,7 @@ const char* effectId (EffectKind k)
         case EffectKind::equo: return "equo";
         case EffectKind::flPitchShifter: return "flPitchShifter";
         case EffectKind::frequencySplitter: return "frequencySplitter";
+        case EffectKind::hardcore: return "hardcore";
     }
     return "eq";
 }
@@ -332,7 +333,7 @@ std::optional<EffectKind> effectFromId (const juce::String& id)
                     EffectKind::fruityDelayBank, EffectKind::fruityMultiband,
                     EffectKind::fruityFastDist, EffectKind::fruityFlangus, EffectKind::fruityFlanger, EffectKind::luxeVerb, EffectKind::convolver,
                     EffectKind::equo, EffectKind::flPitchShifter,
-                    EffectKind::frequencySplitter })
+                    EffectKind::frequencySplitter, EffectKind::hardcore })
         if (id == effectId (k))
             return k;
 

+ 2 - 1
src/ui/MixerComponent.cpp

@@ -1388,7 +1388,8 @@ const EffectKind allEffects[] = { EffectKind::eq,     EffectKind::parametricEq,
                                       EffectKind::spreader, EffectKind::fruityChorus, EffectKind::hyperChorus, EffectKind::vintageChorus,
                                       EffectKind::fruityPanOMatic, EffectKind::fruityBalance, EffectKind::fruityBloodOverdrive,
                                       EffectKind::fruityDelayBank, EffectKind::fruityMultiband,
-                                      EffectKind::fruityFastDist, EffectKind::fruityFlangus, EffectKind::fruityFlanger, EffectKind::luxeVerb };
+                                      EffectKind::fruityFastDist, EffectKind::fruityFlangus, EffectKind::fruityFlanger, EffectKind::luxeVerb,
+                                      EffectKind::hardcore };
 } // namespace
 
 const std::vector<EffectKind>& addableEffects()

+ 129 - 0
tests/HardcoreTests.inc

@@ -0,0 +1,129 @@
+#include "core/HardcoreFx.h"
+
+// Hardcore, exact (REA_rodada71): goldens of Hardcore_x64.dll (the installation's plug-in, run unmodified) on states of
+// our own — 50 parameters from an LCG, the box types and switches set below — and this test's input, rendered with the
+// state before the rate, blocks of 512. Bit-identical. The cabinet cases read the installation's impulses (skipped
+// without it).
+namespace
+{
+std::vector<std::uint8_t> hardcoreTestState (std::uint32_t seed, std::array<int, 5> types, std::array<int, 5> on, int eq, int cab)
+{
+    std::array<float, 50> v {};
+    auto x = seed;
+    for (auto& f : v)
+    {
+        x = (x * 1103515245u + 12345u) & 0x7fffffffu;
+        f = (float) ((x >> 8) & 0x7fffffu) / 8388608.0f;
+    }
+    v[0] = 0.55f, v[1] = 0.45f, v[2] = (float) eq, v[11] = (float) cab;
+    v[12] = v[38] = v[44] = 0.5f;
+    for (int b = 0; b < 5; ++b)
+        v[(std::size_t) (39 + b)] = (float) on[(std::size_t) b], v[(std::size_t) (45 + b)] = (float) types[(std::size_t) b];
+    std::vector<std::uint8_t> s { 'S', 'S', 'L', 'F', 0xcc, 0x01, 0, 0, '1', 'R', 'C', 'H' };
+    const auto* p = (const std::uint8_t*) v.data();
+    s.insert (s.end(), p, p + 200);
+    const char name[] = "LYNX test";
+    s.insert (s.end(), name, name + sizeof (name) - 1);
+    s.resize (8 + 0x1cc, 0);
+    return s;
+}
+
+std::vector<std::uint8_t> hardcoreInstallFile (const std::string& relative)
+{
+    if (realFlpDir.empty())
+        return {};
+    auto path = std::filesystem::path (realFlpDir).parent_path();
+    std::string rel = relative;
+    std::replace (rel.begin(), rel.end(), '\\', '/');
+    std::ifstream in (path / rel, std::ios::binary);
+    return std::vector<std::uint8_t> ((std::istreambuf_iterator<char> (in)), std::istreambuf_iterator<char>());
+}
+} // namespace
+
+TEST (hardcore_exact)
+{
+    constexpr int n = 8192;
+    std::vector<float> inL (n), inR (n);
+    for (int i = 0; i < n; ++i)
+    {
+        inL[(std::size_t) i] = (float) (((i * 37) % 200 - 100) / 60.0);
+        inR[(std::size_t) i] = (float) (((i * 53) % 170 - 85) / 50.0);
+    }
+    struct Gold { int i; float l, r; };
+    auto run = [&] (const std::vector<std::uint8_t>& st, bool cabinet, std::initializer_list<Gold> gold) {
+        const auto s = lynx::hardcore::parse (st);
+        CHECK (s.has_value() && s->presetName == "LYNX test");
+        if (! s)
+            return;
+        lynx::hardcore::Engine e;
+        if (cabinet)
+            for (int c = 1; c <= 20; ++c)
+                e.setCabinetFile (c, hardcoreInstallFile (lynx::hardcore::cabinetPath (c)));
+        for (int i = 0; i < 50; ++i)
+            e.set (i, s->values[(std::size_t) i]);
+        e.prepare (44100.0);
+        std::vector<float> l (inL), r (inR);
+        for (int i = 0; i < n; i += 512)
+            e.process (l.data() + i, r.data() + i, 512);
+        for (const auto& g : gold)
+            CHECK (l[(std::size_t) g.i] == g.l && r[(std::size_t) g.i] == g.r);
+    };
+    // distortion A, chorus, flanger, phaser, reverb; EQ on
+    run (hardcoreTestState (1, { 1, 2, 3, 4, 5 }, { 1, 1, 1, 1, 1 }, 1, 0), false,
+         { { 100, 0.15404899418354034f, 0.15402227640151978f }, { 1000, 0.5094000101089478f, 0.18492065370082855f },
+           { 2047, -1.0110447406768799f, -0.9156813621520996f }, { 4000, -1.7594877481460571f, 0.10223101079463959f },
+           { 8191, 0.14906616508960724f, 1.9577150344848633f } });
+    // delay, noise gate, equalizer, compressor, modulator
+    run (hardcoreTestState (2, { 6, 7, 8, 9, 10 }, { 1, 1, 1, 1, 1 }, 0, 0), false,
+         { { 100, 0.0f, 0.0f }, { 1000, -0.02293410710990429f, -0.049560099840164185f },
+           { 2047, 0.0009527528891339898f, 0.002417751122266054f }, { 4000, -0.07934026420116425f, -0.12522825598716736f },
+           { 8191, -0.29015353322029114f, -0.10772112756967545f } });
+    // tube drive, an empty box, a switched-off distortion, chorus, delay; EQ on
+    run (hardcoreTestState (3, { 11, 0, 1, 2, 6 }, { 1, 1, 0, 1, 1 }, 1, 0), false,
+         { { 100, 0.06743612140417099f, 0.11324237287044525f }, { 1000, -0.019734300673007965f, -0.3736976683139801f },
+           { 2047, 0.8394869565963745f, 1.0702182054519653f }, { 4000, -0.34187665581703186f, -0.32515519857406616f },
+           { 8191, 0.4963859021663666f, 0.36226585507392883f } });
+    if (! hardcoreInstallFile (lynx::hardcore::cabinetPath (4)).empty())
+    {
+        // cabinets "Model D" (float WAV) and "Model T" (24-bit stereo WAV)
+        run (hardcoreTestState (4, { 6, 0, 0, 0, 0 }, { 1, 0, 0, 0, 0 }, 0, 4), true,
+             { { 100, 0.1504828929901123f, 0.12085545808076859f }, { 1000, -0.15621426701545715f, -0.12705086171627045f },
+               { 2047, -0.17077459394931793f, 0.22107036411762238f }, { 4000, -0.15526969730854034f, -0.03145243600010872f },
+               { 8191, 0.4664047658443451f, -0.37835803627967834f } });
+        run (hardcoreTestState (5, { 2, 0, 0, 0, 0 }, { 1, 0, 0, 0, 0 }, 1, 20), true,
+             { { 100, 0.05236158147454262f, -0.0008346981485374272f }, { 1000, 3.7916646003723145f, 6.497415542602539f },
+               { 2047, -6.757109642028809f, -4.441843032836914f }, { 4000, 2.6982486248016357f, -0.5133857131004333f },
+               { 8191, -2.7014360427856445f, 1.8544065952301025f } });
+
+        // the FL import: the slot carries the installation's impulses; the mixer effect equals the engine
+        const auto st = hardcoreTestState (4, { 6, 0, 0, 0, 0 }, { 1, 0, 0, 0, 0 }, 0, 4);
+        const auto slot = lynx::effectFromFl ("Hardcore", st, 120.0, hardcoreInstallFile);
+        CHECK (slot && slot->kind == lynx::EffectKind::hardcore && lynx::hardcore::hasCabinet (*slot, 4)
+               && lynx::hardcore::hasCabinet (*slot, 20));
+        if (slot)
+        {
+            auto fx = lynx::makeEffect (*slot);
+            fx->prepare (44100.0);
+            std::vector<float> l (inL), r (inR);
+            fx->process (l.data(), r.data(), 700, slot->params, 120.0);
+            fx->process (l.data() + 700, r.data() + 700, n - 700, slot->params, 120.0);
+            CHECK (l[1000] == -0.15621426701545715f && r[8191] == -0.37835803627967834f);
+        }
+    }
+
+    // import without the installation: the exact engine, cabinet off; parameters round trip through the slot
+    const auto st = hardcoreTestState (1, { 1, 2, 3, 4, 5 }, { 1, 1, 1, 1, 1 }, 1, 7);
+    const auto slot = lynx::effectFromFl ("Hardcore", st, 120.0);
+    CHECK (slot && slot->kind == lynx::EffectKind::hardcore && slot->state.empty());
+    if (slot)
+    {
+        const auto s = *lynx::hardcore::parse (st);
+        for (int i = 0; i < 50; ++i)
+            CHECK (lynx::hardcore::fromSlot (i, slot->params[(std::size_t) i]) == s.values[(std::size_t) i]);
+        CHECK (lynx::formatEffectParam (lynx::EffectKind::hardcore, 45, slot->params[45], 120.0) == "Distortion");
+        CHECK (lynx::formatEffectParam (lynx::EffectKind::hardcore, 11, slot->params[11], 120.0) == "Model G");
+    }
+    CHECK (lynx::effectInfo (lynx::EffectKind::hardcore).params.size() == 50);
+    CHECK (lynx::hardcore::cabinetPath (9) == "Plugins\\Fruity\\Effects\\Hardcore\\Imp\\Model I .wav");
+    CHECK (! lynx::hardcore::parse (std::vector<std::uint8_t> (100, 0)).has_value());
+}

+ 1 - 0
tests/tests.cpp

@@ -11768,3 +11768,4 @@ TEST (wasp_is_a_silent_placeholder)
 #include "UiToolbarTests.inc"
 #include "LuxeVerbTests.inc"
 #include "ConvolverTests.inc"
+#include "HardcoreTests.inc"