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

Merge branch 'feature/vocodex'

# Conflicts:
#	scripts/build-local.sh
#	scripts/build-windows-zig.sh
Kauan 1 месяц назад
Родитель
Сommit
b7bcfdb4e3

+ 1 - 0
CMakeLists.txt

@@ -36,6 +36,7 @@ add_library(lynx_core STATIC
     src/core/DrumSynthLive.cpp
     src/core/Harmless.cpp
     src/core/VintagePhaser.cpp
+    src/core/Vocodex.cpp
     src/core/FlPatcher.cpp
     src/core/Inflate.cpp
     src/core/WavPack.cpp)

+ 17 - 5
docs/STATUS.md

@@ -1,6 +1,6 @@
 # Status
 
-Last updated: 2026-10-13. Everything below is verified by the core tests (more than a million checks), the
+Last updated: 2026-10-14. Everything below is verified by the core tests (more than a million checks), the
 app's self-test (`LYNX.exe --selftest`), off-screen UI snapshots (`--snapshot`) and a regression run that
 exports the 30 demo projects shipped with FL Studio 2026.
 
@@ -124,6 +124,13 @@ accordingly. Highlights of what is **confirmed and applied**:
   PSOLA path (257-sample latency), Harmonize and MIDI masks; latency reported to PDC.
 - **Fruity Vocoder:** FL's algorithm (band edges, cascaded band-passes, envelope followers, levels).
 - **Frequency Splitter:** exact Linkwitz-Riley structure for every slope (6–96 dB/oct).
+- **Vocodex:** its own engine (`core/Vocodex.cpp`, REA round 35) built from FL's raw state, which the `.lynx`
+  project keeps: band layout and the 13 per-band maps, 64-bit band-pass banks (orders 1–4, flatness, 2×
+  oversampling above 11.05 kHz), PEAK/RMS followers, gate, saturation, double-precision smoother, unison, IPP-style
+  carrier noise, consonant/carrier contour, mod/car pass-through filters and FL's gain ramps; ModIn/CarIn routing and
+  L-R encoding. Bit-exact against the reference model (which is within −137 dB of FL's DLL) on all 77 comparison
+  cases, the 10 demo instances included. Draft follows the stored button for playback and export alike (LYNX has
+  no "HQ for all plugins" option): octave levels and 16-frame re-blocking, its 16 samples of latency reported to PDC.
 - **Fruity Squeeze** and **Vintage Phaser:** FL's algorithms (REA round 29) — Squeeze within 5·10⁻⁹ of the reference model
   (which is bit-exact with FL's DLL), Vintage Phaser (V1/V2, ×4/×8 oversampling, noise, gate, delay) within −121 dB.
 
@@ -170,9 +177,13 @@ accordingly. Highlights of what is **confirmed and applied**:
 - Pitcher: MIDI mode and Harmonize are implemented but LYNX effects receive no MIDI notes, so they behave as FL
   with nothing on the Pitcher's MIDI port (MIDI: no correction; Harmonize: dry voice / dry mix). The reported
   latency (9 / 257 samples) is the DSP's delay; FL's own PDC report is not confirmed.
-- Vocodex: becomes the LYNX vocoder with two side inputs (modulator/carrier from ModIn/CarIn); its band filters,
-  per-band maps, carrier noise, HP/LP, Soundgoodizer and unison differ, the output level is not calibrated against FL,
-  and the internal Sytrus carrier (CarIn = "---") is not available (only the modulator passes).
+- Vocodex: the Soundgoodizer stage (SG > 0, all demo instances) is LYNX's Soundgoodizer approximation (preset A,
+  amount = SG, then the presets' −0.2 dB master limiter) on the engine's output — FL hosts its own Soundgoodizer
+  with `Data/SG.dat`, not decoded yet (on the "Vocodex demo" inputs FL's SG_x64.dll with SG.dat peaks at −0.39 dBFS
+  and sits ≈1.7 dB above the approximation, median of 100 ms windows); the
+  internal Sytrus carrier (CarIn = "---", Ookay and NewStuff) is not available, so that Vocodex passes its
+  modulator unchanged (`vocodex::makeInternalCarrier` is the hook for it); map segments with tension ≠ 0 are read
+  as straight lines (no demo uses them).
 - FLEX: its packs are encrypted; LYNX never opens them (the channel gets a synth patch by preset name).
 
 ## `.flp` format findings (besides `docs/ANALISE_FL_STUDIO.md`)
@@ -215,4 +226,5 @@ Confirmed empirically on the demo projects:
 - Mouse/keyboard interactions are checked by code review and off-screen snapshots only.
 
 ## Open items
-- Ogun's per-partial release and ALT DECAY, Vocodex's internal carrier synth, Harmor's per-partial resonance and image synthesis.
+- Ogun's per-partial release and ALT DECAY, Vocodex's internal carrier synth (needs LYNX's exact Sytrus) and its
+  Soundgoodizer stage (SG_x64.dll not decoded), Harmor's per-partial resonance and image synthesis.

+ 2 - 1
scripts/build-local.sh

@@ -13,7 +13,7 @@ if [[ -z "${CXX:-}" ]]; then
 fi
 
 FLAGS="-std=c++20 -O2 -g -Wall -Wextra -Wpedantic -Isrc -Ithird_party/wavpack/include"
-CORE="src/flp/Flp.cpp src/core/Song.cpp src/core/NoteEdit.cpp src/core/Recorder.cpp src/core/Pdc.cpp src/core/WorkerPool.cpp src/core/TimeStretch.cpp src/core/Arpeggiator.cpp src/core/SynthPresets.cpp src/core/Slicer.cpp src/core/Templates.cpp src/core/FlWrapper.cpp src/core/FlEffects.cpp src/core/Effector.cpp src/core/VintagePhaser.cpp src/core/FlSamplers.cpp src/core/FlSynths.cpp src/core/FlSytrus.cpp src/core/FlGenerators.cpp src/core/PhysicalModels.cpp src/core/DrumSynthLive.cpp src/core/Harmless.cpp src/core/FlPatcher.cpp src/core/Inflate.cpp src/core/WavPack.cpp src/core/Scheduler.cpp src/core/Instruments.cpp src/core/RackRenderer.cpp src/core/FlpImport.cpp src/core/Effects.cpp"
+CORE="src/flp/Flp.cpp src/core/Song.cpp src/core/NoteEdit.cpp src/core/Recorder.cpp src/core/Pdc.cpp src/core/WorkerPool.cpp src/core/TimeStretch.cpp src/core/Arpeggiator.cpp src/core/SynthPresets.cpp src/core/Slicer.cpp src/core/Templates.cpp src/core/FlWrapper.cpp src/core/FlEffects.cpp src/core/Effector.cpp src/core/VintagePhaser.cpp src/core/Vocodex.cpp src/core/FlSamplers.cpp src/core/FlSynths.cpp src/core/FlSytrus.cpp src/core/FlGenerators.cpp src/core/PhysicalModels.cpp src/core/DrumSynthLive.cpp src/core/Harmless.cpp src/core/FlPatcher.cpp src/core/Inflate.cpp src/core/WavPack.cpp src/core/Scheduler.cpp src/core/Instruments.cpp src/core/RackRenderer.cpp src/core/FlpImport.cpp src/core/Effects.cpp"
 
 mkdir -p build-local build-local/wavpack
 # WavPack decoder (C)
@@ -35,5 +35,6 @@ $CXX $FLAGS src/flp/Flp.cpp tools/flpdump.cpp -o build-local/flpdump 2> >(grep -
 
 $CXX $FLAGS $CORE $WAVPACK tools/renderwav.cpp -o build-local/renderwav 2> >(grep -v 'glibc version' >&2)
 $CXX $FLAGS $CORE $WAVPACK tools/comparewav.cpp -o build-local/comparewav 2> >(grep -v 'glibc version' >&2)
+$CXX $FLAGS $CORE $WAVPACK tools/vocodexrender.cpp -o build-local/vocodexrender 2> >(grep -v 'glibc version' >&2)
 
 ./build-local/lynx_tests "$@"

+ 1 - 1
scripts/build-windows-zig.sh

@@ -75,7 +75,7 @@ APP_SOURCES=(src/Main.cpp
              src/engine/SampleLibrary.cpp src/engine/WavPackFormat.cpp src/engine/ProjectFile.cpp src/engine/PluginHost.cpp src/engine/PluginSandbox.cpp src/engine/Exporter.cpp src/engine/StreamPrefetcher.cpp src/engine/ClapFormat.cpp src/engine/MidiFileIo.cpp src/engine/PreviewPlayer.cpp
              src/ui/MainComponent.cpp src/ui/ChannelRackComponent.cpp src/ui/PianoRollComponent.cpp src/ui/PlaylistComponent.cpp src/ui/MixerComponent.cpp src/ui/PluginWindow.cpp src/ui/WindowOwner.cpp src/ui/ParametricEqEditor.cpp src/ui/ExportDialog.cpp src/ui/AutomationUi.cpp src/ui/ChannelSettings.cpp src/ui/BrowserComponent.cpp
              src/core/Song.cpp src/core/Scheduler.cpp src/core/Instruments.cpp src/core/RackRenderer.cpp
-             src/core/FlpImport.cpp src/core/Effects.cpp src/core/NoteEdit.cpp src/core/Recorder.cpp src/core/Pdc.cpp src/core/WorkerPool.cpp src/core/TimeStretch.cpp src/core/Arpeggiator.cpp src/core/SynthPresets.cpp src/core/Slicer.cpp src/core/Templates.cpp src/core/FlWrapper.cpp src/core/FlEffects.cpp src/core/Effector.cpp src/core/VintagePhaser.cpp src/core/FlSamplers.cpp src/core/FlSynths.cpp src/core/FlSytrus.cpp src/core/FlGenerators.cpp src/core/PhysicalModels.cpp src/core/DrumSynthLive.cpp src/core/Harmless.cpp src/core/FlPatcher.cpp src/core/Inflate.cpp src/core/WavPack.cpp src/flp/Flp.cpp
+             src/core/FlpImport.cpp src/core/Effects.cpp src/core/NoteEdit.cpp src/core/Recorder.cpp src/core/Pdc.cpp src/core/WorkerPool.cpp src/core/TimeStretch.cpp src/core/Arpeggiator.cpp src/core/SynthPresets.cpp src/core/Slicer.cpp src/core/Templates.cpp src/core/FlWrapper.cpp src/core/FlEffects.cpp src/core/Effector.cpp src/core/VintagePhaser.cpp src/core/Vocodex.cpp src/core/FlSamplers.cpp src/core/FlSynths.cpp src/core/FlSytrus.cpp src/core/FlGenerators.cpp src/core/PhysicalModels.cpp src/core/DrumSynthLive.cpp src/core/Harmless.cpp src/core/FlPatcher.cpp src/core/Inflate.cpp src/core/WavPack.cpp src/flp/Flp.cpp
              src/platform/MingwFixes.cpp)
 
 echo "WavPack (decoder, C)..."

+ 8 - 0
src/Main.cpp

@@ -395,6 +395,12 @@ private:
         auto utilitySlot = lynx::makeEffectSlot (lynx::EffectKind::utility);
         utilitySlot.params[1] = 0.2f;
         rich.mixer[2].effects.push_back (utilitySlot);
+        auto vocodexSlot = lynx::makeEffectSlot (lynx::EffectKind::vocodex); // FL's raw state travels as base64
+        for (int i = 0; i < 300; ++i)
+            vocodexSlot.state.push_back ((std::uint8_t) (i * 37));
+        vocodexSlot.sidechain = 1;
+        vocodexSlot.sidechain2 = 2;
+        rich.mixer[3].effects.push_back (vocodexSlot);
         rich.addMarker ({ 3840, "Refrão", 0, 4 });
         rich.addMarker ({ 7680, {}, 7, 8 });
         const auto richBack = lynx::ProjectFile::fromJson (lynx::ProjectFile::toJson (rich), error);
@@ -410,6 +416,8 @@ private:
                             && paramsClose (richBack->mixer[2].effects[0].params, peqSlot.params)
                             && richBack->mixer[2].effects[1].kind == lynx::EffectKind::utility
                             && paramsClose (richBack->mixer[2].effects[1].params, utilitySlot.params)
+                            && richBack->mixer[3].effects.size() == 1 && richBack->mixer[3].effects[0].kind == lynx::EffectKind::vocodex
+                            && richBack->mixer[3].effects[0].state == vocodexSlot.state && richBack->mixer[3].effects[0].sidechain2 == 2
                             && richBack->markers() == rich.markers();
 
         // undo/redo

+ 16 - 4
src/core/Effects.cpp

@@ -3,6 +3,7 @@
 #include "core/Effector.h"
 #include "core/PitcherDsp.h"
 #include "core/VintagePhaser.h"
+#include "core/Vocodex.h"
 
 #include "core/Biquad.h"
 
@@ -1820,10 +1821,8 @@ public:
             Branch branch;
             branch.gain = b.gain;
             for (const auto& child : b.chain)
-                if (child.kind == EffectKind::parallel) // nested containers (Patcher series-parallel graphs)
-                    branch.chain.push_back ({ makeParallelEffect (child), child });
-                else if (child.kind != EffectKind::plugin)
-                    branch.chain.push_back ({ makeEffect (child.kind), child });
+                if (child.kind != EffectKind::plugin) // nested containers too (Patcher series-parallel graphs)
+                    branch.chain.push_back ({ makeEffect (child), child });
             branches.push_back (std::move (branch));
         }
         for (const auto& link : slot.links)
@@ -2131,6 +2130,7 @@ const EffectInfo& effectInfo (EffectKind kind)
                                                        { "Formant", 0.5f }, { "Width", 45.0f / 195.0f }, { "Attack", 10.0f / 990.0f },
                                                        { "Release", 90.0f / 990.0f }, { "Hold", 0.0f }, { "Modulator", 0.0f },
                                                        { "Carrier", 0.0f }, { "Wet", 0.8f }, { "Side inputs", 0.0f } } };
+    static const EffectInfo vocodexInfo { "Vocodex", {} }; // everything comes from FL's raw state (EffectSlot::state)
     // raw FL values / max (the names are FL's controls, REA_rodada29 §2.1)
     static const EffectInfo squeezeInfo { "Squeeze", { { "Volume", 127.0f / 160.0f }, { "Mix", 0.5f }, { "Steps", 1.0f / 32768.0f },
                                                        { "Filter", 0.0f }, { "Filter type", 0.0f }, { "Resonance", 0.5f },
@@ -2224,6 +2224,7 @@ const EffectInfo& effectInfo (EffectKind kind)
         case EffectKind::pitchCorrect: return pitchCorrectInfo;
         case EffectKind::squeeze: return squeezeInfo;
         case EffectKind::vintagePhaser: return vintagePhaserInfo;
+        case EffectKind::vocodex: return vocodexInfo;
     }
     return eq;
 }
@@ -2492,6 +2493,7 @@ std::string formatEffectParam (EffectKind kind, int param, float v, double bpm)
 
         case EffectKind::plugin:
         case EffectKind::parallel:
+        case EffectKind::vocodex:
             break;
     }
 
@@ -2515,6 +2517,15 @@ std::unique_ptr<Effect> makeParallelEffect (const EffectSlot& slot)
     return std::make_unique<ParallelEffect> (slot);
 }
 
+std::unique_ptr<Effect> makeEffect (const EffectSlot& slot)
+{
+    if (slot.kind == EffectKind::parallel)
+        return makeParallelEffect (slot);
+    if (slot.kind == EffectKind::vocodex)
+        return vocodex::make (slot.state);
+    return makeEffect (slot.kind);
+}
+
 std::unique_ptr<Effect> makeEffect (EffectKind kind)
 {
     switch (kind)
@@ -2542,6 +2553,7 @@ std::unique_ptr<Effect> makeEffect (EffectKind kind)
         case EffectKind::vocoder: return std::make_unique<Vocoder>();
         case EffectKind::squeeze: return std::make_unique<Squeeze>();
         case EffectKind::vintagePhaser: return makeVintagePhaser();
+        case EffectKind::vocodex: return vocodex::make ({}); // without a state: passes the signal; use makeEffect (slot)
         case EffectKind::pitchCorrect: return std::make_unique<PitchCorrect>();
         case EffectKind::plugin: break; // created by the app (RackState::Factories)
     }

+ 3 - 0
src/core/Effects.h

@@ -87,6 +87,9 @@ public:
 };
 
 std::unique_ptr<Effect> makeEffect (EffectKind kind);
+// The effect of a slot: like makeEffect (kind), but also builds the effects that need more than the kind
+// (`parallel` containers, the Vocodex from its raw state).
+std::unique_ptr<Effect> makeEffect (const EffectSlot& slot);
 
 // FL's mode-0 pan law as a 2×2 matrix (outL = ll·inL + rl·inR, outR = lr·inL + rr·inR), unit volume (REA_rodada27 §3.1)
 void flPanMatrix (double pan, float& ll, float& rl, float& lr, float& rr) noexcept;

+ 28 - 77
src/core/FlEffects.cpp

@@ -1,5 +1,6 @@
 #include "core/FlEffects.h"
 #include "core/VintagePhaser.h"
+#include "core/Vocodex.h"
 #include "core/FlSynths.h"
 
 #include <algorithm>
@@ -796,88 +797,38 @@ std::optional<EffectSlot> fruityVocoder (const std::vector<std::uint8_t>& d, std
 }
 } // namespace
 
+std::vector<EffectSlot> soundgoodizerApproximation (int preset, int amount)
+{
+    // a Soundgoodizer state (version, preset, amount) through the same conversion as the plugin's own slots, then
+    // the master limiter of its Maximus presets (a–d.dat: −0.2 dB ceiling, 86 ms release; REA_rodada8 §2)
+    std::vector<std::uint8_t> state (12, 0);
+    const std::int32_t words[3] { 1, preset, amount };
+    std::memcpy (state.data(), words, sizeof (words));
+    std::vector<EffectSlot> chain (1);
+    soundgoodizer (state, chain[0]);
+    auto limiterSlot = makeEffectSlot (EffectKind::limiter);
+    limiterSlot.params[0] = clamp01 ((-0.2 + 12.0) / 12.0);
+    limiterSlot.params[1] = 0.0f;
+    limiterSlot.params[2] = limiterReleaseValue (86.0);
+    chain.push_back (limiterSlot);
+    return chain;
+}
+
 std::optional<VocodexConversion> vocodexEffect (const std::vector<std::uint8_t>& d)
 {
-    // REA_rodada20 §4.2.1: u32 version (8 in the high word), 13 maps (i32 version, i32, i32 n, n × 24 B, 20 B),
-    // 20 × i32 parameters, a 0x24-byte block (hold mode, order, unison, bands, draft, ModIn, CarIn, 8 × u8)
-    if (d.size() < 4)
-        return std::nullopt;
-    auto version = (std::uint32_t) i32At (d, 0);
-    if (version > 0xffff)
-        version >>= 16;
-    if (version < 5 || version > 8) // older blocks are laid out differently
-        return std::nullopt;
-    std::size_t pos = 4;
-    std::vector<std::pair<double, double>> distribution; // map 8: (x, y)
-    for (int m = 0; m < 13; ++m)
-    {
-        if (pos + 12 > d.size())
-            return std::nullopt;
-        const auto n = i32At (d, pos + 8);
-        if (n < 0 || n > 10000 || pos + 12 + (std::size_t) n * 24 + 20 > d.size())
-            return std::nullopt;
-        double x = 0.0;
-        for (int k = 0; k < n; ++k)
-        {
-            double dx = 0.0, y = 0.0;
-            std::memcpy (&dx, d.data() + pos + 12 + 24 * (std::size_t) k, 8);
-            std::memcpy (&y, d.data() + pos + 20 + 24 * (std::size_t) k, 8);
-            x += dx;
-            if (m == 8 && std::isfinite (y))
-                distribution.emplace_back (x, y);
-        }
-        pos += 12 + (std::size_t) n * 24 + 20;
-    }
-    if (pos + 20 * 4 + 0x24 > d.size())
+    // the exact engine keeps FL's raw state (REA_rodada35); ModIn/CarIn index the track's inputs list
+    const auto state = vocodex::parseState (d);
+    if (! state)
         return std::nullopt;
-    auto tag = [&] (int t) { return i32At (d, pos + 4 * (std::size_t) t); };
-    const auto block = pos + 20 * 4;
-    const auto order = i32At (d, block + 4), bands = i32At (d, block + 12);
     VocodexConversion out;
-    out.modIn = i32At (d, block + 20);
-    out.carIn = i32At (d, block + 24);
-    if (d[block + 28] != 0) // L-R encoding: modulator left, carrier right (the Fruity Vocoder's layout)
-        out.modIn = out.carIn = 0;
-
-    auto slot = makeEffectSlot (EffectKind::vocoder);
-    slot.params[16] = d[block + 28] != 0 ? 0.0f : 1.0f; // separate inputs, unless L-R encoded
-    slot.params[0] = (float) std::clamp (std::round (std::log2 (std::clamp (bands, 5, 100) / 4.0)), 0.0, 5.0) / 5.0f; // nearest of 4…128
-    slot.params[1] = (float) (std::clamp (order, 1, 3) - 1) / 2.0f;
-    slot.params[2] = 1.0f; // mix
-    // band range from map 8 (§4.2.3): y → Hz through the inverse of FL's scale (a = 65.41 Hz, b = 21 096 Hz, p = 3/28)
-    auto hz = [] (double y) {
-        constexpr double a = 65.40639, b = 21096.16, p = 3.0 / 28.0;
-        const auto f = y < p ? a * y / p : a + (b - a) * a / b * (std::exp ((y - p) / (1.0 - p) * std::log (1.0 + b / a)) - 1.0);
-        return std::clamp (f, 20.0, 20000.0);
-    };
-    double lo = 0.1429, hi = 0.9918;
-    if (! distribution.empty())
-    {
-        lo = hi = distribution.front().second;
-        for (const auto& [x, y] : distribution)
-            lo = std::min (lo, y), hi = std::max (hi, y);
-    }
-    auto freqParam = [] (double f) { return (float) clamp01 (std::log (1.0 + (f - 10.0) / 159.9) / std::log (101.0)); };
-    slot.params[4] = freqParam (hz (lo));
-    slot.params[5] = freqParam (hz (hi));
-    slot.params[6] = 1.0f; // log spacing
-    slot.params[8] = (float) clamp01 ((std::clamp (tag (17), -1200, 1200) + 1200) / 2400.0); // Mod pitch → carrier bank shift
-    // attack/release (×map 6/7 at ×1): (501^(v/10000) − 1)·2 ms and ·4 ms; the LYNX vocoder starts at 10 ms
-    slot.params[10] = (float) clamp01 (((std::pow (501.0, std::clamp (tag (9), 0, 10000) / 10000.0) - 1.0) * 2.0 - 10.0) / 990.0);
-    slot.params[11] = (float) clamp01 (((std::pow (501.0, std::clamp (tag (11), 0, 10000) / 10000.0) - 1.0) * 4.0 - 10.0) / 990.0);
-    // pass-through curve11(v/12800) and wet (7^(v/1000) − 1)/6 onto the vocoder's curve11(1.25·p)
-    auto curve11Param = [] (double gain) { return (float) clamp01 (std::log (1.0 + 10.0 * std::max (0.0, gain)) / std::log (11.0) / 1.25); };
-    auto curve11 = [] (double x) { return (std::pow (11.0, x) - 1.0) / 10.0; };
-    slot.params[13] = curve11Param (curve11 (std::clamp (tag (2), 0, 16000) / 12800.0));
-    slot.params[14] = curve11Param (curve11 (std::clamp (tag (4), 0, 16000) / 12800.0));
-    slot.params[15] = curve11Param ((std::pow (7.0, std::clamp (tag (0), 0, 2000) / 1000.0) - 1.0) / 6.0);
-    if (out.carIn < 0)
-    {
-        slot.params[2] = 0.0f; // the internal Sytrus carrier is not available: only the modulator passes
+    out.slot = makeEffectSlot (EffectKind::vocodex);
+    out.slot.state = d;
+    out.modIn = state->lrEncoding ? 0 : state->modIn;
+    out.carIn = state->lrEncoding ? 0 : state->carIn;
+    if (state->internalCarrier() && vocodex::makeInternalCarrier (*state) == nullptr)
         out.notes.push_back ("Vocodex: internal carrier synth not available (modulator only)");
-    }
-    out.notes.push_back ("Vocodex: approximated by the vocoder (band filters, noise, HP/LP, Soundgoodizer and unison differ)");
-    out.slot = slot;
+    if (state->params[vocodex::sg] > 0)
+        out.notes.push_back ("Vocodex: Soundgoodizer stage approximated");
     return out;
 }
 

+ 5 - 2
src/core/FlEffects.h

@@ -68,8 +68,8 @@ struct LovePhilterConversion
 // compressor's detector; REA_rodada22 §1)
 std::optional<EffectSlot> fruityLimiterCompressor (const std::vector<std::uint8_t>& state);
 
-// Vocodex as the LYNX vocoder in "side inputs" mode (REA_rodada20 §4.2): ModIn/CarIn index the track's inputs
-// list (0 = own input; CarIn < 0 = internal synth carrier)
+// Vocodex as the exact engine (core/Vocodex.h, REA_rodada35) holding FL's raw state: ModIn/CarIn index the track's
+// inputs list (0 = own input; CarIn < 0 = internal synth carrier)
 struct VocodexConversion
 {
     EffectSlot slot;
@@ -77,6 +77,9 @@ struct VocodexConversion
     std::vector<std::string> notes;
 };
 std::optional<VocodexConversion> vocodexEffect (const std::vector<std::uint8_t>& state);
+// LYNX's Soundgoodizer approximation (REA_rodada8; preset 0…3 = A…D, amount 0…1000): the compressor followed by
+// the presets' −0.2 dB master limiter
+std::vector<EffectSlot> soundgoodizerApproximation (int preset, int amount);
 
 std::optional<LovePhilterConversion> lovePhilterEffects (const std::vector<std::uint8_t>& state);
 

+ 2 - 1
src/core/RackRenderer.cpp

@@ -135,6 +135,7 @@ std::unique_ptr<const RackState> RackState::build (Song song,
             if (previous != nullptr && t < previous->song.mixer.size() && t < previous->effects.size()
                 && i < previous->song.mixer[t].effects.size() && i < previous->effects[t].size()
                 && previous->song.mixer[t].effects[i].kind == kind && kind != EffectKind::parallel // the container is rebuilt
+                && previous->song.mixer[t].effects[i].state == slots[i].state
                 && (kind != EffectKind::plugin
                     || (previous->song.mixer[t].effects[i].plugin.id == slots[i].plugin.id && previous->sampleRate == sampleRate)))
             {
@@ -154,7 +155,7 @@ std::unique_ptr<const RackState> RackState::build (Song song,
             }
             else
             {
-                effect = kind == EffectKind::parallel ? makeParallelEffect (slots[i]) : makeEffect (kind);
+                effect = makeEffect (slots[i]);
                 effect->prepare (sampleRate);
             }
 

+ 3 - 1
src/core/Song.h

@@ -279,7 +279,8 @@ enum class EffectKind : std::uint8_t
     vocoder,      // Fruity Vocoder channel vocoder: L modulates, R is the carrier (mono output)
     pitchCorrect, // pitch correction (FL's Pitcher): detects the pitch and pulls it to the nearest allowed note
     squeeze,      // FL's Fruity Squeeze, exact (REA_rodada29 §2): quantiser, periodic gate, filter; raw values / max
-    vintagePhaser // FL's Vintage Phaser (REA_rodada29 §3, core/VintagePhaser.h): 36 normalised engine values
+    vintagePhaser, // FL's Vintage Phaser (REA_rodada29 §3, core/VintagePhaser.h): 36 normalised engine values
+    vocodex       // FL's Vocodex (REA_rodada35, core/Vocodex.h): built from FL's raw state (EffectSlot::state)
 };
 
 constexpr int maxEffectParams = 48; // the 7-band parametric EQ and the Pitcher use most of them
@@ -315,6 +316,7 @@ struct EffectSlot
     int sidechain2 = -1;  // second side input (vocoder carrier); −1 = none
     std::vector<EffectBranch> branches;           // used when kind == parallel
     std::vector<EffectLink> links;                // used when kind == parallel
+    std::vector<std::uint8_t> state;              // FL's raw plugin state, for exact effects built from it (vocodex)
 };
 
 // Send from one track to another (post-fader), like FL's routing between inserts.

+ 1731 - 0
src/core/Vocodex.cpp

@@ -0,0 +1,1731 @@
+#include "core/Vocodex.h"
+
+#include <algorithm>
+#include <climits>
+#include <cmath>
+#include <cstring>
+
+#include "core/FlEffects.h"
+
+// The engine's rounding is part of its behaviour (the reference matches FL's DLL to the last bits): no fused
+// multiply-add contraction, whatever the target CPU.
+#if defined(__clang__)
+#pragma STDC FP_CONTRACT OFF
+#endif
+
+namespace lynx::vocodex
+{
+namespace
+{
+constexpr double ln2 = 0.69314718055994529;
+constexpr double pi = 3.14159265358979323846;
+constexpr int maxVoices = 6;         // voices v = −4…1 at index v + 4 (v ≤ 0 analyse the modulator, v = 1 the carrier)
+constexpr int maxOrder = 4;
+constexpr int levelCount = 6;        // signal levels: 0 = 2× up-sampled, 1 = native rate, 2… = successive halves
+constexpr int smootherStages = 8;
+constexpr int fifoFrames = 16;       // Draft re-blocking (and its latency)
+constexpr double lnHundredth = -4.6051701859880918; // ln 0.01: a smoother stage covers 99 % of a step in t samples
+constexpr float tiny = 5.9604644775390625e-08f;      // 2⁻²⁴: state values below it are flushed to 0
+constexpr int noTail = INT_MAX;
+
+// --- FL's frequency scale (REA_rodada20 §4.2.3): map y ↔ Hz -------------------------------------------------------
+struct FreqScale
+{
+    double a, b, p, k4, k5, k6, k7;
+
+    FreqScale()
+    {
+        a = std::exp (0.057762265046662105 * -33.0) * 440.0;
+        b = std::exp (0.057762265046662105 * 67.0) * 440.0;
+        const double p2 = 1.0;
+        p = (std::log (2.0) / std::log (b * 2.0 / a)) * p2 + a * (1.0 / b) * (1.0 - p2);
+        const double q = (p2 * b) / a, l3 = std::log (q + 1.0);
+        k4 = 1.0 / l3;
+        k5 = (1.0 / (1.0 - p)) * l3;
+        k6 = q / (b - a);
+        k7 = 1.0 / q;
+    }
+    double toHz (double y) const noexcept { return p <= y ? (std::exp ((y - p) * k5) - 1.0) * (b - a) * k7 + a : (y * a) / p; }
+    double toY (double f) const noexcept { return a <= f ? p + std::log ((f - a) * k6 + 1.0) * k4 * (1.0 - p) : (f * p) / a; }
+};
+
+const FreqScale& freqScale()
+{
+    static const FreqScale scale;
+    return scale;
+}
+
+// maps 1 (pan), 2 (gain offset) and 10 (pitch) are read centred (y − 0.5)
+constexpr std::array<double, 13> mapCentre { 0, 0.5, 0.5, 0, 0, 0, 0, 0, 0, 0, 0.5, 0, 0 };
+
+// straight segments between the points (curved segments, tension ≠ 0, are not decoded; no demo uses them)
+double mapAt (const Map& m, double x) noexcept
+{
+    const auto n = m.x.size();
+    if (n == 0)
+        return 0.0;
+    if (n == 1 || x <= m.x[0])
+        return m.y[0];
+    for (std::size_t i = 1; i < n; ++i)
+        if (x <= m.x[i])
+        {
+            const double dx = m.x[i] - m.x[i - 1];
+            const double t = dx > 0 ? (x - m.x[i - 1]) / dx : 1.0;
+            return m.y[i - 1] + t * (m.y[i] - m.y[i - 1]);
+        }
+    return m.y[n - 1];
+}
+
+// 2^x for the float exponents of the engine: integer exponents by repeated products, others through exp
+float powFloat (float base, float x) noexcept
+{
+    if (x == 0.0f)
+        return 1.0f;
+    const float r = std::rint (x);
+    if (r == x)
+    {
+        const int k = (int) r;
+        double p = 1.0, b = base;
+        for (int a = k < 0 ? -k : k; a != 0; a >>= 1)
+        {
+            if ((a & 1) != 0)
+                p *= b;
+            b *= b;
+        }
+        return (float) (k < 0 ? 1.0 / p : p);
+    }
+    return (float) std::exp ((double) x * std::log ((double) base));
+}
+
+// (11^l − 1)/10 with l = v·scale
+double curve11 (int v, float scale) noexcept
+{
+    const float l = (float) v * scale;
+    if (l == 1.0f)
+        return 1.0;
+    return (float) ((std::exp ((double) (l * 2.39789534f)) - 1.0) * (double) 0.100000001f);
+}
+
+// (7^l − 1)/6
+float curve7 (float l) noexcept
+{
+    if (l == 1.0f)
+        return 1.0f;
+    return (float) ((std::exp ((double) (l * 1.9459101f)) - 1.0) * (double) 0.166666672f);
+}
+
+// (3^(2m) − 1)/2
+double curve3 (double m) noexcept
+{
+    const float h = (float) (m * 2.0);
+    if (h == 1.0f)
+        return 1.0;
+    return (float) ((std::exp ((double) (h * 1.09861231f)) - 1.0) * (double) 0.5f);
+}
+
+double flushToFloat (double v) noexcept
+{
+    float f = (float) v;
+    if (std::fabs (f) < tiny)
+        f = 0.0f;
+    return (double) f;
+}
+
+// --- biquads ---------------------------------------------------------------------------------------------------------
+struct Biquad
+{
+    float f = 0.0f, bw = 0.0f; // design frequency (Hz) and band width (octaves)
+    double b0 = 0, b1 = 0, b2 = 0, a1 = 0, a2 = 0;
+    std::array<double, 8> s {}; // x1 L/R, x2 L/R, y1 L/R, y2 L/R
+
+    // band-pass with a constant 0 dB peak; w0 = 2π/fs
+    void bandPass (double w0) noexcept
+    {
+        const double w = (double) f * w0, sn = std::sin (w), cs = std::cos (w);
+        const double x = 0.34657359027997264 * (double) bw * w / sn;
+        const double alpha = sn * ((std::exp (x) - std::exp (-x)) * 0.5);
+        const double d = 1.0 / (alpha + 1.0);
+        a1 = d * cs * -2.0;
+        a2 = d * (1.0 - alpha);
+        b1 = 0.0;
+        b0 = d * alpha;
+        b2 = d * -alpha;
+    }
+
+    // low-pass / high-pass with α = sin ω · q
+    void lowHighPass (bool high, double w0, double q) noexcept
+    {
+        const double w = (double) f * w0, sn = std::sin (w), cs = std::cos (w);
+        const double alpha = sn * q, d = 1.0 / (alpha + 1.0);
+        a1 = d * cs * -2.0;
+        a2 = d * (1.0 - alpha);
+        if (! high)
+        {
+            b1 = d * (1.0 - cs);
+            b0 = b1 * (double) 0.5f;
+        }
+        else
+        {
+            b1 = d * -(cs + 1.0);
+            b0 = -b1 * (double) 0.5f;
+        }
+        b2 = b0;
+    }
+
+    // stereo, 64-bit signal (band filters: b1 = 0)
+    void run64 (const double* in, double* out, int n) noexcept
+    {
+        double x1L = s[0], x1R = s[1], x2L = s[2], x2R = s[3], y1L = s[4], y1R = s[5], y2L = s[6], y2R = s[7];
+        for (int k = 0; k < n; ++k)
+        {
+            const double xL = in[2 * k], xR = in[2 * k + 1];
+            const double yL = xL * b0 + ((x2L * b2 - y2L * a2) - y1L * a1);
+            const double yR = xR * b0 + ((x2R * b2 - y2R * a2) - y1R * a1);
+            out[2 * k] = yL;
+            out[2 * k + 1] = yR;
+            x2L = x1L, x2R = x1R, x1L = xL, x1R = xR, y2L = y1L, y2R = y1R, y1L = yL, y1R = yR;
+        }
+        s = { x1L, x1R, x2L, x2R, y1L, y1R, y2L, y2R };
+    }
+
+    // stereo, float signal; the state is rounded to float once per call
+    void run32 (const float* in, float* out, int n) noexcept
+    {
+        double x1L = s[0], x1R = s[1], x2L = s[2], x2R = s[3], y1L = s[4], y1R = s[5], y2L = s[6], y2R = s[7];
+        for (int k = 0; k < n; ++k)
+        {
+            const double xL = in[2 * k], xR = in[2 * k + 1];
+            const double yL = xL * b0 + (((x1L * b1 - y2L * a2) + x2L * b2) - y1L * a1);
+            const double yR = xR * b0 + (((x1R * b1 - y2R * a2) + x2R * b2) - y1R * a1);
+            out[2 * k] = (float) yL;
+            out[2 * k + 1] = (float) yR;
+            x2L = x1L, x2R = x1R, x1L = xL, x1R = xR, y2L = y1L, y2R = y1R, y1L = yL, y1R = yR;
+        }
+        s = { x1L, x1R, x2L, x2R, y1L, y1R, y2L, y2R };
+        for (auto& v : s)
+            v = flushToFloat (v);
+    }
+
+    void run32Mono (const float* in, float* out, int n) noexcept
+    {
+        double x1 = s[0], x2 = s[2], y1 = s[4], y2 = s[6];
+        for (int k = 0; k < n; ++k)
+        {
+            const double x = in[k];
+            const double y = x * b0 + (((x1 * b1 - y2 * a2) + x2 * b2) - y1 * a1);
+            out[k] = (float) y;
+            x2 = x1, x1 = x, y2 = y1, y1 = y;
+        }
+        s[0] = x1, s[2] = x2, s[4] = y1, s[6] = y2;
+        for (auto& v : s)
+            v = flushToFloat (v);
+    }
+};
+
+// --- polyphase all-pass half-band pair (two 3-section all-pass chains) ---------------------------------------------
+constexpr double halfA[3] { 0.14737711360104661, 0.48246854276970014, 0.88300502576937312 };
+constexpr double halfB[3] { 0.039151597734460045, 0.30264684832849342, 0.6746159185469639 };
+
+struct HalfBand
+{
+    double s[12][2] {};
+
+    void clear() noexcept { std::memset (s, 0, sizeof (s)); }
+
+    void roundState() noexcept
+    {
+        for (int i = 0; i < 6; ++i)
+            for (int c = 0; c < 2; ++c)
+                s[i][c] = flushToFloat (s[i][c]);
+    }
+
+    // n frames in → 2n frames out
+    void up (const float* in, float* out, int n) noexcept
+    {
+        for (int k = 0; k < n; ++k)
+            for (int c = 0; c < 2; ++c)
+            {
+                const double x = in[2 * k + c];
+                const double t0 = s[6][c] + (x - s[0][c]) * halfA[0];
+                s[6][c] = x, s[0][c] = t0;
+                const double t3 = s[9][c] + (x - s[3][c]) * halfB[0];
+                s[9][c] = x, s[3][c] = t3;
+                const double t1 = s[7][c] + (s[0][c] - s[1][c]) * halfA[1];
+                s[7][c] = s[0][c], s[1][c] = t1;
+                const double t4 = s[10][c] + (s[3][c] - s[4][c]) * halfB[1];
+                s[10][c] = s[3][c], s[4][c] = t4;
+                const double t2 = s[8][c] + (s[1][c] - s[2][c]) * halfA[2];
+                s[2][c] = t2;
+                const double t5 = s[11][c] + (s[4][c] - s[5][c]) * halfB[2];
+                s[5][c] = t5;
+                out[4 * k + 2 + c] = (float) t2;
+                out[4 * k + c] = (float) t5;
+                s[8][c] = s[1][c], s[11][c] = s[4][c];
+            }
+        roundState();
+    }
+
+    // 2n frames in → n frames out
+    void down (const float* in, float* out, int n) noexcept
+    {
+        for (int k = 0; k < n; ++k)
+            for (int c = 0; c < 2; ++c)
+            {
+                const double x0 = in[4 * k + c], x1 = in[4 * k + 2 + c];
+                const double t0 = s[6][c] + (x0 - s[0][c]) * halfA[0];
+                s[6][c] = x0, s[0][c] = t0;
+                const double t3 = s[9][c] + (x1 - s[3][c]) * halfB[0];
+                s[9][c] = x1, s[3][c] = t3;
+                const double t1 = s[7][c] + (s[0][c] - s[1][c]) * halfA[1];
+                s[7][c] = s[0][c], s[1][c] = t1;
+                const double t4 = s[10][c] + (s[3][c] - s[4][c]) * halfB[1];
+                s[10][c] = s[3][c], s[4][c] = t4;
+                const double t2 = s[8][c] + (s[1][c] - s[2][c]) * halfA[2];
+                s[8][c] = s[1][c], s[2][c] = t2;
+                const double t5 = s[11][c] + (s[4][c] - s[5][c]) * halfB[2];
+                s[11][c] = s[4][c], s[5][c] = t5;
+                out[2 * k + c] = (float) ((t5 + t2) * 0.5);
+            }
+        roundState();
+    }
+};
+
+// --- followers -------------------------------------------------------------------------------------------------------
+// maximum over the current sample and the W − 1 previous ones (monotonic queue; the inputs are ≥ 0, so the zero
+// history at the start never wins)
+struct SlidingMax
+{
+    int window = 1;
+    std::vector<float> value;
+    std::vector<std::uint32_t> when;
+    int head = 0, count = 0;
+    std::uint32_t clock = 0;
+
+    void setup (int w)
+    {
+        window = std::max (1, w);
+        value.assign ((std::size_t) window, 0.0f);
+        when.assign ((std::size_t) window, 0);
+        clear();
+    }
+    void clear() noexcept { head = count = 0, clock = 0; }
+
+    void run (float* e, int n) noexcept
+    {
+        if (window <= 1)
+            return;
+        for (int k = 0; k < n; ++k, ++clock)
+        {
+            while (count > 0 && clock - when[(std::size_t) head] >= (std::uint32_t) window)
+            {
+                head = head + 1 == window ? 0 : head + 1;
+                --count;
+            }
+            const float x = e[k];
+            while (count > 0)
+            {
+                auto back = head + count - 1;
+                if (back >= window)
+                    back -= window;
+                if (value[(std::size_t) back] > x)
+                    break;
+                --count;
+            }
+            auto pos = head + count;
+            if (pos >= window)
+                pos -= window;
+            value[(std::size_t) pos] = x;
+            when[(std::size_t) pos] = clock;
+            ++count;
+            e[k] = value[(std::size_t) head];
+        }
+    }
+};
+
+// √(mean over W samples of the input) with a double running sum and a float ring
+struct MovingRms
+{
+    int window = 1, pos = 0;
+    std::vector<float> ring;
+    double sum = 0.0;
+    float scale = 1.0f;
+
+    void setup (int w)
+    {
+        window = std::max (1, w);
+        ring.assign ((std::size_t) window, 0.0f);
+        scale = (float) (1.0 / (double) (window * 2));
+        clear();
+    }
+    void clear() noexcept
+    {
+        std::fill (ring.begin(), ring.end(), 0.0f);
+        pos = 0, sum = 0.0;
+    }
+
+    void run (float* e, int n) noexcept // e: L² + R² in, rms out
+    {
+        double s = sum;
+        int p = pos;
+        for (int k = 0; k < n; ++k)
+        {
+            if (window <= ++p)
+                p = 0;
+            s = (s - (double) ring[(std::size_t) p]) + (double) e[k];
+            ring[(std::size_t) p] = e[k];
+            e[k] = (float) (s * (double) scale);
+        }
+        sum = s, pos = p;
+        for (int k = 0; k < n; ++k)
+            e[k] = std::sqrt (std::max (e[k], 0.0f));
+    }
+};
+
+// one-pole attack/release stage, running value in double precision
+struct Smoother
+{
+    double ca = 0.0, cr = 0.0, y = 0.0;
+    bool single = true;
+
+    void run (float* e, int n) noexcept
+    {
+        double v = y;
+        if (! single)
+            for (int k = 0; k < n; ++k)
+            {
+                const double x = e[k];
+                const double c = x >= v ? ca : cr;
+                v = x + c * (v - x);
+                e[k] = (float) v;
+            }
+        else
+            for (int k = 0; k < n; ++k)
+            {
+                const double x = e[k];
+                v = (v - x) * ca + x;
+                e[k] = (float) v;
+            }
+        if (! ((double) tiny < std::fabs (v)))
+            v = 0.0;
+        y = v;
+    }
+};
+
+// stage count round(order + 0.5), each stage t/√order, the last one scaled by its fractional part
+int setupSmoother (std::array<Smoother, smootherStages>& stages, double att, double attOrder, double rel, double relOrder) noexcept
+{
+    if (attOrder <= 1.0)
+        attOrder = 1.0;
+    const double ro = 1.0 < relOrder ? relOrder : 1.0;
+    const int n1 = (int) std::nearbyint (attOrder + 0.5), n2 = (int) std::nearbyint (ro + 0.5);
+    const int n = std::min (std::max (n1, n2), smootherStages);
+    att = att / std::sqrt (attOrder);
+    rel = rel / std::sqrt (ro);
+    for (int i = 0; i < n; ++i)
+    {
+        if (n1 - 1 <= i)
+            att = i < n1 ? att * (1.0 - ((double) n1 - attOrder)) : 0.0;
+        if (n2 - 1 <= i)
+            rel = i < n2 ? rel * (1.0 - ((double) n2 - ro)) : 0.0;
+        double ca = 0.0, cr = 0.0;
+        if (0.0 < att)
+            ca = std::exp (lnHundredth / std::max (att, 1.0));
+        if (0.0 < rel)
+            cr = std::exp (lnHundredth / std::max (rel, 1.0));
+        auto& st = stages[(std::size_t) i];
+        st.ca = ca, st.cr = cr, st.single = ca == cr, st.y = 0.0;
+    }
+    return n;
+}
+
+// --- gain ramps: linear over the block, slope limited to 44.1/fs per sample ------------------------------------------
+float ramp (float& current, float target, float maxSlope, int n, float& start) noexcept
+{
+    start = current;
+    float d = target - start;
+    if (d != 0.0f)
+    {
+        current = target;
+        d = d / (float) n;
+        if (maxSlope < std::fabs (d))
+        {
+            d = std::copysign (maxSlope, d);
+            current = start + d * (float) n;
+            if (std::fabs (current) < 1e-30f)
+                current = 0.0f;
+        }
+    }
+    return d;
+}
+
+// per-sample gains of a ramp, two interleaved accumulators (even/odd samples) as the engine sums them
+void rampGains (float g, float d, int n, float* gg) noexcept
+{
+    float ge = g + 0.0f, go = g + d;
+    const float d2 = d + d;
+    int k = 0;
+    for (; k + 8 <= n; k += 8)
+    {
+        gg[k] = ge;
+        gg[k + 1] = go;
+        gg[k + 2] = ge + d2;
+        gg[k + 3] = go + d2;
+        gg[k + 4] = gg[k + 2] + d2;
+        gg[k + 5] = gg[k + 3] + d2;
+        gg[k + 6] = gg[k + 4] + d2;
+        gg[k + 7] = gg[k + 5] + d2;
+        ge = gg[k + 6] + d2;
+        go = gg[k + 7] + d2;
+    }
+    for (; k < n; ++k)
+    {
+        gg[k] = ge;
+        ge += d;
+    }
+}
+
+// --- the uniform generator of the installation's IPP (ippsRandUniform_Direct_32f), bit-exact ------------------------
+void randUniform (float* out, int n, float lo, float hi, std::uint32_t& seed) noexcept
+{
+    constexpr std::uint32_t inc = 0x3c6ef373u, mul = 69069u;
+    const double scale = (double) (hi - lo) * 2.3283064365387e-10, offset = (double) (lo + hi) * 0.5;
+    std::uint32_t r10 = seed, lcg = 0x436cbae9u, r14 = r10 * mul + inc, r12 = r14 * mul + inc;
+    std::int32_t borrow = -1;
+    int i = 0;
+    for (int k = 0; k < n / 2; ++k)
+    {
+        const auto t = (std::int32_t) (r14 - r12 + (std::uint32_t) borrow);
+        borrow = t < 0 ? -1 : 0;
+        const std::uint32_t x1 = (std::uint32_t) t - (borrow != 0 ? 18u : 0u);
+        lcg = lcg * mul;
+        const auto o1 = (std::int32_t) (x1 + lcg + inc);
+        const auto t2 = (std::int32_t) (r10 - r14 + (std::uint32_t) borrow);
+        borrow = t2 < 0 ? -1 : 0;
+        const std::uint32_t x2 = (std::uint32_t) t2 - (borrow != 0 ? 18u : 0u);
+        lcg = (lcg + inc) * mul;
+        const auto o2 = (std::int32_t) (x2 + lcg + inc);
+        lcg = lcg + inc;
+        out[i] = (float) ((double) o1 * scale + offset);
+        out[i + 1] = (float) ((double) o2 * scale + offset);
+        i += 2;
+        r12 = r10, r14 = x1, r10 = x2;
+    }
+    std::uint32_t last = r10;
+    if ((n & 1) != 0)
+    {
+        const auto t = (std::int32_t) (r14 - r12 + (std::uint32_t) borrow);
+        last = (std::uint32_t) t - (t < 0 ? 18u : 0u);
+        lcg = lcg * mul;
+        out[i] = (float) ((double) (std::int32_t) (last + lcg + inc) * scale + offset);
+    }
+    seed = last;
+}
+
+// --- Draft FIFOs (frames of interleaved stereo) ----------------------------------------------------------------------
+struct Fifo
+{
+    float buf[2 * fifoFrames] {};
+    int pos = 0;
+
+    // input side: releases whole multiples of 16 frames into `out`; returns how many
+    int push (const float* in, float* out, int n) noexcept
+    {
+        const int k = std::min (fifoFrames - pos, n);
+        std::memcpy (buf + 2 * pos, in, 8 * (std::size_t) k);
+        pos += k;
+        if (pos < fifoFrames)
+            return 0;
+        std::memcpy (out, buf, 8 * fifoFrames);
+        const int r = (n - k) % fifoFrames, m = n - k - r;
+        std::memcpy (out + 2 * fifoFrames, in + 2 * k, 8 * (std::size_t) m);
+        std::memcpy (buf, in + 2 * (k + m), 8 * (std::size_t) r);
+        pos = r;
+        return fifoFrames + m;
+    }
+
+    // output side: `nout` frames from what is queued, then from `in` (nin frames); the rest is queued
+    void pull (const float* in, int nin, float* out, int nout) noexcept
+    {
+        const int k = std::min (pos, nout);
+        std::memcpy (out, buf, 8 * (std::size_t) k);
+        std::memmove (buf, buf + 2 * k, 8 * (std::size_t) (fifoFrames - k));
+        pos -= k;
+        const int c = std::min (nout - k, nin);
+        std::memcpy (out + 2 * k, in, 8 * (std::size_t) c);
+        const int rest = nin - c;
+        std::memcpy (buf + 2 * pos, in + 2 * c, 8 * (std::size_t) rest);
+        pos += rest;
+    }
+};
+
+// one analysis (modulator) or filtering (carrier) voice of a band
+struct Voice
+{
+    double oct = 0, width = 0, f = 0, bwf = 0, pitch = 1, pitchMap = 0, gainMap = 0, panMap = 0, offsetMap = 0;
+    float pan = 0, gain = 0, inv = 0, threshold = 0, gainL = 0, gainR = 0;
+    int oversample = 1;
+    std::array<Biquad, maxOrder> filters {};
+    SlidingMax peak;
+    MovingRms rms;
+    std::array<Smoother, smootherStages> smoother {};
+    int stages = 0;
+    float last = 0.0f;
+};
+
+struct Band
+{
+    std::array<Voice, maxVoices> voices;
+    double modPass = 0, satMix = 0, holdMul = 1, attMul = 1, relMul = 1;
+    bool saturate = false;
+    float offset = 0, carrierGain = 0;
+    int level = 0;
+};
+} // namespace
+
+// --- state ------------------------------------------------------------------------------------------------------------
+std::optional<State> parseState (const std::vector<std::uint8_t>& d)
+{
+    auto i32 = [&d] (std::size_t o) {
+        std::int32_t v = 0;
+        std::memcpy (&v, d.data() + o, 4);
+        return v;
+    };
+    auto f64 = [&d] (std::size_t o) {
+        double v = 0;
+        std::memcpy (&v, d.data() + o, 8);
+        return v;
+    };
+    if (d.size() < 4)
+        return std::nullopt;
+    State s;
+    auto version = (std::uint32_t) i32 (0);
+    if (version > 0xffff)
+        version >>= 16;
+    if (version < 5 || version > 8) // older blocks are laid out differently
+        return std::nullopt;
+    s.version = (int) version;
+    std::size_t o = 4;
+    for (auto& m : s.maps)
+    {
+        if (o + 12 > d.size())
+            return std::nullopt;
+        const auto n = i32 (o + 8);
+        if (n < 0 || n > 4096 || o + 12 + 24 * (std::size_t) n + 20 > d.size())
+            return std::nullopt;
+        o += 12;
+        double x = 0.0;
+        for (int i = 0; i < n; ++i, o += 24)
+        {
+            x += f64 (o);
+            m.x.push_back (x);
+            m.y.push_back (f64 (o + 8));
+        }
+        o += 20;
+    }
+    if (o + 20 * 4 + 0x24 > d.size())
+        return std::nullopt;
+    for (auto& p : s.params)
+        p = i32 (o), o += 4;
+    s.holdMode = std::clamp (i32 (o), 0, 1);
+    s.order = std::clamp (i32 (o + 4), 1, maxOrder);
+    s.unison = std::clamp (i32 (o + 8), 0, 4);
+    s.bands = std::clamp (i32 (o + 12), 5, 100);
+    s.draftField = i32 (o + 16);
+    s.modIn = i32 (o + 20);
+    s.carIn = i32 (o + 24);
+    s.lrEncoding = d[o + 28] != 0;
+    s.minTimes = d[o + 29] != 0;
+    s.toMod = d[o + 30] != 0;
+    s.threaded = d[o + 31] != 0;
+    s.subtractiveGate = d[o + 32] != 0;
+    s.toNoise = d[o + 33] != 0;
+    s.fromCar = d[o + 34] != 0;
+    s.fromConsonants = d[o + 35] != 0;
+    o += 0x24;
+    if (o + 13 <= d.size())
+    {
+        std::memcpy (s.mapAxis.data(), d.data() + o, 13);
+        o += 13;
+        if (o < d.size() && o + 1 + d[o] <= d.size())
+        {
+            s.tone.assign ((const char*) d.data() + o + 1, d[o]);
+            o += 1 + (std::size_t) d[o];
+            if (o + 4 <= d.size())
+            {
+                const auto k = i32 (o);
+                o += 4;
+                for (int i = 0; i < k && i < 128 && o + 4 <= d.size(); ++i, o += 4)
+                    s.notes.push_back (i32 (o));
+            }
+        }
+    }
+    return s;
+}
+
+// --- engine ----------------------------------------------------------------------------------------------------------
+struct Engine::Impl
+{
+    State st;
+    double fs = 44100.0, w0 = 0.0;
+    int maxBlock = 0;
+    float maxSlope = 0.001f;
+    bool draft = false;
+    int levels = 1; // signal levels in use: 5 with Draft, 1 without
+
+    std::vector<Band> bands;
+    int bandCount = 0, unison = 0, order = 2;
+    float wet = 0, wetNow = 0, carPass = 0, carPassNow = 0, modPass = 0, modPassNow = 0, noiseAmp = 0, widthFactor = 0;
+    double flat = 0, attOrder = 1, relOrder = 1;
+    std::array<Biquad, 2> modHpFilters {}, carLpFilters {}, noiseHpFilters {};
+    int modHpCount = 0, carLpCount = 0, noiseHpCount = 0;
+    std::array<std::array<HalfBand, levelCount>, 2> analysis {};
+    std::array<HalfBand, levelCount> synthesis {};
+    int tail = noTail, tailCount = 0;
+    float tailMax = 0.0f;
+
+    // contour: consonant (zero-crossing) detector and/or carrier → 12 ms peak → 16/44 ms smoother
+    bool contour = false;
+    SlidingMax contourPeak;
+    std::array<Smoother, smootherStages> contourSmoother {};
+    int contourStages = 0;
+    Biquad consonantHp;
+    int zcWindow = 1, zcPos = 0, zcCount = 0;
+    float zcOffset = 0.0f, zcPrev = 0.0f;
+    std::vector<int> zcRing;
+
+    std::uint32_t seed = 0;
+    std::vector<std::int16_t> satTable; // index 0 and size + 2 are guards
+    int satSize = 0x3fff;
+
+    std::array<Fifo, 2> fifoIn {};
+    Fifo fifoOut {};
+    bool snap = false; // after a Flush the gains jump to their targets
+
+    std::array<std::array<std::vector<double>, levelCount>, 2> level;
+    std::array<std::vector<double>, levelCount> acc;
+    std::array<bool, levelCount> touched {};
+    std::vector<double> tmp64a, tmp64b;
+    std::vector<float> tmp32, env, envSum, x32a, x32b, voc, outBuf, modPassBuf, carPassBuf, noise, contourBuf, mono, carBuf, modBuf, gains;
+
+    double map (int m, double x) const noexcept { return mapAt (st.maps[(std::size_t) m], x) - mapCentre[(std::size_t) m]; }
+
+    void setupBands();
+    void setupPassFilters();
+    void setupSaturation();
+    void clear() noexcept;
+    void filterBand (Voice& u, int sig, int lvl, int n, double* out) noexcept;
+    void accumulate (int lv, const double* a, const double* b, double scale, int n2) noexcept;
+    void saturate (float* e, int n, float dry, float wetGain, float sc) const noexcept;
+    void process (const float* own, const float* mod, const float* car, float* dst, int n) noexcept;
+};
+
+void Engine::Impl::setupBands()
+{
+    const auto& s = st;
+    const auto& scale = freqScale();
+    const int N = s.bands, fat = s.unison;
+    bandCount = N, unison = fat, order = s.order;
+    bands.assign ((std::size_t) N, Band {});
+    widthFactor = (float) (std::exp ((double) ((float) s.params[bandWidth] * 0.00100000005f) * std::log (5.0)) - 1.0) * 0.5f;
+    flat = (double) ((float) s.params[flatness] * 0.00999999978f);
+    attOrder = (double) powFloat (2.0f, (float) s.params[attackCurve] * 0.00100000005f);
+    relOrder = (double) powFloat (2.0f, (float) s.params[releaseCurve] * 0.00100000005f);
+    const double c2 = std::exp (0.057762265046662105 * -33.0) * 440.0;
+    const double invOrderSpan = order > 1 ? 1.0 / (double) (order - 1) : 0.0;
+    // unison detune per voice (v = 0, −1, −2, …) for U = 1…4
+    static constexpr float detune[30] { 0, 0, 0, 0, 0, -1, 1, 0, 0, 0, -1, 0, 1, 0, 0, -1, 0.333333343f, -0.333333343f, 1, 0,
+                                        -1, 0.5f, 0, -0.5f, 1, 0, 0, 0, 0, 0 };
+
+    for (int v = -fat; v < 2; ++v)
+    {
+        double g0 = (double) (s.holdMode == 1) * 0.5 + 1.0;
+        if (order > 1)
+            g0 = g0 / ((double) order - flat * (double) (order - 1));
+        const double q = std::sqrt (4.0 / std::sqrt ((double) N));
+        g0 = g0 * q * (double) powFloat (2.0f, (float) (order - 1)) * 3.0;
+
+        for (int b = 0; b < N; ++b)
+        {
+            auto& B = bands[(std::size_t) b];
+            auto& u = B.voices[(std::size_t) (v + 4)];
+            double f = scale.toHz (map (8, (double) b / (double) (N - 1)));
+            if (f <= 20.0)
+                f = 20.0;
+            u.f = f;
+            double pos[2];
+            pos[0] = pos[1] = scale.toY (u.f);
+            const auto& axis = s.mapAxis;
+            if (v < 1)
+            {
+                u.pitchMap = map (10, pos[0]) * -2.0;
+                double t = u.pitchMap;
+                if (fat > 0)
+                    t = t + (double) (detune[fat * 5 + (-v)] * (float) s.params[unisonPitch] * 0.00100000005f);
+                u.pitch = std::exp (((double) s.params[modPitch] * -0.0008333333333333334 + t) * ln2);
+                pos[1] = scale.toY (u.f * u.pitch);
+                u.gainMap = curve3 (map (0, pos[axis[0]]));
+                u.panMap = map (1, pos[axis[1]]) * 2.0;
+                {
+                    const double m = map (2, pos[axis[2]]) * 2.0;
+                    const double e = std::exp ((double) (float) std::fabs (m) * std::log (1025.0));
+                    const double sign = m == 0 ? 0 : (m < 0 ? -1 : 1);
+                    u.offsetMap = (double) (((float) (e - 1.0) / 1024.0f) * (float) sign);
+                }
+                {
+                    const double m = map (11, pos[axis[11]]);
+                    if (m == 0.0)
+                        B.saturate = false;
+                    else
+                        B.saturate = true, B.satMix = m;
+                }
+                B.holdMul = (double) powFloat (2.0f, (float) (map (5, pos[axis[5]]) * 6.0)) * 0.125;
+                B.attMul = (double) powFloat (2.0f, (float) (map (6, pos[axis[6]]) * 6.0)) * 0.125;
+                B.relMul = (double) powFloat (2.0f, (float) (map (7, pos[axis[7]]) * 6.0)) * 0.125;
+                B.modPass = (double) ((float) curve3 (map (4, pos[axis[4]])) * 0.5f);
+                {
+                    const double m = map (3, pos[1]); // the gate map is always read at the shifted position
+                    const double e = std::exp ((double) (float) m * std::log (1025.0));
+                    u.threshold = (float) ((double) (float) (e - 1.0) * 0.0009765625);
+                }
+                u.bwf = (double) powFloat (2.0f, (float) s.params[modBandWidth] * 0.00100000005f) * 0.25;
+                u.gain = (float) (g0 * u.gainMap);
+                u.pan = (float) u.panMap;
+                B.offset = (float) u.offsetMap;
+                if (axis[9] != 0)
+                    pos[0] = pos[1];
+            }
+            else
+            {
+                u.gain = (float) g0;
+                u.pitch = 1.0;
+                u.bwf = 1.0;
+            }
+            const float w9 = powFloat (2.0f, (float) (map (9, pos[0]) * 4.0));
+            u.bwf = u.bwf * (double) widthFactor * 0.25 * (double) w9;
+            u.oct = std::log (u.f / c2) * 1.4426950408889634;
+        }
+
+        for (int b = 0; b < N; ++b)
+        {
+            auto& B = bands[(std::size_t) b];
+            auto& u = B.voices[(std::size_t) (v + 4)];
+            double d = 0.0;
+            if (b > 0)
+                d = 0.0 + std::fabs (bands[(std::size_t) b - 1].voices[(std::size_t) (v + 4)].oct - u.oct);
+            if (b < N - 1)
+            {
+                d = d + std::fabs (bands[(std::size_t) b + 1].voices[(std::size_t) (v + 4)].oct - u.oct);
+                if (b > 0)
+                    d = d * (double) 0.5f;
+            }
+            d = d * u.bwf;
+            double w = 0.016666666666666666;
+            if (0.016666666666666666 <= d)
+                w = 8.0 < d ? 8.0 : d;
+            u.width = w;
+            const double g = std::sqrt (1.0 / u.width);
+            u.gain = (float) ((double) u.gain * g);
+            float gg = u.gain;
+            if (gg <= 1.52587890625e-05f)
+                gg = 1.52587890625e-05f;
+            u.inv = 1.0f / gg;
+            u.threshold = u.threshold * u.inv;
+            if (s.subtractiveGate)
+                u.threshold = -u.threshold;
+            if (v < 1)
+                B.modPass = B.modPass * g0 * g * 0.25;
+            for (int i = 0; i < order; ++i)
+            {
+                auto& qq = u.filters[(std::size_t) i];
+                const double ww = u.width * (double) order;
+                double bw = 2.0;
+                if (ww < 2.0)
+                    bw = ww;
+                qq.bw = (float) bw;
+                double off = 0.0;
+                if (order > 1)
+                {
+                    qq.bw = (float) ((double) qq.bw / (flat * (double) 0.5f + 1.0));
+                    off = (((double) (i % order)) * invOrderSpan - 0.5) * flat * (double) qq.bw;
+                    if (order == 3)
+                    {
+                        if (i != 1)
+                            qq.bw = qq.bw * 0.5f;
+                    }
+                    else if (order == 4 && (i == 0 || i == 3))
+                        qq.bw = (float) ((double) qq.bw * 0.36363636363636365);
+                }
+                qq.f = (float) (c2 * u.pitch * std::exp ((u.oct + off) * ln2));
+                qq.s = {};
+            }
+        }
+    }
+
+    const double att = (double) (float) (std::exp ((double) ((float) s.params[attack] * 9.99999975e-05f) * std::log (501.0)) - 1.0) * 2.0 * 0.001;
+    const double rel = (double) (float) (std::exp ((double) ((float) s.params[release] * 9.99999975e-05f) * std::log (501.0)) - 1.0) * 2.0 * 0.001 * fs * 2.0;
+    const double holdT = (double) (float) (std::exp ((double) ((float) s.params[hold] * 9.99999975e-05f) * std::log (501.0)) - 1.0) * 2.0 * 0.001 * fs * 0.25;
+    tailMax = 0.0f;
+    for (int b = 0; b < N; ++b)
+    {
+        auto& B = bands[(std::size_t) b];
+        B.carrierGain = B.voices[5].gain;
+        B.offset = B.offset * B.carrierGain;
+
+        // oversampling per voice (any edge above 11 050 Hz) and, in Draft, the band's octave level
+        double rr = 0.0;
+        for (int v = -fat; v < 2; ++v)
+        {
+            auto& u = B.voices[(std::size_t) (v + 4)];
+            double mx = 0.0;
+            for (int i = 0; i < order; ++i)
+            {
+                const double e = (double) u.filters[(std::size_t) i].f * std::exp ((double) (u.filters[(std::size_t) i].bw * 2.0f) * ln2);
+                if (mx <= e)
+                    mx = e;
+            }
+            u.oversample = (11050.0 < mx) + 1;
+            double r = 11050.0;
+            if (u.oversample < 2)
+            {
+                r = rr;
+                if (rr <= mx)
+                    r = mx;
+            }
+            rr = r;
+        }
+        B.level = 0;
+        if (draft)
+            while (B.level < 4 && rr * (double) (1u << (B.level + 1)) < 11050.0)
+                ++B.level;
+        const double dec = 1.0 / (double) (1u << B.level);
+
+        for (int v = -fat; v < 1; ++v)
+        {
+            auto& u = B.voices[(std::size_t) (v + 4)];
+            if (fat > 0)
+                u.pan = (float) ((double) u.pan + ((double) ((b - v) % (fat + 1)) / (double) fat - 0.5) * (double) s.params[unisonPan] * (double) 0.0078125f);
+            const double gs = B.saturate ? 1.0 : (double) u.gain;
+            const float pan = std::clamp (u.pan, -1.0f, 1.0f);
+            const float gain = (float) ((gs * (double) B.carrierGain) / (double) (fat + 1));
+            if (! std::signbit (pan))
+                u.gainR = gain, u.gainL = (1.0f - pan) * gain;
+            else
+                u.gainL = gain, u.gainR = (pan + 1.0f) * gain;
+
+            double minT = 0.0;
+            if (s.minTimes)
+            {
+                const auto& qq = u.filters[0];
+                const double e = (double) qq.f * std::exp ((double) (-3.0f - qq.bw) * ln2);
+                double c = 40.0;
+                if (40.0 <= e)
+                    c = 16000.0 < e ? 16000.0 : e;
+                minT = fs / c;
+                if (s.holdMode == 1)
+                    minT = minT * 2.0;
+            }
+            double holdS = holdT * B.holdMul;
+            if (holdS <= minT)
+                holdS = minT;
+            holdS = holdS * dec;
+            if (s.holdMode == 0)
+                u.peak.setup ((int) std::nearbyint (holdS));
+            else
+                u.rms.setup ((int) std::nearbyint (holdS));
+
+            double minT2 = 0.0;
+            if (s.minTimes)
+            {
+                const auto& qq = B.voices[5].filters[0];
+                const double e = (double) qq.f * std::exp ((double) (float) (-qq.bw) * ln2);
+                double c = 40.0;
+                if (40.0 <= e)
+                    c = 800.0 < e ? 800.0 : e;
+                minT2 = fs / c;
+            }
+            double a = att * fs * B.attMul;
+            if (a <= minT2)
+                a = minT2;
+            double rl = rel * B.relMul;
+            if (rl <= minT2)
+                rl = minT2;
+            rl = rl * dec;
+            u.stages = setupSmoother (u.smoother, a * dec, attOrder, rl, relOrder);
+            u.last = 0.0f;
+            const float t = (float) (holdS + rl);
+            if (tailMax <= t)
+                tailMax = t;
+        }
+        for (int v = -fat; v < 2; ++v)
+        {
+            auto& u = B.voices[(std::size_t) (v + 4)];
+            for (int i = 0; i < order; ++i)
+            {
+                auto& qq = u.filters[(std::size_t) i];
+                double f2 = (double) ((qq.f * (float) (1u << B.level)) / (float) u.oversample);
+                const double cap = fs * 0.4;
+                if (cap <= f2)
+                    f2 = cap;
+                qq.f = (float) f2;
+                qq.bandPass (w0);
+            }
+        }
+    }
+}
+
+void Engine::Impl::setupPassFilters()
+{
+    static constexpr double q[2] { 0.356510361215121, 0.943792598854838 };
+    auto hz = [] (int v) { return (float) (std::exp ((((double) v * std::log (375.0)) / (std::log (2.0) * 65536.0)) * ln2) * 40.0); };
+    auto design = [&] (std::array<Biquad, 2>& f, int& count, bool on, bool high, int v) {
+        count = on ? 2 : 0;
+        for (int i = 0; i < 2 && on; ++i)
+        {
+            f[(std::size_t) i] = Biquad {};
+            f[(std::size_t) i].f = hz (v);
+            f[(std::size_t) i].lowHighPass (high, w0, q[i]);
+        }
+    };
+    design (modHpFilters, modHpCount, st.params[Param::modHp] != 0, true, st.params[Param::modHp]);
+    design (carLpFilters, carLpCount, st.params[Param::carLp] != 0x10000, false, st.params[Param::carLp]);
+    design (noiseHpFilters, noiseHpCount, st.params[Param::carNoiseHp] != 0, true, st.params[Param::carNoiseHp]);
+}
+
+// 16 384-step shaping table from the saturation-curve map (log-spaced x)
+void Engine::Impl::setupSaturation()
+{
+    const int n = satSize;
+    satTable.assign ((std::size_t) n + 4, 0);
+    auto* t = satTable.data() + 1;
+    const double step = 4.0 / (double) n;
+    double x = 0.0;
+    for (int i = 0; i <= n; ++i)
+    {
+        const double m = curve3 (mapAt (st.maps[12], x));
+        const double v = std::clamp (std::nearbyint (m * 8191.75), -32768.0, 32767.0);
+        t[i] = (std::int16_t) v;
+        const double l = std::log ((double) ((float) ((double) (i + 1) * step) * 2.0f + 1.0f));
+        x = (double) (float) (l * (double) 0.91023922f) * 0.5;
+    }
+    t[-1] = t[0];
+    t[n + 1] = t[n];
+}
+
+void Engine::Impl::saturate (float* e, int n, float dry, float wetGain, float sc) const noexcept
+{
+    const auto* t = satTable.data() + 1;
+    const int size = satSize;
+    wetGain = wetGain * 3.0517578125e-05f;
+    for (int k = 0; k < n; ++k)
+    {
+        const float x = e[k];
+        const float f = x * sc * (float) size;
+        int i = (int) std::rint (f);
+        const float fr = f - (float) i;
+        float y;
+        if (i >= 0)
+        {
+            i = std::min (i, size);
+            const float a = (float) t[i];
+            y = ((float) t[i + 1] - a) * fr + a;
+        }
+        else
+        {
+            const int j = std::min (-i, size);
+            const float a = (float) t[j];
+            y = -(a - ((float) t[j + 1] - a) * fr);
+        }
+        e[k] = y * wetGain + x * dry;
+    }
+}
+
+void Engine::Impl::clear() noexcept
+{
+    for (auto& B : bands)
+        for (int v = -unison; v < 2; ++v)
+        {
+            auto& u = B.voices[(std::size_t) (v + 4)];
+            for (auto& f : u.filters)
+                f.s = {};
+            u.peak.clear();
+            u.rms.clear();
+            for (auto& sm : u.smoother)
+                sm.y = 0.0;
+            u.last = 0.0f;
+        }
+    for (auto* filters : { &modHpFilters, &carLpFilters, &noiseHpFilters })
+        for (auto& f : *filters)
+            f.s = {};
+    for (auto& side : analysis)
+        for (auto& h : side)
+            h.clear();
+    for (auto& h : synthesis)
+        h.clear();
+    contourPeak.clear();
+    for (auto& sm : contourSmoother)
+        sm.y = 0.0;
+    consonantHp.s = {};
+    std::fill (zcRing.begin(), zcRing.end(), 0);
+    zcPos = zcCount = 0;
+    zcPrev = 0.0f;
+    fifoIn = {};
+    fifoOut = {};
+    fifoOut.pos = fifoFrames; // 16 zero frames queued: the Draft latency
+    seed = 0;
+    tailCount = 0;
+}
+
+void Engine::Impl::filterBand (Voice& u, int sig, int lvl, int n, double* out) noexcept
+{
+    if (u.oversample < 2)
+    {
+        const double* in = level[(std::size_t) sig][(std::size_t) lvl + 1].data();
+        for (int i = 0; i < order; ++i)
+        {
+            u.filters[(std::size_t) i].run64 (in, out, n);
+            in = out;
+        }
+    }
+    else // 2× copy, brought back by averaging pairs
+    {
+        const double* in = level[(std::size_t) sig][0].data();
+        double* t = tmp64b.data();
+        for (int i = 0; i < order; ++i)
+        {
+            u.filters[(std::size_t) i].run64 (in, t, 2 * n);
+            in = t;
+        }
+        for (int k = 0; k < n; ++k)
+        {
+            out[2 * k] = (t[4 * k] + t[4 * k + 2]) * 0.5;
+            out[2 * k + 1] = (t[4 * k + 1] + t[4 * k + 3]) * 0.5;
+        }
+    }
+}
+
+// acc[lv] (+)= a·b, or a·scale without b
+void Engine::Impl::accumulate (int lv, const double* a, const double* b, double scale, int n2) noexcept
+{
+    double* d = acc[(std::size_t) lv].data();
+    const bool first = ! touched[(std::size_t) lv];
+    if (b != nullptr)
+    {
+        if (first)
+            for (int k = 0; k < n2; ++k)
+                d[k] = a[k] * b[k];
+        else
+            for (int k = 0; k < n2; ++k)
+                d[k] = d[k] + a[k] * b[k];
+    }
+    else
+    {
+        if (first)
+            for (int k = 0; k < n2; ++k)
+                d[k] = a[k] * scale;
+        else
+            for (int k = 0; k < n2; ++k)
+                d[k] = d[k] + a[k] * scale;
+    }
+    touched[(std::size_t) lv] = true;
+}
+
+namespace
+{
+bool silent (const float* x, int n) noexcept
+{
+    for (int i = 0; i < n; ++i)
+        if (std::fabs (x[i]) > 9.99999997e-07f)
+            return false;
+    return true;
+}
+} // namespace
+
+void Engine::Impl::process (const float* own, const float* mod, const float* car, float* dst, int n) noexcept
+{
+    const auto& s = st;
+    const int fat = unison;
+
+    // tail bypass: both inputs silent for long enough → the own input passes and processing is frozen
+    if (tail != noTail)
+    {
+        if (! silent (car, 2 * n) || ! silent (mod, 2 * n))
+            tailCount = tail;
+        else
+            tailCount -= n;
+        if (tailCount <= -n)
+        {
+            if (dst != own)
+                std::memcpy (dst, own, 8 * (std::size_t) n);
+            snap = true;
+            return;
+        }
+    }
+
+    int m = n;
+    const float* C = car;
+    const float* M = mod;
+    if (draft)
+    {
+        m = fifoIn[0].push (car, carBuf.data(), n);
+        fifoIn[1].push (mod, modBuf.data(), n);
+        C = carBuf.data();
+        M = modBuf.data();
+    }
+    float* out = outBuf.data();
+
+    if (m > 0)
+    {
+        // contour
+        const float* cont = nullptr;
+        if (contour)
+        {
+            const float* src = nullptr;
+            float* cb = contourBuf.data();
+            float* mono_ = mono.data();
+            if (s.fromConsonants)
+            {
+                src = cb;
+                if (s.params[Param::freeze] == 0)
+                {
+                    for (int k = 0; k < m; ++k)
+                        mono_[k] = M[2 * k] + M[2 * k + 1];
+                    consonantHp.run32Mono (mono_, mono_, m);
+                    for (int k = 0; k < m; ++k)
+                        mono_[k] += zcOffset;
+                    for (int k = 0; k < m; ++k)
+                    {
+                        const float y = mono_[k];
+                        if (zcWindow <= ++zcPos)
+                            zcPos = 0;
+                        const int c = y * zcPrev < 0.0f;
+                        zcPrev = y;
+                        zcCount = (zcCount - zcRing[(std::size_t) zcPos]) + c;
+                        zcRing[(std::size_t) zcPos] = c;
+                        mono_[k] = (float) zcCount;
+                    }
+                    for (int k = 0; k < m; ++k)
+                    {
+                        float v = mono_[k] * 0.00625f;
+                        v = v * v;
+                        if (v > 1.0f)
+                            v = 1.0f;
+                        cb[2 * k] = cb[2 * k + 1] = v;
+                    }
+                }
+                else
+                    std::memset (cb, 0, 8 * (std::size_t) m);
+            }
+            if (s.fromCar)
+            {
+                if (src == nullptr)
+                    src = C;
+                else
+                    for (int k = 0; k < 2 * m; ++k)
+                        cb[k] = C[k] * cb[k];
+            }
+            for (int k = 0; k < m; ++k)
+            {
+                const float a = std::fabs (src[2 * k]), b = std::fabs (src[2 * k + 1]);
+                mono_[k] = a <= b ? b : a;
+            }
+            contourPeak.run (mono_, m);
+            for (int i = 0; i < contourStages; ++i)
+                contourSmoother[(std::size_t) i].run (mono_, m);
+            for (int k = 0; k < m; ++k)
+                cb[2 * k] = cb[2 * k + 1] = mono_[k];
+            cont = cb;
+        }
+
+        // carrier noise (band filters only)
+        const float* CA = C;
+        if (noiseAmp != 0.0f)
+        {
+            float* nz = noise.data();
+            randUniform (nz, 2 * m, -noiseAmp, noiseAmp, seed);
+            for (int i = 0; i < noiseHpCount; ++i)
+                noiseHpFilters[(std::size_t) i].run32 (nz, nz, m);
+            if (s.toNoise && cont != nullptr)
+                for (int k = 0; k < 2 * m; ++k)
+                    nz[k] = cont[k] * nz[k];
+            for (int k = 0; k < 2 * m; ++k)
+                nz[k] = C[k] + nz[k];
+            CA = nz;
+        }
+
+        // analysis levels
+        const float* sig[2] { CA, M };
+        for (int i = 0; i < 2; ++i)
+        {
+            auto& lv = level[(std::size_t) i];
+            analysis[(std::size_t) i][0].up (sig[i], x32a.data(), m);
+            for (int k = 0; k < 4 * m; ++k)
+                lv[0][(std::size_t) k] = (double) x32a[(std::size_t) k];
+            for (int k = 0; k < 2 * m; ++k)
+                lv[1][(std::size_t) k] = (double) sig[i][k];
+            const float* src = sig[i];
+            int len = m;
+            for (int j = 2; j <= levels; ++j)
+            {
+                len >>= 1;
+                analysis[(std::size_t) i][(std::size_t) j].down (src, x32b.data(), len);
+                for (int k = 0; k < 2 * len; ++k)
+                    lv[(std::size_t) j][(std::size_t) k] = (double) x32b[(std::size_t) k];
+                std::memcpy (x32a.data(), x32b.data(), 8 * (std::size_t) len);
+                src = x32a.data();
+            }
+        }
+
+        // bands
+        touched.fill (false);
+        float* e = env.data();
+        float* es = envSum.data();
+        float* t32 = tmp32.data();
+        double* ta = tmp64a.data();
+        double* tb = tmp64b.data();
+        for (int b = 0; b < bandCount; ++b)
+        {
+            auto& B = bands[(std::size_t) b];
+            const int lv = B.level, nb = m >> lv;
+            for (int v = -fat; v < 1; ++v)
+            {
+                auto& u = B.voices[(std::size_t) (v + 4)];
+                filterBand (u, 1, lv, nb, ta);
+                if (B.modPass != 0.0)
+                    accumulate (lv + 1, ta, nullptr, B.modPass, 2 * nb);
+                for (int k = 0; k < 2 * nb; ++k)
+                    t32[k] = (float) ta[k];
+                if (s.holdMode == 0)
+                {
+                    for (int k = 0; k < nb; ++k)
+                    {
+                        const float a = std::fabs (t32[2 * k]), c = std::fabs (t32[2 * k + 1]);
+                        e[k] = a <= c ? c : a;
+                    }
+                    u.peak.run (e, nb);
+                }
+                else
+                {
+                    for (int k = 0; k < nb; ++k)
+                    {
+                        const float a = t32[2 * k];
+                        float c = t32[2 * k + 1];
+                        c = c * c;
+                        e[k] = a * a + c;
+                    }
+                    u.rms.run (e, nb);
+                }
+                if (u.threshold != 0.0f)
+                {
+                    if (! s.subtractiveGate)
+                    {
+                        for (int k = 0; k < nb; ++k)
+                            if (e[k] < u.threshold)
+                                e[k] = 0.0f;
+                    }
+                    else
+                        for (int k = 0; k < nb; ++k)
+                        {
+                            e[k] += u.threshold;
+                            if (e[k] < 0.0f)
+                                e[k] = 0.0f;
+                        }
+                }
+                if (s.params[Param::freeze] == 0)
+                {
+                    if (B.saturate)
+                    {
+                        const double g4 = (double) u.gain * 0.25;
+                        saturate (e, nb, (float) (g4 * 4.0 * (1.0 - B.satMix)), (float) (4.0 * B.satMix), (float) g4);
+                    }
+                    for (int i = 0; i < u.stages; ++i)
+                        u.smoother[(std::size_t) i].run (e, nb);
+                    if (nb > 0)
+                        u.last = e[nb - 1];
+                }
+                else
+                    for (int k = 0; k < nb; ++k)
+                        e[k] = u.last;
+                if (v == -fat)
+                    for (int k = 0; k < nb; ++k)
+                    {
+                        es[2 * k] = e[k] * u.gainL;
+                        es[2 * k + 1] = e[k] * u.gainR;
+                    }
+                else
+                    for (int k = 0; k < nb; ++k)
+                    {
+                        es[2 * k] = e[k] * u.gainL + es[2 * k];
+                        es[2 * k + 1] = e[k] * u.gainR + es[2 * k + 1];
+                    }
+            }
+            if (B.offset != 0.0f)
+            {
+                for (int k = 0; k < 2 * nb; ++k)
+                    es[k] += B.offset;
+                if (B.offset < 0.0f)
+                    for (int k = 0; k < 2 * nb; ++k)
+                        if (es[k] < 0.0f)
+                            es[k] = 0.0f;
+            }
+            filterBand (B.voices[5], 0, lv, nb, ta);
+            for (int k = 0; k < 2 * nb; ++k)
+                tb[k] = (double) es[k];
+            accumulate (lv + 1, tb, ta, 0.0, 2 * nb);
+        }
+
+        // pass-through (written to the output base)
+        {
+            const float* c = C;
+            if (carPass != 0.0f || carPassNow != 0.0f)
+                for (int i = 0; i < carLpCount; ++i)
+                {
+                    carLpFilters[(std::size_t) i].run32 (c, carPassBuf.data(), m);
+                    c = carPassBuf.data();
+                }
+            if (snap)
+                carPassNow = carPass;
+            float start = 0.0f;
+            const float d = ramp (carPassNow, carPass, maxSlope, m, start);
+            if (d == 0.0f)
+            {
+                if (start == 0.0f)
+                    std::memset (out, 0, 8 * (std::size_t) m);
+                else if (start == 1.0f)
+                    std::memmove (out, c, 8 * (std::size_t) m);
+                else
+                    for (int k = 0; k < 2 * m; ++k)
+                        out[k] = c[k] * start;
+            }
+            else
+            {
+                rampGains (start, d, m, gains.data());
+                for (int k = 0; k < m; ++k)
+                {
+                    out[2 * k] = c[2 * k] * gains[(std::size_t) k];
+                    out[2 * k + 1] = c[2 * k + 1] * gains[(std::size_t) k];
+                }
+            }
+        }
+        auto addRamped = [&] (const float* src, float start, float d) {
+            if (d == 0.0f)
+            {
+                if (start != 0.0f)
+                {
+                    if (start == 1.0f)
+                        for (int k = 0; k < 2 * m; ++k)
+                            out[k] += src[k];
+                    else
+                        for (int k = 0; k < 2 * m; ++k)
+                            out[k] = src[k] * start + out[k];
+                }
+            }
+            else
+            {
+                rampGains (start, d, m, gains.data());
+                for (int k = 0; k < m; ++k)
+                {
+                    out[2 * k] = src[2 * k] * gains[(std::size_t) k] + out[2 * k];
+                    out[2 * k + 1] = src[2 * k + 1] * gains[(std::size_t) k] + out[2 * k + 1];
+                }
+            }
+        };
+        {
+            if (snap)
+                modPassNow = modPass;
+            if (modPass != 0.0f || modPassNow != 0.0f)
+            {
+                const float* mm = M;
+                float* mp = modPassBuf.data();
+                for (int i = 0; i < modHpCount; ++i)
+                {
+                    modHpFilters[(std::size_t) i].run32 (mm, mp, m);
+                    mm = mp;
+                }
+                if (s.toMod && cont != nullptr)
+                {
+                    if (mm != mp)
+                    {
+                        std::memcpy (mp, mm, 8 * (std::size_t) m);
+                        mm = mp;
+                    }
+                    for (int k = 0; k < 2 * m; ++k)
+                        mp[k] = cont[k] * mp[k];
+                }
+                float start = 0.0f;
+                const float d = ramp (modPassNow, modPass, maxSlope, m, start);
+                addRamped (mm, start, d);
+            }
+        }
+
+        // synthesis: the level sums from the coarsest one up
+        {
+            int len = m >> (levels - 1);
+            float* a = x32a.data();
+            float* b2 = x32b.data();
+            for (int j = levels; j >= 1; --j)
+            {
+                const double* d = acc[(std::size_t) j].data();
+                const bool t = touched[(std::size_t) j];
+                if (j == levels)
+                    for (int k = 0; k < 2 * len; ++k)
+                        a[k] = t ? (float) d[k] : 0.0f;
+                else
+                    for (int k = 0; k < 2 * len; ++k)
+                    {
+                        const float x = t ? (float) d[k] : 0.0f;
+                        a[k] = x + a[k];
+                    }
+                if (j > 1)
+                {
+                    synthesis[(std::size_t) j].up (a, b2, len);
+                    std::swap (a, b2);
+                    len <<= 1;
+                }
+            }
+            std::memcpy (voc.data(), a, 8 * (std::size_t) m);
+        }
+        {
+            if (snap)
+                wetNow = wet;
+            float start = 0.0f;
+            const float d = ramp (wetNow, wet, maxSlope, m, start);
+            addRamped (voc.data(), start, d);
+        }
+        snap = false;
+    }
+
+    if (draft)
+        fifoOut.pull (out, m, dst, n);
+    else
+        std::memcpy (dst, out, 8 * (std::size_t) n);
+}
+
+Engine::Engine() : impl (std::make_unique<Impl>()) {}
+Engine::~Engine() = default;
+
+void Engine::prepare (const State& state, double sampleRate, int maxBlockFrames, bool draftMode)
+{
+    auto& p = *impl;
+    p.st = state;
+    p.fs = sampleRate;
+    p.maxBlock = std::max (16, maxBlockFrames);
+    p.w0 = 2.0 * pi / sampleRate;
+    p.maxSlope = (float) (44.1 / sampleRate);
+    p.draft = draftMode;
+    p.levels = draftMode ? 5 : 1;
+    const auto& s = p.st;
+
+    p.wet = curve7 ((float) s.params[Param::wet] * 0.00100000005f);
+    p.carPass = (float) curve11 (s.params[carVol], 7.81249983e-05f);
+    p.contour = (s.toMod || s.toNoise) && (s.fromCar || s.fromConsonants);
+    p.modPass = (float) curve11 (s.params[modVol], 7.81249983e-05f);
+    if (s.toMod && s.fromCar)
+        p.modPass = s.params[Param::freeze] == 1 ? 0.0f : p.modPass * 4.0f;
+    p.noiseAmp = curve7 ((float) s.params[carNoise] * 7.81249983e-05f) * 0.5f;
+    if (s.toNoise && s.fromCar)
+        p.noiseAmp *= 4.0f;
+
+    p.setupBands();
+    p.setupPassFilters();
+    p.setupSaturation();
+    if (p.contour)
+    {
+        p.contourPeak.setup ((int) std::nearbyint (sampleRate * 0.012));
+        p.contourStages = setupSmoother (p.contourSmoother, sampleRate * 0.016, 3.0, sampleRate * 0.044, 3.0);
+        p.consonantHp = Biquad {};
+        p.consonantHp.f = 90.0f;
+        const double sn = std::sin ((double) p.consonantHp.f * p.w0);
+        p.consonantHp.lowHighPass (true, p.w0, sn / sn);
+        p.zcOffset = (float) std::exp ((double) (0.115129255f * -42.0f)); // 10^(−42/20)
+        p.zcWindow = std::max (1, (int) std::nearbyint (8.0 * 0.001 * sampleRate));
+        p.zcRing.assign ((std::size_t) p.zcWindow, 0);
+    }
+
+    const auto n = (std::size_t) p.maxBlock + 64;
+    for (auto& side : p.level)
+        for (auto& v : side)
+            v.assign (4 * n, 0.0);
+    for (auto& v : p.acc)
+        v.assign (4 * n, 0.0);
+    p.tmp64a.assign (4 * n, 0.0);
+    p.tmp64b.assign (4 * n, 0.0);
+    for (auto* v : { &p.tmp32, &p.x32a, &p.x32b })
+        v->assign (4 * n, 0.0f);
+    for (auto* v : { &p.env, &p.envSum, &p.voc, &p.outBuf, &p.modPassBuf, &p.carPassBuf, &p.noise, &p.contourBuf, &p.mono,
+                     &p.carBuf, &p.modBuf, &p.gains })
+        v->assign (2 * n, 0.0f);
+
+    p.tail = s.params[carNoise] == 0 && ! s.internalCarrier() ? (int) std::nearbyint (sampleRate * 0.5 + (double) p.tailMax + 16.0) : noTail;
+    p.clear();
+    p.snap = false;
+    p.wetNow = p.carPassNow = p.modPassNow = 0.0f; // FL fades the output in when the plugin is created
+}
+
+void Engine::flush() noexcept
+{
+    impl->clear();
+    impl->snap = true;
+}
+
+void Engine::process (const float* own, const float* mod, const float* car, float* out, int n) noexcept
+{
+    impl->process (own, mod, car, out, n);
+}
+
+int Engine::latencySamples() const noexcept { return impl->draft ? fifoFrames : 0; }
+int Engine::maxBlock() const noexcept { return impl->maxBlock; }
+
+// --- internal carrier --------------------------------------------------------------------------------------------------
+std::unique_ptr<Carrier> makeInternalCarrier (const State&)
+{
+    return nullptr; // no LYNX instrument plays the internal Sytrus carrier yet
+}
+
+// --- the effect --------------------------------------------------------------------------------------------------------
+namespace
+{
+class VocodexEffect final : public Effect
+{
+public:
+    static constexpr int chunk = 2048;
+
+    explicit VocodexEffect (const std::vector<std::uint8_t>& raw)
+        : state (parseState (raw))
+    {
+        if (state && state->internalCarrier())
+            carrier = makeInternalCarrier (*state);
+        if (state && state->params[sg] > 0)
+        {
+            sgSlots = soundgoodizerApproximation (0, state->params[sg]);
+            for (const auto& slot : sgSlots)
+                sgEffects.push_back (makeEffect (slot.kind));
+        }
+        for (auto* v : { &ownBuf, &modBuf, &carBuf, &outBuf, &zeros })
+            v->assign (2 * chunk, 0.0f);
+    }
+
+    void prepare (double sr) noexcept override
+    {
+        if (runsEngine())
+            engine.prepare (*state, sr, chunk, state->draft());
+        if (carrier != nullptr)
+            carrier->prepare (sr);
+        for (auto& e : sgEffects)
+            e->prepare (sr);
+    }
+
+    void reset() noexcept override
+    {
+        if (runsEngine())
+            engine.flush();
+        for (auto& e : sgEffects)
+            e->reset();
+    }
+
+    int latencySamples() const noexcept override
+    {
+        if (! runsEngine())
+            return 0;
+        auto latency = engine.latencySamples();
+        for (const auto& e : sgEffects)
+            latency += e->latencySamples(); // the Soundgoodizer's limiter look-ahead
+        return latency;
+    }
+
+    void setSidechain (const float* left, const float* right) noexcept override
+    {
+        side[0] = { left, right };
+        useSide[0] = true;
+    }
+    void setSidechain2 (const float* left, const float* right) noexcept override
+    {
+        side[1] = { left, right };
+        useSide[1] = true;
+    }
+
+    void process (float* l, float* r, int n, const EffectParams&, double bpm) noexcept override
+    {
+        const auto sides = side;
+        const auto used = useSide;
+        useSide = { false, false };
+        if (! state)
+            return;
+
+        for (int done = 0; done < n; done += chunk)
+        {
+            const int len = std::min (chunk, n - done);
+            float* L = l + done;
+            float* R = r + done;
+            auto interleave = [len] (const float* a, const float* b, std::vector<float>& to) {
+                for (int k = 0; k < len; ++k)
+                    to[(std::size_t) (2 * k)] = a[k], to[(std::size_t) (2 * k + 1)] = b[k];
+            };
+            // a side input (k > 0) that is routed gives that track's signal (silence when it is quiet); one that
+            // does not resolve to a track falls back to the own input
+            auto input = [&] (int index, int which, std::vector<float>& to) -> const float* {
+                if (index == 0 || ! used[(std::size_t) which])
+                    return ownBuf.data();
+                const auto& s = sides[(std::size_t) which];
+                if (s[0] == nullptr || s[1] == nullptr)
+                    return zeros.data();
+                interleave (s[0] + done, s[1] + done, to);
+                return to.data();
+            };
+            interleave (L, R, ownBuf);
+            const float* mod = nullptr;
+            const float* car = nullptr;
+            if (state->lrEncoding) // own input L → modulator, R → carrier (both channels)
+            {
+                for (int k = 0; k < len; ++k)
+                {
+                    modBuf[(std::size_t) (2 * k)] = modBuf[(std::size_t) (2 * k + 1)] = L[k];
+                    carBuf[(std::size_t) (2 * k)] = carBuf[(std::size_t) (2 * k + 1)] = R[k];
+                }
+                mod = modBuf.data();
+                car = carBuf.data();
+            }
+            else
+            {
+                mod = input (state->modIn, 0, modBuf);
+                if (state->carIn < 0)
+                {
+                    if (carrier == nullptr) // no internal carrier: the modulator passes
+                    {
+                        for (int k = 0; k < len; ++k)
+                            L[k] = mod[2 * k], R[k] = mod[2 * k + 1];
+                        continue;
+                    }
+                    carrier->render (carBuf.data(), len);
+                    car = carBuf.data();
+                }
+                else
+                    car = input (state->carIn, 1, carBuf);
+            }
+            engine.process (ownBuf.data(), mod, car, outBuf.data(), len);
+            for (int k = 0; k < len; ++k)
+                L[k] = outBuf[(std::size_t) (2 * k)], R[k] = outBuf[(std::size_t) (2 * k + 1)];
+        }
+        if (runsEngine())
+            for (std::size_t i = 0; i < sgEffects.size(); ++i)
+                sgEffects[i]->process (l, r, n, sgSlots[i].params, bpm);
+    }
+
+private:
+    bool runsEngine() const noexcept { return state && (! state->internalCarrier() || carrier != nullptr); }
+
+    std::optional<State> state;
+    Engine engine;
+    std::unique_ptr<Carrier> carrier;
+    std::vector<EffectSlot> sgSlots;
+    std::vector<std::unique_ptr<Effect>> sgEffects;
+    std::vector<float> ownBuf, modBuf, carBuf, outBuf, zeros;
+    std::array<std::array<const float*, 2>, 2> side {};
+    std::array<bool, 2> useSide { false, false };
+};
+} // namespace
+
+std::unique_ptr<Effect> make (const std::vector<std::uint8_t>& state)
+{
+    return std::make_unique<VocodexEffect> (state);
+}
+} // namespace lynx::vocodex

+ 93 - 0
src/core/Vocodex.h

@@ -0,0 +1,93 @@
+#pragma once
+
+// FL Studio's Vocodex, rebuilt from the behaviour decoded in docs/analise/REA_rodada35.md (clean-room; the reference
+// model matches the installation's engine to −137 dB or better on every demo instance). The effect keeps FL's raw
+// state (EffectSlot::state) and builds the whole engine from it: band layout and per-band maps, 64-bit band-pass
+// filter banks with 2× / octave-level multirate, PEAK/RMS followers, gate, saturation, smoother, unison, carrier
+// noise, consonant/carrier contour, pass-through and the gain ramps. Draft re-blocks into 16-frame chunks (16 samples
+// of latency, reported to PDC). The Soundgoodizer stage (SG > 0) is LYNX's Soundgoodizer approximation
+// (compressor + the presets' −0.2 dB master limiter, whose look-ahead adds to the latency).
+
+#include <array>
+#include <cstdint>
+#include <memory>
+#include <optional>
+#include <string>
+#include <vector>
+
+#include "core/Effects.h"
+
+namespace lynx::vocodex
+{
+// One of the 13 maps: points (x accumulated from the stored deltas, y) with straight segments
+struct Map
+{
+    std::vector<double> x, y;
+};
+
+enum Param { wet, sg, modVol, modHp, carVol, carLp, carNoise, carNoiseHp, hold, attack, attackCurve, release, releaseCurve,
+             freeze, bandWidth, flatness, modBandWidth, modPitch, unisonPitch, unisonPan, paramCount };
+
+// The saved state (REA_rodada35 §2.1, REA_rodada20 §4.2.1)
+struct State
+{
+    int version = 8;
+    std::array<Map, 13> maps;      // 0 gain, 1 pan, 2 gain offset, 3 gate, 4 mod pass, 5/6/7 hold/att/rel, 8 band
+                                   // distribution, 9 band width, 10 pitch, 11 saturation mix, 12 saturation curve
+    std::array<int, paramCount> params {};
+    int holdMode = 0;              // 0 PEAK, 1 RMS
+    int order = 2;                 // filter order K (1…4)
+    int unison = 0;                // extra analysis voices U (0…4)
+    int bands = 47;                // 5…100
+    int draftField = 1;            // 0 = Draft button on
+    int modIn = 0, carIn = 0;      // 0 = own input, k = k-th side input, CarIn < 0 = internal synth
+    bool lrEncoding = false, minTimes = true, toMod = false, threaded = true, subtractiveGate = true, toNoise = false,
+         fromCar = false, fromConsonants = false;
+    std::array<std::uint8_t, 13> mapAxis {}; // per map: 0 = read at the band frequency, 1 = at the pitch-shifted one
+    std::string tone;              // internal carrier synth preset
+    std::vector<int> notes;        // notes latched on the internal carrier's keyboard
+
+    bool draft() const noexcept { return draftField == 0; }
+    bool internalCarrier() const noexcept { return carIn < 0 && ! lrEncoding; }
+};
+
+std::optional<State> parseState (const std::vector<std::uint8_t>& bytes);
+
+// The vocoder engine. Signals are interleaved stereo; `process` handles at most `maxBlock` frames per call.
+class Engine
+{
+public:
+    Engine();
+    ~Engine();
+    Engine (const Engine&) = delete;
+    Engine& operator= (const Engine&) = delete;
+
+    // Builds bands, filters, followers and buffers (allocates). Gains start ramping from 0, as when FL creates it.
+    void prepare (const State& state, double sampleRate, int maxBlock, bool draft);
+    // FL's Flush: clears every filter / follower / FIFO and the noise seed; the gains snap to their targets
+    void flush() noexcept;
+    void process (const float* own, const float* mod, const float* car, float* out, int n) noexcept;
+
+    int latencySamples() const noexcept;
+    int maxBlock() const noexcept;
+
+private:
+    struct Impl;
+    std::unique_ptr<Impl> impl;
+};
+
+// Source of the internal carrier (CarIn < 0): renders interleaved stereo into `out`.
+class Carrier
+{
+public:
+    virtual ~Carrier() = default;
+    virtual void prepare (double sampleRate) = 0;
+    virtual void render (float* out, int n) noexcept = 0;
+};
+
+// The internal carrier synth (a Sytrus with the preset `<tone>.fst` and the state's notes held at volume 0.5,
+// REA_rodada35 §8). LYNX has no instrument for it yet: returns nullptr, and the effect then passes the modulator.
+std::unique_ptr<Carrier> makeInternalCarrier (const State& state);
+
+std::unique_ptr<Effect> make (const std::vector<std::uint8_t>& state);
+} // namespace lynx::vocodex

+ 10 - 1
src/engine/ProjectFile.cpp

@@ -129,6 +129,7 @@ const char* effectId (EffectKind k)
         case EffectKind::pitchCorrect: return "pitchCorrect";
         case EffectKind::squeeze: return "squeeze";
         case EffectKind::vintagePhaser: return "vintagePhaser";
+        case EffectKind::vocodex: return "vocodex";
     }
     return "eq";
 }
@@ -170,6 +171,8 @@ juce::var effectToVar (const EffectSlot& slot)
         e->setProperty ("sidechain", slot.sidechain);
     if (slot.sidechain2 >= 0)
         e->setProperty ("sidechain2", slot.sidechain2);
+    if (! slot.state.empty()) // FL's raw state of an exact effect (Vocodex), base64
+        e->setProperty ("state", juce::Base64::toBase64 (slot.state.data(), slot.state.size()));
 
     if (slot.kind == EffectKind::plugin)
         e->setProperty ("plugin", pluginToVar (slot.plugin));
@@ -230,6 +233,12 @@ std::optional<EffectSlot> effectFromVar (const juce::var& e)
     slot.plugin = pluginFromVar (e["plugin"]);
     slot.sidechain = juce::jlimit (-1, maxMixerTracks - 1, (int) e.getProperty ("sidechain", -1));
     slot.sidechain2 = juce::jlimit (-1, maxMixerTracks - 1, (int) e.getProperty ("sidechain2", -1));
+    if (e.hasProperty ("state"))
+    {
+        juce::MemoryOutputStream raw;
+        if (juce::Base64::convertFromBase64 (raw, e["state"].toString()))
+            slot.state.assign ((const std::uint8_t*) raw.getData(), (const std::uint8_t*) raw.getData() + raw.getDataSize());
+    }
 
     if (auto* branches = e["branches"].getArray())
         for (const auto& b : *branches)
@@ -262,7 +271,7 @@ std::optional<EffectSlot> effectFromVar (const juce::var& e)
 std::optional<EffectKind> effectFromId (const juce::String& id)
 {
     for (auto k : { EffectKind::eq, EffectKind::compressor, EffectKind::delay, EffectKind::reverb, EffectKind::plugin,
-                    EffectKind::limiter, EffectKind::filter, EffectKind::distortion, EffectKind::chorus, EffectKind::parametricEq, EffectKind::utility, EffectKind::volumeGate, EffectKind::peakController, EffectKind::pitchShift, EffectKind::freqShift, EffectKind::parallel, EffectKind::lofi, EffectKind::effector, EffectKind::crossover, EffectKind::rhythmGain, EffectKind::autoPan, EffectKind::vocoder, EffectKind::pitchCorrect, EffectKind::squeeze, EffectKind::vintagePhaser })
+                    EffectKind::limiter, EffectKind::filter, EffectKind::distortion, EffectKind::chorus, EffectKind::parametricEq, EffectKind::utility, EffectKind::volumeGate, EffectKind::peakController, EffectKind::pitchShift, EffectKind::freqShift, EffectKind::parallel, EffectKind::lofi, EffectKind::effector, EffectKind::crossover, EffectKind::rhythmGain, EffectKind::autoPan, EffectKind::vocoder, EffectKind::pitchCorrect, EffectKind::squeeze, EffectKind::vintagePhaser, EffectKind::vocodex })
         if (id == effectId (k))
             return k;
 

+ 1 - 1
src/ui/MixerComponent.cpp

@@ -1258,7 +1258,7 @@ void EffectsPanel::showSlotMenu (int slot)
     };
     if (kind == EffectKind::compressor)
         sideMenu ("Sidechain from", false);
-    if (kind == EffectKind::vocoder)
+    if (kind == EffectKind::vocoder || kind == EffectKind::vocodex)
     {
         sideMenu ("Modulator from", false);
         sideMenu ("Carrier from", true);

+ 209 - 0
tests/tests.cpp

@@ -32,6 +32,7 @@
 #include "core/SoftClip.h"
 #include "core/Slicer.h"
 #include "core/Templates.h"
+#include "core/Vocodex.h"
 #include "core/TimeStretch.h"
 #include "core/WorkerPool.h"
 #include "core/Song.h"
@@ -4829,6 +4830,214 @@ TEST (vocoder_follows_modulator)
         CHECK (l[i] == r[i] && std::isfinite (l[i]));    // mono output
 }
 
+// Vocodex (REA_rodada35): a synthetic state in FL's layout (version 8, 13 maps, 20 parameters, the 0x24 block,
+// 13 map-axis bytes, tone, notes)
+struct VocodexSpec
+{
+    // Wet, SG, ModVol, ModHP, CarVol, CarLP, CarNoise, CarNoiseHP, Hold, Att, AttCurve, Rel, RelCurve, Freeze, BW,
+    // Flatness, ModBW, ModPitch, FatPitch, FatPan
+    std::array<std::int32_t, 20> params { 1000, 0, 0, 0, 0, 65536, 0, 0, 0, 2000, 0, 3000, 0, 0, 1000, 0, 2000, 0, 0, 0 };
+    std::array<std::int32_t, 7> block { 0, 2, 0, 24, 1, 1, 2 }; // hold mode, order, unison, bands, draft field, ModIn, CarIn
+    std::array<std::uint8_t, 8> flags { 0, 1, 0, 1, 1, 0, 0, 0 }; // L-R, MIN TIMES, TO MOD, THREADED, subtractive, TO NOISE, FROM CAR, FROM CONS
+
+    std::vector<std::uint8_t> bytes() const
+    {
+        std::vector<std::uint8_t> d;
+        auto put = [&d] (const void* p, std::size_t n) { d.insert (d.end(), (const std::uint8_t*) p, (const std::uint8_t*) p + n); };
+        auto i32 = [&] (std::int32_t v) { put (&v, 4); };
+        i32 (8 << 16);
+        for (int m = 0; m < 13; ++m)
+        {
+            const double y0 = m == 8 ? 0.1429 : (m == 3 || m == 4 || m == 11) ? 0.0 : 0.5;
+            const double y1 = m == 8 ? 0.9918 : y0;
+            i32 (1), i32 (0), i32 (2);
+            for (const auto& [dx, y] : { std::pair { 0.0, y0 }, std::pair { 1.0, y1 } })
+            {
+                put (&dx, 8), put (&y, 8);
+                i32 (0), i32 (0); // tension (f32 0), flags
+            }
+            const std::array<std::uint8_t, 20> tail {};
+            put (tail.data(), tail.size());
+        }
+        for (auto v : params)
+            i32 (v);
+        for (auto v : block)
+            i32 (v);
+        put (flags.data(), flags.size());
+        const std::array<std::uint8_t, 13> axis {};
+        put (axis.data(), axis.size());
+        d.push_back (3), put ("PWM", 3);
+        i32 (1), i32 (60);
+        return d;
+    }
+};
+
+std::vector<float> vocodexSaw (int n, double hz, double fs)
+{
+    std::vector<float> out ((std::size_t) n);
+    for (int i = 0; i < n; ++i)
+        out[(std::size_t) i] = (float) (2.0 * std::fmod (i * hz / fs, 1.0) - 1.0) * 0.4f;
+    return out;
+}
+
+TEST (vocodex_state_parse_and_conversion)
+{
+    VocodexSpec spec;
+    spec.block = { 1, 3, 2, 40, 0, 2, 1 };
+    spec.params[17] = -1200;
+    const auto raw = spec.bytes();
+    const auto s = lynx::vocodex::parseState (raw);
+    CHECK (s.has_value());
+    if (! s)
+        return;
+    CHECK (s->version == 8 && s->holdMode == 1 && s->order == 3 && s->unison == 2 && s->bands == 40);
+    CHECK (s->draft() && s->modIn == 2 && s->carIn == 1 && s->minTimes && s->subtractiveGate && ! s->lrEncoding);
+    CHECK (s->params[lynx::vocodex::modPitch] == -1200 && s->params[lynx::vocodex::carLp] == 65536);
+    CHECK (s->maps[8].x.size() == 2 && std::abs (s->maps[8].y[1] - 0.9918) < 1e-12 && s->maps[8].x[1] == 1.0);
+    CHECK (s->tone == "PWM" && s->notes.size() == 1 && s->notes[0] == 60);
+
+    const auto v = lynx::vocodexEffect (raw);
+    CHECK (v && v->slot.kind == lynx::EffectKind::vocodex && v->slot.state == raw && v->modIn == 2 && v->carIn == 1 && v->notes.empty());
+    spec.block[6] = -1; // internal synth carrier: not available yet → reported
+    spec.params[1] = 150; // Soundgoodizer stage
+    const auto w = lynx::vocodexEffect (spec.bytes());
+    CHECK (w && w->carIn == -1 && w->notes.size() == 2);
+    CHECK (! lynx::vocodex::parseState ({ 1, 2, 3 }).has_value());
+}
+
+TEST (vocodex_vocodes_side_inputs)
+{
+    // modulator on side input 1 (noise in the first half), carrier on side input 2 (saw), own input silent: the
+    // output follows the modulator's envelope and fades after it stops
+    VocodexSpec spec;
+    lynx::EffectSlot slot = lynx::makeEffectSlot (lynx::EffectKind::vocodex);
+    slot.state = spec.bytes();
+    auto fx = lynx::makeEffect (slot);
+    fx->prepare (48000.0);
+    CHECK (fx->latencySamples() == 0);
+    const auto car = vocodexSaw (48000, 110.0, 48000.0);
+    std::vector<float> mod (48000), l (48000, 0.0f), r (48000, 0.0f);
+    std::uint32_t seed = 7;
+    for (std::size_t i = 0; i < mod.size(); ++i)
+    {
+        seed = seed * 1664525u + 1013904223u;
+        mod[i] = i < 24000 ? ((float) (seed >> 8) / 16777216.0f - 0.5f) : 0.0f;
+    }
+    for (int done = 0; done < 48000; done += 512)
+    {
+        const int n = std::min (512, 48000 - done);
+        fx->setSidechain (mod.data() + done, mod.data() + done);
+        fx->setSidechain2 (car.data() + done, car.data() + done);
+        fx->process (l.data() + done, r.data() + done, n, slot.params, 120.0);
+    }
+    auto rms = [&] (int from, int to) {
+        double e = 0.0;
+        for (int i = from; i < to; ++i)
+            e += (double) l[(std::size_t) i] * l[(std::size_t) i] + (double) r[(std::size_t) i] * r[(std::size_t) i];
+        return std::sqrt (e / (2.0 * (to - from)));
+    };
+    CHECK (rms (6000, 20000) > 0.02);
+    CHECK (rms (40000, 48000) < 0.01 * rms (6000, 20000));
+    CHECK (std::abs (l[0]) < 1e-6f); // the gains ramp up from 0 when the plugin is created
+}
+
+TEST (vocodex_draft_latency_and_pass_through)
+{
+    // carrier pass-through at unit gain only (Wet 0): after a Flush the gains snap, so the output is the carrier,
+    // 16 samples late in Draft
+    VocodexSpec spec;
+    spec.params[0] = 0;      // Wet
+    spec.params[4] = 12800;  // CarVol = 1
+    for (const int draftField : { 1, 0 })
+    {
+        spec.block[4] = draftField;
+        const auto s = lynx::vocodex::parseState (spec.bytes());
+        CHECK (s.has_value());
+        lynx::vocodex::Engine engine;
+        engine.prepare (*s, 44100.0, 300, s->draft());
+        CHECK (engine.latencySamples() == (draftField == 0 ? 16 : 0));
+        engine.flush();
+        const auto saw = vocodexSaw (3000, 220.0, 44100.0);
+        std::vector<float> car (6000), mod (6000, 0.0f), out (6000);
+        for (int i = 0; i < 3000; ++i)
+            car[(std::size_t) (2 * i)] = car[(std::size_t) (2 * i + 1)] = saw[(std::size_t) i];
+        static constexpr int sizes[] { 300, 37, 128, 1, 255, 16, 299 }; // uneven blocks exercise the FIFOs
+        for (int done = 0, k = 0, n = 0; done < 3000; done += n, ++k)
+        {
+            n = std::min (sizes[k % 7], 3000 - done);
+            engine.process (mod.data() + 2 * done, mod.data() + 2 * done, car.data() + 2 * done, out.data() + 2 * done, n);
+        }
+        const int lag = engine.latencySamples();
+        auto maxError = 0.0f;
+        for (int i = lag; i < 3000; ++i)
+            maxError = std::max (maxError, std::abs (out[(std::size_t) (2 * i)] - saw[(std::size_t) (i - lag)]));
+        CHECK (maxError == 0.0f);
+    }
+}
+
+TEST (vocodex_soundgoodizer_stage_limits_the_output)
+{
+    // SG > 0: the vocoder's output (loud here: Wet 2000) goes through the Soundgoodizer approximation, whose
+    // master limiter keeps the peaks under −0.2 dBFS; its look-ahead is reported as latency
+    VocodexSpec spec;
+    spec.params[0] = 2000;
+    spec.params[1] = 250;
+    lynx::EffectSlot slot = lynx::makeEffectSlot (lynx::EffectKind::vocodex);
+    slot.state = spec.bytes();
+    auto fx = lynx::makeEffect (slot);
+    fx->prepare (48000.0);
+    CHECK (fx->latencySamples() == 72); // 1.5 ms at 48 kHz
+    const auto car = vocodexSaw (48000, 110.0, 48000.0);
+    std::vector<float> mod (48000), l (48000, 0.0f), r (48000, 0.0f);
+    for (std::size_t i = 0; i < mod.size(); ++i)
+        mod[i] = 0.9f * (float) std::sin (0.07 * (double) i) * (float) std::sin (0.0003 * (double) i);
+    auto peak = 0.0f;
+    for (int done = 0; done < 48000; done += 512)
+    {
+        const int n = std::min (512, 48000 - done);
+        fx->setSidechain (mod.data() + done, mod.data() + done);
+        fx->setSidechain2 (car.data() + done, car.data() + done);
+        fx->process (l.data() + done, r.data() + done, n, slot.params, 120.0);
+    }
+    for (std::size_t i = 0; i < l.size(); ++i)
+        peak = std::max ({ peak, std::abs (l[i]), std::abs (r[i]) });
+    CHECK (peak > 0.5f && peak <= 0.9775f);
+}
+
+TEST (vocodex_tail_bypass_and_noise)
+{
+    // both inputs silent for longer than 0.5 s + hold + release: the own input passes unchanged
+    VocodexSpec spec;
+    const auto s = lynx::vocodex::parseState (spec.bytes());
+    CHECK (s.has_value());
+    lynx::vocodex::Engine engine;
+    engine.prepare (*s, 44100.0, 512, false);
+    std::vector<float> zero (1024, 0.0f), own (1024), out (1024);
+    for (std::size_t i = 0; i < own.size(); ++i)
+        own[i] = 0.25f * (float) std::sin (0.01 * (double) i);
+    for (int b = 0; b < 80; ++b)
+        engine.process (own.data(), zero.data(), zero.data(), out.data(), 512);
+    CHECK (out == own);
+
+    // carrier noise: the IPP-compatible generator restarts from the same seed after a Flush
+    spec.params[6] = 9000;
+    const auto noisy = lynx::vocodex::parseState (spec.bytes());
+    lynx::vocodex::Engine a;
+    a.prepare (*noisy, 44100.0, 512, false);
+    std::vector<float> mod (1024), first (1024), second (1024);
+    for (std::size_t i = 0; i < mod.size(); ++i)
+        mod[i] = 0.3f * (float) std::sin (0.05 * (double) i);
+    a.flush();
+    a.process (own.data(), mod.data(), zero.data(), first.data(), 512);
+    a.flush();
+    a.process (own.data(), mod.data(), zero.data(), second.data(), 512);
+    CHECK (first == second);
+    auto energy = 0.0;
+    for (auto v : first)
+        energy += (double) v * v;
+    CHECK (energy > 1e-6 && std::isfinite (energy));
+}
+
 TEST (synth_spectral_oscillator)
 {
     // 1/n spectrum = saw: same harmonic proportions and same level as LYNX's saw

+ 97 - 0
tools/vocodexrender.cpp

@@ -0,0 +1,97 @@
+// Runs LYNX's Vocodex engine (core/Vocodex.h) on raw signals, for comparison with the REA round-35 reference model.
+// Usage: vocodexrender <state.bin> <mod.f32> <car.f32|-> <own.f32|-> <out.f32> <fs> <block> [modk=1] [cark=2] [draft=0|1]
+// mod/car/own: interleaved stereo float32. `mod` arrives on side input `modk`, `car` on `cark`, `own` is the track's
+// own input; the state's ModIn/CarIn select among them (0 = own input, CarIn < 0 = internal synth → silence).
+// The Soundgoodizer stage is not applied (the engine only).
+
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <fstream>
+#include <iterator>
+#include <vector>
+
+#include "core/Vocodex.h"
+
+namespace
+{
+std::vector<float> readF32 (const char* path)
+{
+    std::ifstream in (path, std::ios::binary);
+    std::vector<char> bytes ((std::istreambuf_iterator<char> (in)), std::istreambuf_iterator<char>());
+    std::vector<float> out (bytes.size() / sizeof (float));
+    std::memcpy (out.data(), bytes.data(), out.size() * sizeof (float));
+    return out;
+}
+} // namespace
+
+int main (int argc, char** argv)
+{
+    if (argc < 8)
+    {
+        std::fprintf (stderr, "usage: vocodexrender state.bin mod.f32 car.f32|- own.f32|- out.f32 fs block [modk=1 cark=2 draft=0|1]\n");
+        return 1;
+    }
+    std::ifstream stateFile (argv[1], std::ios::binary);
+    const std::vector<std::uint8_t> raw ((std::istreambuf_iterator<char> (stateFile)), std::istreambuf_iterator<char>());
+    const auto state = lynx::vocodex::parseState (raw);
+    if (! state)
+    {
+        std::fprintf (stderr, "not a Vocodex state\n");
+        return 1;
+    }
+    const auto mod = readF32 (argv[2]);
+    const auto car = std::strcmp (argv[3], "-") != 0 ? readF32 (argv[3]) : std::vector<float> {};
+    const auto own = std::strcmp (argv[4], "-") != 0 ? readF32 (argv[4]) : std::vector<float> {};
+    const int fs = std::atoi (argv[6]), block = std::atoi (argv[7]);
+    int modk = 1, cark = 2, draft = -1;
+    for (int i = 8; i < argc; ++i)
+    {
+        char key[64];
+        int value = 0;
+        if (std::sscanf (argv[i], "%63[^=]=%d", key, &value) == 2)
+        {
+            if (std::strcmp (key, "modk") == 0)
+                modk = value;
+            else if (std::strcmp (key, "cark") == 0)
+                cark = value;
+            else if (std::strcmp (key, "draft") == 0)
+                draft = value;
+        }
+    }
+
+    lynx::vocodex::Engine engine;
+    engine.prepare (*state, fs, block, draft >= 0 ? draft != 0 : state->draft());
+    const auto frames = (long) mod.size() / 2;
+    std::vector<float> out ((std::size_t) frames * 2), zero ((std::size_t) block * 2), lm (zero.size()), lc (zero.size());
+    for (long n0 = 0; n0 < frames; n0 += block)
+    {
+        const int len = (int) std::min<long> (block, frames - n0);
+        const float* m = mod.data() + 2 * n0;
+        const float* c = car.empty() ? zero.data() : car.data() + 2 * n0;
+        const float* o = own.empty() ? zero.data() : own.data() + 2 * n0;
+        const float *mm, *cc;
+        if (state->lrEncoding)
+        {
+            for (int k = 0; k < len; ++k)
+            {
+                lm[(std::size_t) (2 * k)] = lm[(std::size_t) (2 * k + 1)] = o[2 * k];
+                lc[(std::size_t) (2 * k)] = lc[(std::size_t) (2 * k + 1)] = o[2 * k + 1];
+            }
+            mm = lm.data(), cc = lc.data();
+        }
+        else
+        {
+            auto pick = [&] (int index) { return index == 0 ? o : index == modk ? m : index == cark ? c : o; };
+            mm = pick (state->modIn);
+            cc = state->carIn < 0 ? zero.data() : pick (state->carIn);
+        }
+        engine.process (o, mm, cc, out.data() + 2 * n0, len);
+    }
+    std::FILE* f = std::fopen (argv[5], "wb");
+    if (f == nullptr)
+        return 1;
+    std::fwrite (out.data(), sizeof (float), out.size(), f);
+    std::fclose (f);
+    return 0;
+}