Browse Source

Harmless: effects rack (chorus, delay, reverb, Maximus compressor) from REA round 36

- docs/analise/REA_rodada36.md: Harmless's rack decoded (fixed chorus/delay/reverb records of FL's
  shared DSP library and Reverb_x64.dll; the compressor is the hosted SG_x64.dll loaded with
  Harmless/Data/Compression/<n>.fst, i.e. FL's Maximus engine, decoded for everything those presets
  use). Model incl. rack within -60 dB of the DLL on 135 of 139 demo channels; Harmor shares the units.
- core/HarmlessFx: C++ port (within -98 dB of the reference model, most units -129 dB or exact);
  Harmless runs it on the float voice mix in FL's order and keeps rendering the rack tail.
- Import reads the compression preset from the user's FL installation (report entry when missing).
- Tests: harmless_rack (goldens from the reference model, our own Maximus states), real-file check.
Kauan 1 month ago
parent
commit
4cdae71fb7

+ 1 - 0
CMakeLists.txt

@@ -35,6 +35,7 @@ add_library(lynx_core STATIC
     src/core/PhysicalModels.cpp
     src/core/DrumSynthLive.cpp
     src/core/Harmless.cpp
+    src/core/HarmlessFx.cpp
     src/core/VintagePhaser.cpp
     src/core/FlPatcher.cpp
     src/core/Inflate.cpp

+ 15 - 5
docs/STATUS.md

@@ -57,7 +57,9 @@ exports the 30 demo projects shipped with FL Studio 2026.
   engine (REA round 30: all 120 patches, one per key, morph, voice modes; recorded waves read from the user's own FL
   installation; within −138 dB of the reference model verified against FL's DLLs); Harmless on its additive engine
   (REA round 32: 528-partial bank, FL's full voice; within −151 dB of the reference model, which is within −60 dB of
-  FL's DLL on 135 of 139 demo channels); Sytrus, Harmor, GMS, Kepler, Ogun/Autogun, MiniSynth, DX10, Fruit Kick, Toxic Biohazard,
+  FL's DLL on 135 of 139 demo channels) and its effects rack (REA round 36: chorus, delay, reverb and the Maximus
+  compressor with Harmless's own presets read from the user's FL installation; the model with the rack is within −60 dB
+  of the DLL on 135 of 139 demo channels); Sytrus, Harmor, GMS, Kepler, Ogun/Autogun, MiniSynth, DX10, Fruit Kick, Toxic Biohazard,
   Morphine, PoiZone and BassDrum on the built-in synth; Sakura and Drumpad on physical models rebuilt from their
   engines (REA round 28), BooBass on its engine with the multisample read from the user's own FL installation
   (REA round 29; within −138 dB of the reference renders verified against FL's DLLs).
@@ -95,8 +97,13 @@ accordingly. Highlights of what is **confirmed and applied**:
   volume envelope with FL's smoothers and the 30 ms end/steal fade, all LFO shapes (global/retriggered, attack),
   6 Hz vibrato, stereo tremolo, unison (detune tables, pan, phase, attack, LFO offsets), portamento/mono/legato,
   grittiness, both phase-randomness modes; FL's level law (`0.75·(3^x − 1)/2`·Final.Vol·unison gain through the
-  cos/sin pan law, channel volume applied once). The old synth approximation remains for unreadable states and for
-  the synth's "FL presets" button.
+  cos/sin pan law, channel volume applied once). Its effects rack (`core/HarmlessFx.cpp`, REA round 36) runs on the
+  voice mix in FL's order: chorus (8 records of FL's chorus library, ⌊D⌋ taps), delay (normal / ping-pong with stereo
+  offsets, tempo-synced time, feedback ramp), reverb (FL's shared plate reverb with 6 records) and the compressor =
+  FL's Maximus engine (low cut, ×2 oversampling, Linkwitz–Riley crossovers, peak-window detector, √-scaled attack /
+  release / release-2 stages, drawn-curve gain tables with tensions, lookahead, saturation, band mix) loaded with
+  `Harmless/Data/Compression/<n>.fst` from the user's installation. The old synth approximation remains for unreadable
+  states and for the synth's "FL presets" button.
 - **Ogun:** exact initial spectrum of the timbre engine (seeded IPP-style generator, fullness/morph/pre-decay
   weights, Forced/Impulse maps and patterns, RMS normalisation, fixed seed-3 phases) on the spectral oscillator,
   with each partial's own decay `(t − 0.025)·B·E_dec + 0.025` (the spectrum evolves during the note); cutoff `44100·(c + c₀)` Hz, FL's Q/width, 20 s release, unison ±5(11^(P15/256) − 1) cents.
@@ -149,8 +156,11 @@ accordingly. Highlights of what is **confirmed and applied**:
   ×10 (Exo only); a synced LFO1 is locked to the song position at note start (FL runs it from the host's beat delta);
   old (version < 4) synced states use the stored rate, as FL's engine right after loading (whether FL re-sends the
   converted rate is not confirmed).
-- Harmless: the effects rack (chorus/delay/reverb/compressor) is not decoded and stays off (its compressor holds FL's
-  demo peaks near 0.976; without it LYNX's output can reach full scale); the editor's quality
+- Harmless: the rack compressor needs the user's FL installation (its four presets are read from it; otherwise it
+  stays off and the import report says so); the chorus/delay use the x87 kernels FL picks on the test machine (another
+  CPU may make FL round the chorus delay instead of truncating it — not confirmed); a fresh delay starts its feedback
+  ramp at the stored value (FL's host call order not observed); Maximus features unused by the presets (RMS detector,
+  saturation B, other curve segment types, linear-phase mode) are not decoded; the editor's quality
   (0/1) is used for playback and export alike (FL renders with quality 2; LYNX's engine does not tell instruments
   when it renders offline); FL seeds its random draws from the clock, LYNX from a fixed seed (spectral-random
   phases, Noise resonance and the LFO "voice random" are deterministic and differ from any FL render by design);

+ 432 - 0
docs/analise/REA_rodada36.md

@@ -0,0 +1,432 @@
+# Behavioural analysis of FL Studio 2026: round 36 (REA) — Harmless: the effects rack (chorus, delay, reverb, compressor = Maximus)
+
+> **Nature of this document.** Continuation of `REA_rodada32.md` §1.20 (Harmless, effects rack "not decoded"), with
+> material shared with `REA_rodada31.md` §7 (Sytrus post-voice chain: same chorus/delay library, same shared reverb
+> DLL), `REA_rodada8.md` §1–2 (Maximus/Soundgoodizer state format) and `REA_rodada35.md` §7 (Vocodex hosts the same
+> Soundgoodizer DLL). *Clean-room* reverse engineering, behavioural only. No Image-Line code or pseudocode was copied:
+> what is here are data layouts, formulas and behaviours described in our own words. Addresses (`FUN_xxxxxxxx`),
+> offsets and globals serve only to trace the evidence. No FLEX pack was opened; no Image-Line preset or audio data was
+> copied into the repository (Harmless's four compression presets are read at run time from the user's installation;
+> the tests use Maximus states we built ourselves).
+>
+> **Rule for this round (user request): no speculation.** Every value comes from decompilation (**[DECOMP]**), from
+> the official Image-Line manual (**[DOC]**, with URL), from the data (**[DATA]**) or from running the installation's
+> own DLLs, unmodified (**[EXEC]**). Where there was not enough evidence, the item is marked **"not confirmed"**.
+> Inferences are stated explicitly as **inference**. Results of our own numerical models (which implement only what is
+> marked DECOMP/EXEC) are marked **[model]**.
+
+| Marker | Meaning |
+|---|---|
+| **[DECOMP]** | read in the decompiled/disassembled code |
+| **[DOC]** | official Image-Line manual (URL cited) |
+| **[DATA]** | checked in `.flp`/`.fst`/installation files, or a table read from a DLL's data section |
+| **[EXEC]** | result obtained by running the installation's own DLL (without modifying it) |
+| **[model]** | output of our own model, which only implements DECOMP/EXEC facts |
+| **not confirmed** | not enough evidence in this round |
+
+- **Date:** 2026-10-14. Scratch directory (paths below are relative to it): `/home/kauan/.claude/jobs/f8789b49/tmp/`.
+- **Targets** (hashed in this round):
+
+  | Module | File (SHA-256) | Language | Key functions |
+  |---|---|---|---|
+  | Harmless | `Plugins/Fruity/Generators/Harmless/Harmless_x64.dll` `4100bf85ad29dc665051a73ef62017272a25aefbda1cf2f1ace39e6be376440b` (= rounds 10/21/24/27/32) | Delphi | Gen_Render `FUN_007886b0`; ProcessParam `FUN_0077f630` (cases 0x5a…0x62); rack set-ups: chorus `FUN_00789570`, delay `FUN_00789080`, reverb `FUN_00789280`, compressor `FUN_00789800`; library: chorus `FUN_0074a790` (ctor), `FUN_0074a9b0` (set-up), `FUN_0074b0b0` (phase advance), `FUN_0074b0f0` (ring write), `FUN_0074b2f0` / `FUN_0074b180` / `FUN_0074b230` (x87 taps), `FUN_0074b7e0` / `FUN_0074b440` / `FUN_0074b600` (SSE taps); delay `FUN_007471d0` (ctor), `FUN_00747070`/`FUN_00747010` (ring), `FUN_00747510` (input add), `FUN_007475a0` / `FUN_007477f0` (x87 normal / ping-pong), `FUN_007481f0` / `FUN_007484b0` (SSE twins); reverb wrapper `FUN_0074a360`, `FUN_00749540` (loads the shared DLL), `FUN_00749b60` (coefficients), `FUN_0074a540` (process); ramp `FUN_00612db0`; hosted-plugin loader `FUN_0076f2c0`, preset loader `FUN_0076f7f0`, data-file request `FUN_0073f1e0` |
+  | Shared reverb | `Shared/Reverb_x64.dll` `9881ff2ccd74227e454a3d5f1912568f4336abe06e68f3693162aa4d251c969f` (= round 31) | C++ (MSVC) | process `FUN_180002980` (round 31 §7.5) |
+  | Soundgoodizer | `Shared/SG_x64.dll` `ad567e65e2aac8314d23f2322f4d17e1b5529a09f64c43d596189582f006f6ac` (= round 35) | Delphi (`TTestPlug`, VMT `0x83e4d8`) | CreatePlugInstance `0x83e620`; VMT slots 1 Dispatcher `FUN_0083e670`, 3 SaveRestoreState `FUN_0083ef50`, 6 ProcessParam `FUN_00841b40`, **7 Eff_Render `FUN_00843a40`**; set-ups `FUN_00844e10` (crossover), `FUN_00840c80` (times), `FUN_008417e0` (modes), `FUN_00841380` (saturation), `FUN_00845b50` (curve → gain table), `FUN_00840b40` + `FUN_0083a5c0` (low cut), `FUN_00847ce0` (oversampling), `FUN_00845940` (reset), `FUN_00840a00` (latency); kernels `FUN_00624580` (biquad design), `FUN_00624e90` (biquad), `FUN_00628b80` (stereo matrix), `FUN_00605410` (control smoother), `FUN_00629710` + `FUN_007806b0` (peak detector), `FUN_0077f350` (lookahead delay), `FUN_0062a240` (saturation A), `FUN_0083a9c0` / `FUN_0083ab90` (2:1 up/down), `FUN_00627cc0` (state rounding), `FUN_00629890` (silence test); envelope `FUN_007876c0` (iterator start), `FUN_007885d0` (step/evaluate), point preparation in `FUN_00785xxx` (`0x7854f0`…) and `FUN_0060dfd0` (tension record) |
+  | Compression presets | `Plugins/Fruity/Generators/Harmless/Data/Compression/1.fst` `3dc934f3…4d74`, `2.fst` `5224cc29…eb12`, `3.fst` `b9c7ad76…a5a`, `4.fst` `1cb33a3b…73b9` | FL preset (Maximus state) | read in place [DATA] |
+  | Harmor (comparison only, §4) | `Plugins/Fruity/Generators/Harmor/Harmor_x64.dll` `23673ad84b11321c8133084e61ae53c3aa72e437586295083c3a06dd499d5aba` | Delphi | byte search only (no decompilation in this round) |
+
+- **Tools:** Ghidra 12.1.4 headless with a new project `/tmp/r36gh_SG` for `SG_x64.dll` (automatic analysis;
+  dumps `r36/out/sg_plug.c` = `0x82c000…0x864000`, `sg_rec.c` (recursive from the VMT slots), `sg_env.c`
+  (`0x781000…0x78b000`), `sg_rt.c`, `sg_rt2.c`, `sg_f2.c`, `sg_f3.c`, `sg_lc.c`, `sg_t.c`); the round-32 Harmless dump
+  `r32/out/plug_all.c` plus `r36/out/d1.c` (functions outside it, from `/tmp/r32gh_H`); round 31's reverb dump
+  `r31/out/rev_all.c`; `objdump` for x87/SSE details; constants with `r18/k.py`; IPP names with `r27/py/ippmap.py`
+  (Harmless) and our `r36/py/ippsg.py` (SG's dispatcher `FUN_005bbf20`, dump `r36/out/sg_ipp.c`); `r36/py/fn.py`
+  (function extractor).
+- **EXEC harnesses** (our own C, Zig 0.14.1 → Windows x64; `SetErrorMode` first, vectored fault handler,
+  `TerminateProcess` at the end, `timeout`; nothing was left running):
+  - `r36/run/hl36.c` → `hl36.exe`: the round-32 Harmless harness plus (a) **answers to the host's data-file requests**
+    (dispatcher query `0x47` returns an interface whose method 6, request `0x3fc`, returns the installation path of the
+    requested `Harmless\Data\…` file; dispatcher `0x1d` returns the plugin folder), (b) peeks `fp=` (run-time function
+    pointers), `gd=` (globals), `pb=` (a byte behind a pointer). Without (a) the plugin cannot open its compression
+    preset and the hosted Soundgoodizer keeps its own default state — **the "peaks near 0.976" measured before this round
+    came from that default state, not from Harmless's presets** (EXEC: preset 2 on a test patch peaks at 0.880 with the
+    file answered, 0.976 without).
+  - `r35/run/vcx_*.exe` (round 35's generic effect harness): hosts `SG_x64.dll` standalone — restores a state through its
+    SaveRestoreState, sets parameter 5 through ProcessParam, renders through Eff_Render; `pp=`/`pd=`/`fp=`/`gd=` peeks.
+- **Models (pure Python + numpy, `python3 -I`):** `r36/py/rack.py` (chorus, delay, reverb, the Gen_Render rack
+  order; the reverb is round 31's model with Harmless's parameters), `r36/py/maxmodel.py` (the Maximus engine as used by
+  the presets), `r36/py/mxstate.py` (`.fst` / Maximus state reader), `r36/py/mkstate.py` (our own Maximus states for
+  tests). Drivers: `hx.py`, `sgx.py`; checks `t1.py` (Harmless compressor ≡ SG), `t2.py` (rack units),
+  `maxtest.py` (Maximus vs SG), `t48.py` (48 kHz, other blocks), `syntest.py` (our own states), `batrack.py` → 
+  `batrack_final.out` (139 demo channels, whole channel), `cpptest.py` (C++ port vs model), `dbg137.py`.
+- **C++ checks:** `r36/cpp/rackcmp.cpp` (LYNX's `hlfx::Rack` on a file), `r36/cpp/chanrec36.cpp` (the previous agent's
+  channel recorder with the installation's files readable), `r36/py/dllcmp36.py` (recorded LYNX channel vs the DLL).
+- **Manual:** `https://www.image-line.com/fl-studio-learning/fl-studio-online-manual/html/plugins/Harmless.htm`
+  (abbreviated `…/plugins/Harmless.htm`).
+
+---
+
+## 1. The rack inside Harmless
+
+### 1.1 Order of operations in Gen_Render **[DECOMP `FUN_007886b0`]**
+
+The voices are mixed into a float stereo buffer M (round 32 §1.1). Then, per host block of n samples:
+
+1. **Tail counter** (`+0x7b8`): when at least one voice record exists at the start of the block it is reloaded with
+   `+0x7bc`; otherwise it decreases by n (if positive). `+0x7bc = round(0.004·fs) + (chorus ring length in frames)`
+   (`FUN_00789570`; the ring is `host block size + chorus maximum delay`, §1.3) **[DECOMP; EXEC peek: 5421 at 44.1 kHz
+   with chorus type 3 and 512-sample blocks]**. "Active" below means counter > 0.
+2. **Chorus** (object `+0x7c0`, if its type > 0): active → M is written into the chorus ring, the taps produce T, M is
+   multiplied by the dry gain `+0x7c8` (when ≠ 1) and `M += T`; not active → only the tap phases advance by n.
+3. **Delay** (object `+0x7d0`, type > 0): active → `T = M·vol` (`+0x7e4`) is added into the delay ring at the write
+   position (+ the stereo offset of each channel); then always: the delay produces T, `M += T`.
+4. **Reverb** (object `+0x7f0`, type > 0): input `L + R` (no ½, run-time pointer `0x7ff590` → `FUN_006119f0`
+   [EXEC]), the shared reverb renders stereo T, `M += T·wet` (`ippsAddProductC_32f`, `wet = +0x7f8`).
+5. **Compressor** (list `+0x800 → +0x128`, non-empty when the compression type > 0): every hosted plugin processes M in
+   place (its Eff_Render, §1.6).
+6. Phases/counters advance and M is added to the host buffer (round 32).
+
+So the rack runs on the sum of all voices, after the per-voice tremolo and level law, i.e. on a signal that already
+includes the channel volume (Final.Vol) **[DECOMP]**. EXEC confirms the order: model (voices + this rack) vs the DLL
+with every unit on: §3.
+
+### 1.2 Parameters **[DECOMP `FUN_0077f630` cases 0x5a…0x62, set-ups; DATA; DOC]**
+
+| Param | Name (manual) | Law | Notes |
+|---|---|---|---|
+| p90 | Chorus type | 0 off, 1…8 a fixed record (§1.3) | `FUN_00789570` |
+| p91 | Chorus mix | m = p91·0.001 (float): dry `1 − (5^m − 1)/4`, wet volume `1 − (5^(1−m) − 1)/4` | both 0.691 at 500 |
+| p92 | Delay type | 0 off, 1…3 (§1.4) | `FUN_00789080` |
+| p93 | Delay vol | `(11^x − 1)/10`, x = p93·0.001 (exactly 1 at x = 1; ln 11 from the run-time float `0x7ff514` = 2.3978953 [EXEC]) | input gain into the ring |
+| p94 | Delay fb | p94·0.001 (float) | through a ramp (§1.4) |
+| p95 | Delay time | `round(p95·fs·0.3125/BPM)` samples = p95/192 beat (tempo `+0x2cc`, 120 by default [EXEC]) | min 1 |
+| p96 | Reverb type | 0 off, 1…6 (§1.5) | `FUN_00789280` |
+| p97 | Reverb vol | `0.5·(11^x − 1)/10`, x = p97·0.001 | wet gain |
+| combo 3 | Compression type | 0 off, n = 1…4 loads `Data\Compression\<n>.fst` into a hosted `SG.dll` (§1.6) | read from the editor's combo (`+0x9f8 → +0x3b0`) when the state loads |
+| p98 | Compression mix | sent unchanged as **parameter 5** of the hosted plugin (Maximus "LMH mix", §2.4) | `FUN_0077f630` case 0x62 |
+
+[DOC `…/plugins/Harmless.htm`]: chorus "similar to Unison but operates across all voices"; delay Time "is tempo
+synced"; the compressor types are "compression, limiting and distortion effects", "Limiting … disables the Mix control"
+and **"Harmless uses the Maximus compression engine"** — all consistent with the code.
+
+### 1.3 Chorus **[DECOMP + DATA + EXEC]**
+
+- Records (table `0x7ee73c + 0x20·type`, 6 used ints per record) **[DATA]**: type → (order N, depth/1024, speed/1024,
+  delay/128, spread/128, cross/128): 1 (4, 512, 768, 8, 128, −32), 2 (5, 1024, 856, 0, 128, 68), 3 (7, 512, 512,
+  128, 128, 54), 4 (6, 561, 854, 0, 0, 38), 5 (1, 136, 312, 0, 0, 128), 6 (2, 86, 632, 0, 0, 0), 7 (1, 42, 944, 0, 0,
+  −22), 8 (9, 81, 170, 0, 0, −66). The "volume" field of the unit is the wet gain of §1.2.
+- The unit is the **same library code as Sytrus's effects unit** (round 31 §7.3: identical constants 1092.5, 101,
+  75 000, 50 000, 2³¹, 500, 1001, 1000, 8, the 20 per-tap factors at `0x7ea5ac`), so its laws are round 31's:
+  2N taps, parabolic LFO per tap, linear interpolation in the ring, gains normalised by `(1 − (1001^(1 − 1/Σ|g|) −
+  1)/1000)·volume` **[DECOMP `FUN_0074a9b0`]**. Note: the sum Σ|g| and the maximum delay start at 0 (the decompiler
+  shows them as the low half of a double constant) — EXEC fails at −24 dB with 1 and matches with 0.
+- **Two tap kernels**, chosen once by a CPU-feature byte (`PTR_DAT_007f0870[0x16]`): x87 (`FUN_0074b180`, with the x87
+  control word 0x0F3F: truncation toward zero, 64-bit mantissa) or SSE (`FUN_0074b440`, `cvtsd2si` = round to nearest).
+  **On the test machine the byte is 0 [EXEC], so the x87 kernel runs: integer delay = ⌊D⌋** (this is also what round 31
+  observed in Sytrus). Which kernel FL uses on another CPU is **not confirmed** (the meaning of byte 0x16 was not
+  identified; inference: a CPU feature).
+- Chorus read position: the ring is written block by block; tap value
+  `s[n−k] + (D − k)·(s[n−k−1] − s[n−k])`, `k = ⌊D⌋`, first tap stored, the others added in extended precision then
+  rounded to float.
+- EXEC (`t2.py`, Harmless with a saw voice, model fed the DLL's own dry mix): types 1…8 −127.0…−143.5 dB (type 4 with
+  mix 0: bit-identical).
+
+### 1.4 Delay **[DECOMP + DATA + EXEC]**
+
+- Records (table `0x7ee67c + 8·type`) **[DATA]**: type → (offset in ms, ping-pong flag): 1 (0, 0) normal, 2 (+1, 2)
+  ping-pong with the **right** input written 1 ms later, 3 (−20, 2) ping-pong with the **left** input 20 ms later
+  (`round(|ms|·0.001·fs)` frames; the sign picks the side).
+- Ring of `(host block + offset + D)` frames; per block (active) the input `M·vol` is added at the write position
+  (`read + D`) plus the channel offset; then per sample: `y = ring[r]`, `ring[r] = 0`, `ring[r + D] += fb·y` (normal),
+  output `(L, R)`; ping-pong: output `(R, L)` and feedback `(R, L)` crossed; the written value is set to 0 when its
+  magnitude is below 2⁻²⁴ (integer compare of the float bits, x87 kernel `FUN_007475a0`/`FUN_007477f0` — same CPU-byte
+  choice as the chorus; the SSE twins compare an integer converted to float and in effect never flush).
+- Feedback through `FUN_00612db0` (per-block linear ramp limited to `0.001·44100/fs` per sample). **Start of the
+  ramp:** the constructor's target is 0.5 and a ring (re)allocation copies the current target into the ramp
+  (`FUN_007474d0`); in the harness (state loaded, then the sample rate set) the ramp starts **at the state's
+  feedback** — EXEC: with D = 1 (p95 = 0) a start at 0.5 gives −27…−56 dB, a start at the target is bit-identical.
+  Whether FL sets the sample rate before or after loading a state (which would make a new unit start at 0.5) was
+  not observed: **not confirmed**; LYNX uses the harness behaviour.
+- EXEC: types 1…3 incl. D = 1 and feedback up to 0.9: **bit-identical** (44.1 and 48 kHz, blocks 512 and 256).
+
+### 1.5 Reverb **[DECOMP + DATA + EXEC]**
+
+- `FUN_00749540` loads `Reverb_x64.dll` (`CreateReverbInstance`) — the shared reverb of round 31 §7.5 — and
+  `FUN_00749b60` writes its parameter block. Records (table `0x7ee67c + 0x20·type`, 8 ints) **[DATA]**: type →
+  (lowcut Hz (0 = off), highcut ×100 Hz, predelay, room, diffusion, decay ×0.1 s, damping ×100 Hz, colour):
+  1 (75, 40, 0, 40, 100, 15, 40, 2), 2 (0, 115, 18, 40, 100, 22, 50, 2), 3 (34, 21, 27, 90, 100, 45, 31, 3),
+  4 (400, 60, 31, 60, 65, 23, 37, 1), 5 (100, 36, 0, 35, 100, 6, 36, 2), 6 (100, 60, 0, 17, 100, 5, 30, 2). Predelay
+  `round(pre·fs/384)`, decay length `dec·fs/10`. The coefficient laws are round 31's (line lengths `MulDiv` with
+  truncation [`objdump 0x5b8070`], diffusion 0.07/0.35/0.51, colour factors 0.2/0.6/1/1.5/3, 500 Hz shelf); the
+  0.11 law written at block offset `+0x20` is not read by the process function (its input all-passes all use `+0x2c`).
+- Input `L + R`, output added with `wet = 0.5·(11^x − 1)/10` (§1.2).
+- EXEC: types 1…6 −129.3…−136.4 dB.
+
+### 1.6 Compressor = Soundgoodizer hosting a Maximus state **[DECOMP + EXEC]**
+
+- `FUN_00789800`: type > 0 → if no sub-plugin yet, `FUN_0076f2c0` loads `SG.dll` (resolved to `Shared\SG_x64.dll`)
+  through its own `CreatePlugInstance` with Harmless as its host (rate, block size and process mode forwarded); then the
+  path `<plugin folder>\Data\Compression\<n>.fst` is resolved through the host (request `0x3fc`, `FUN_0073f1e0`) and
+  `FUN_0076f7f0` extracts the plugin state from the `.fst` and hands it to the sub-plugin's state loader; finally
+  ProcessParam(0x62, p98) sends parameter 5. Type 0 removes the sub-plugin.
+- **The four presets are Maximus states** (event 0xD5 after the plugin name "Maximus", version 7) **[DATA]**: 1 = master
+  brickwall only (bands 0/2 off, band 1 "compression off" at unity); 2 and 3 = three-band maximisers (24 dB crossovers,
+  band curves with knees and tensions, saturation, stereo separation; 3 adds a 20 Hz low cut); 4 = "distortion": every
+  band in "compression off" with +18 dB post gain and saturation A, ×2 oversampling. The manual's "limiting … disables
+  the Mix control" matches preset 1 (no band compresses, so the band mix has no effect) **[DATA + DOC]**.
+- EXEC (`t1.py`): Harmless with compression n vs (Harmless with compression 0) → standalone `SG_x64.dll` with the state of
+  `n.fst` and parameter 5 = p98: **−95.5…−∞ dB** (n = 1…4; p98 = 0, 300, 500, 1000). So the stage is exactly "SG with
+  that state". (Inference: FL answers request `0x3fc` with the same installation file — the answer itself was not
+  observed in FL.)
+
+---
+
+## 2. The Maximus engine (as run by `SG_x64.dll`) **[DECOMP + EXEC]**
+
+Only what Harmless's four presets use was decoded; §2.9 lists the rest. Field names refer to the band record
+`B = 0x380 + 0x100·b` (b = 0 low, 1 mid, 2 high, 3 master) of the plugin object.
+
+### 2.1 State → working values **[DECOMP `FUN_0083ef50`, `FUN_00841b40`, `FUN_008417e0`; EXEC peeks]**
+
+- The state block (59 parameters, 59 "backup" ints, UI block) is read raw into the object at `+0x12C`; parameter
+  indices and laws as round 8 §1.2. **New:** the UI int at state offset `0x1F4` is the **oversampling order** (`+0x31C`;
+  preset 4 has 1 → ×2) **[DECOMP + EXEC peek `+0x7C0` = 2]**; v ≥ 14 flags byte bit 6 selects a curve scale of 1.0
+  instead of 0.975 (table `0x8b8ad0`).
+- Per band: mode (`B+8`), pre = L7(pre/1000), post = L7(post/1000) with `L7(x) = (7^x − 1)/6` in float (1 at x = 1);
+  parameter 5 (band mix) `mix = p5·0.001` and the flag `mix ≠ 1`.
+- Time law `T(v) = 2·(501^(v/10000) − 1)` ms (`(501^x − 1)` kept as float), samples = `T·0.001·fs`.
+- Stereo separation s = p10/1000: s > 0 → `(5^s − 1)/4`, s < 0 → s; capped at 1; 2×2 matrix
+  `L' = L(1 − s/2) + R·s/2`, `R' = R(1 − s/2) + L·s/2` (positive narrows to mono, negative widens)
+  **[DECOMP `FUN_00616320`; EXEC peeks: 0.845491529/0.154508501 for 500, 1.174/−0.174 for −348]**.
+
+### 2.2 Signal flow per block **[DECOMP `FUN_00843a40`]**
+
+1. **Silence counter:** a block is silent when every sample is within ±10⁻⁶. Non-silent → counter = latency +
+   round(1.5·fs) (`+0x784`); silent → counter −= n. While counter > −n the block is processed; otherwise the plugin
+   resets once (§2.8) and passes the block through untouched.
+2. **Low cut** (p6 ≥ 0): four high-pass biquads at `0.8·5·2^(p6/16384)` Hz with α = sin ω·{0.19771184, 0.61932772,
+   0.67684454, 1.07935691} (table `0x8b8580`) **[DECOMP `FUN_0083a5c0`; DATA]**, in place on the input.
+3. **Oversampling** (order 1): 2:1 polyphase all-pass interpolator (§2.7) → the bands run at 2·fs.
+4. **Crossover** (§2.3) and **bands 0…2** (§2.4): each band's output is summed (low band in place, others added).
+5. The sum is decimated back (order 1) and runs through the **master band** (§2.4) in place; master mode 2 mutes.
+
+### 2.3 Crossover **[DECOMP `FUN_00844e10`, `FUN_00624b50`, `FUN_00624580`, `FUN_00624e90`; EXEC]**
+
+- `f_low = 30·2^(p0·ln(533.33)/ln2/65536)`, `f_high` the same from p2 (swapped if both bands are on and out of order);
+  slope `sL = p1`, `sH = p3`, **−1 when the outer band is off** (mode 3), clamped to `0.4999·rate`.
+- Biquads (RBJ form, `a0 = 1 + α`): low-pass, high-pass and all-pass, α = sin ω (slope 0 → one stage, Q = 0.5) or
+  α = sin ω/√2 (slope 1 → two stages, Q = 0.7071 each: Linkwitz–Riley 24 dB); direct form I in double, output float,
+  **the four states per channel rounded to float (and zeroed below 2⁻²⁴) at the end of every block** (`FUN_00627cc0`).
+- Topology: low = (sL+1) low-pass stages at f_low (+ one all-pass at f_high when sH = 1); mid: (sL+1) high-pass stages
+  at f_low applied **in place on the input** (so the high band sees them too), then (sH+1) low-pass stages at f_high;
+  high = (sH+1) high-pass stages at f_high of that high-passed input. Band polarity `B+0x18` = table `0x8b8bbc`
+  [slope]: −1 for 12 dB, +1 for 24 dB, 0 for an off band (applied in the band mix, §2.4) **[DECOMP + EXEC peeks]**.
+- EXEC: preset 4 (24/12 dB crossovers at 52.5 Hz / 936 Hz, ×2 oversampling, saturation, no detector): −106 dB.
+
+### 2.4 One band **[DECOMP `FUN_00843a40`, `FUN_00840c80`, `FUN_00845b50`, `FUN_00605410`, `FUN_007806b0`; EXEC]**
+
+For mode < 2: stereo matrix (§2.1). For mode 0 ("on"), the gain is computed from the band signal:
+
+1. **Detector (peak):** `max(|L|, |R|)` then the running maximum over the last W samples (monotonic-wedge
+   algorithm), `W = max(L, round(T(sustain)·fs)·K, 1)` — L = lookahead (below), K = oversampling factor.
+2. **Release stages** (`B+0x98`): `count = release curve` (p17) one-poles, each `s ← x + c·(s − x)` with c = 0 when the
+   input is ≥ the state (instant rise) and `c = exp(ln 0.01/N)` otherwise, **N = 2·T(release)·fs·K/√count** (the per-stage
+   time is divided by the **square root** of the stage count — `FUN_0040c3d0` is `sqrt` [DECOMP + EXEC peeks of the
+   coefficients]); float states, flushed below 2⁻²⁴ at the end of a block.
+3. **Static curve:** index `i = trunc(level·float(pre·8192.25))` (`ippsConvert_32f32s_Sfs`, round toward zero;
+   negatives → 0); gain `= lerp(table[i], table[i+1], frac)·(pre·post)`, or `table_end·post/level` above the table
+   (§2.5).
+4. **Attack / release-2 stages** (`B+0x90`): `count = p15` one-poles on the gain, rising (gain ≥ state) with release 2
+   and falling with attack: attack `N = 0.8·A/√count`, A = T(attack)·fs·K, or A = L when the attack is 0 ("Default");
+   release 2 `N = 2·T(rel2)·fs·K/√count`, or the attack's N when 0. They start (reset) at `pre·post·table[0]`.
+5. **Lookahead:** the audio (not the detector input) is delayed by `L` samples: bands 0…2 use
+   `L = round(T(p4)·fs)·K` when the band is on/compression-off and at least one band compresses; the master uses
+   `L = round(T(master attack)·fs)` when it compresses; otherwise 0.
+6. When the band mix is not 1 (bands 0…2), the delayed band signal is kept as "dry".
+7. Mode 0: audio × gain; modes 1–3: audio × post.
+8. **Saturation A** (p11 < 0, mode < 2): odd table read with linear interpolation (§2.6).
+9. Bands 0…2, mode < 2: band mix `y·(mix·pol) + dry·((1 − mix)·pol)` when mix ≠ 1, else `y·pol` (pol = §2.3 polarity);
+   modes 2/3 contribute nothing (an "off" band was already merged into its neighbour by the crossover).
+
+EXEC peeks confirmed every working value (W, L, coefficients, table sizes, matrices) for the four presets.
+
+### 2.5 The drawn curve and its gain table **[DECOMP `FUN_00845b50`, `FUN_007876c0`, `FUN_007885d0`, point preparation; EXEC]**
+
+- Envelope points in memory: dx (double), y (float), tension (float), type byte; dx ≤ 0 → 0.
+- Evaluation (iterator: segment index, position t, rate 1/dx, start value, delta): the curve is evaluated
+  incrementally at `c_i = ln(1 + 2·max(i,1)/8192)/(2 ln 3)` for i = 0…32 768 (`c` = editor x for level `i/8192`);
+  value = `y_prev + shape(t)·(y_next − y_prev)` with the arriving point's shape:
+  - **type 0**, tension τ ≠ 0: `q = 1000001^|τ| − 1` (float, sign of τ), `b = 1/|q|`, `c = ln(|q| + 1)`;
+    τ > 0: `shape = 1 − (e^{(1−t)c} − 1)·b`; τ < 0: `shape = (e^{tc} − 1)·b`; τ = 0: linear;
+  - **type 7**: `u = 1 − t` (τ > 0) or `t`; `shape = t − (u⁶ − u)·τ`.
+  (Other segment types exist in the code — 1, 3…6, 8…12 — and are not used by the presets: **not modelled**.)
+- Output level `(3^{2y} − 1)/2·s`, s = 0.975 (or 1, §2.1); table[i] = output/level; once the output equals s (within
+  2⁻²⁴) the table stops at the last non-saturated index (`B+0x3C`), whose output end value is `B+0x40`; `B+0x48` =
+  maximum output/s.
+- EXEC: our own states with type-7 (τ = 0.36) and type-0 (τ = 0.14, 0.085) segments vs SG: −103 / −122 dB.
+
+### 2.6 Saturation A **[DECOMP `FUN_00841380`, `FUN_0062a240`; EXEC]**
+
+- Knee exponent `p = 20 − 19·ln(1 + 0.1·|thr|)/ln 101` (float; thr = p11 < 0 → p from 1 at −1000 to 20 near 0),
+  ceiling `cl = L7(p12)`, top `= max(B50·post, cl)` with `B50 = B+0x48` (band compressing, peak detector) or 4.0.
+- Table of 65 537 values: `t_i = (atan((i·d)^p))^{1/p} / (atan((65536·d)^p))^{1/p}`, `d = top/(cl·65536)` (IPP
+  `Powx_64f_A53`, `Atan_64f_A53`), values below 2⁻²⁴ set to 0, converted to float.
+- Applied per sample (x87, truncating): `v = x·65536/top`, `k = trunc(|v|)` (≤ 65 536), linear interpolation, sign of x,
+  × cl. So the band output saturates smoothly at `cl`, sharper for smaller |thr|.
+- Saturation B (p11 > 0, `FUN_00629fd0`/`FUN_0062a010`/`FUN_0062a090`, an exponential soft clip above a threshold) is not
+  used by the presets: **not modelled**.
+
+### 2.7 Oversampling filters **[DECOMP `FUN_0083a9c0`, `FUN_0083ab90`; EXEC peek of the coefficient table]**
+
+Two cascades of three first-order all-passes `y = x[n−1] + k(x[n] − y[n−1])`, branch A k = 0.14737711, 0.48246854,
+0.88300503, branch B k = 0.03915160, 0.30264685, 0.67461592 (the same as Sytrus's decimator, round 31 §7.2);
+up: each input sample gives (B, A); down: `0.5·(B + A)` with A fed by even and B by odd samples; the all-pass outputs are
+rounded to float (zero below 2⁻²⁴) at the end of each block.
+
+### 2.8 Reset and latency **[DECOMP `FUN_00845940`, `FUN_00840a00`]**
+
+Reset (at load and after 1.5 s of silence): attack stages → `pre·post·table[0]`, release stages → 0, lookahead
+delays, crossover/low-cut/oversampling states → 0, counter → −0x3FFFFFFF (processing restarts with the next non-silent
+block). Latency reported to the host = `max(L₀…₂)/K + L₃` (not compensated inside Harmless).
+
+### 2.9 Not decoded / not used by Harmless's presets
+
+RMS detector (`FUN_007808b0` class: `L² + R²`, box sum over W, scale, sqrt — structure only), saturation B, envelope
+segment types other than 0 and 7, the linear-phase ("FFT", `+0x32C`, `engine_x64.dll`) path, solo/mute flags,
+oversampling orders above 1, curve-scale flag of v ≥ 14 states (read, not exercised). LYNX rejects a preset that needs
+any of them (none of the four does).
+
+---
+
+## 3. Verification **[EXEC + model]**
+
+Relative error `20·log₁₀(‖model − DLL‖/‖DLL‖)`, both channels, worst reported, 44.1 kHz, blocks of 512 unless stated.
+
+| Check | Cases | Result |
+|---|---|---|
+| Harmless compressor ≡ hosted SG (`t1.py`) | types 1…4, p98 0/300/500/1000 | −95.5…−∞ dB |
+| Chorus (`t2.py`) | types 1…8 (mixes 0…1000) | −127.0…−∞ dB |
+| Delay | types 1…3, D = 1…5512, fb ≤ 0.9 | bit-identical |
+| Reverb | types 1…6 | −129.3…−136.4 dB |
+| All three units | chorus 3 + delay 2 + reverb 4 | −131.3 dB |
+| Maximus vs SG standalone (`maxtest.py`) | 4 presets × mixes × {saw, noise bursts with silences, loud two-tone} | −91.2…−123.0 dB |
+| Our own Maximus states (`syntest.py`) | limiter only; 3 bands + ×2 + low cut + separation + saturation + tensions + release 2 | −122.2 / −103.1 dB |
+| 48 kHz, blocks 512 / 256 / 300 (`t48.py`) | chorus 2/7, delay 3, reverb 1/6, all, SG presets 1…4 | rack −128.1…−∞ dB; SG −94.8…−123.9 dB |
+
+**Whole channels — the 139 Harmless channels of the demo projects with their saved state, rack on** (`batrack.py` →
+`batrack_final.out`; model = round 32's voice model with the DLL's per-voice random draws peeked, as in round 32,
+followed by `rack.py` with `maxmodel.py`; three overlapping notes, 2 s so that delay/reverb tails are included):
+
+- **135 of 139 channels ≤ −60 dB** (median −79.8 dB; 122 ≤ −70 dB; 69 ≤ −80 dB; best −100.7 dB; worst of these
+  −62.4 dB, "Steptime"). They include every chorus type, every delay type (incl. D = 1 sample), every reverb type and
+  all four compression presets with their saved mixes.
+- **The 4 remaining channels are the same as in round 32** (Galactic: Snare −25.6, High Hat +1.7, Galactic +0.3,
+  Noisesweep −2.4 dB): the Freq phaser at quality 0, whose output depends on IPP `Exp_32f_A11`'s error pattern
+  (round 32 §1.9) — not a rack effect.
+- Without the delay-ramp correction of §1.4, "Kick Stab" (delay time 0) was at −53 dB; with it −72.9 dB.
+- Per-channel list: `r36/py/batrack_final.out`.
+
+How the random parts are handled: the DLL seeds its generator from the clock (round 32 §1.19), so every DLL run
+draws different per-voice seeds; the harness reads the draws of *that* run from the voice records right after note-on
+and the model uses them. The rack itself has no random part. LYNX (C++) uses its own deterministic generator, so
+for channels with spectral-random phases, Noise resonance or the "voice random" LFO, LYNX can only be compared with the
+model fed LYNX's own draws (round 32's port check, −151 dB) — not sample by sample with an FL render.
+
+**C++ port** (`cpptest.py`: `hlfx::Rack` vs `rack.py` + `maxmodel.py` on the same input, 44.1/48 kHz, blocks 512/333):
+chorus −142.9…−144.7 dB, delay bit-identical, reverb −129.1…−136.4 dB, Maximus presets 1–2 bit-identical and 3–4
+−144.9…−154.2 dB, full racks −98.2…−129.4 dB.
+**End to end** (`chanrec36` + `dllcmp36.py`, LYNX's recorded channel vs the DLL fed the same notes and FL levels):
+Galactic "Kick" (compression 3, deterministic voice) −79.0 dB over 28 notes; channels with clock-seeded or Freq-phaser
+parts differ as described above, and identically with the rack switched off (not a rack effect).
+
+---
+
+## 4. Harmor shares the rack's building blocks **[DATA (byte search)]**
+
+`Harmor_x64.dll` contains the same UTF-16 strings `SG.dll`, `Reverb_x64.dll`, `CreateReverbInstance`, a path built
+from `System`, `\`, `Compression`, `.fst` (Harmor's presets are `Plugins/Fruity/Generators/Harmor/System/Compression/
+1…4.fst`; `1.fst` is byte-identical to Harmless's `1.fst`, 2–4 differ), the 20 chorus per-tap factors (at VA
+`0x91b6f0`), and **byte-identical code** for the chorus x87 tap kernel (Harmless `FUN_0074b180` = Harmor VA
+`0x7a9240`), the chorus set-up (`FUN_0074a9b0` = `0x7a8a70`) and the reverb coefficient set-up (`FUN_00749b60` =
+`0x7a7c20`); the delay kernel's first 24 bytes match at `0x7a5660`. Harmor also names separate reverb controls
+(`dec`, `diff`, `damp`). **Conclusion:** the chorus, delay and reverb units and the SG/Maximus compressor are the same
+library and DLLs; a Harmor port can reuse LYNX's `hlfx` units (and the Maximus engine with Harmor's own presets). Harmor's
+Gen_Render order, parameter laws and preset tables were **not analysed** (not confirmed).
+
+---
+
+## Summary table (question → result)
+
+| # | Item | Result |
+|---|---|---|
+| R1 | Order | chorus → delay → reverb → compressor on the float voice mix, then added to the host buffer; tail counter round(0.004·fs) + chorus ring **[DECOMP + EXEC]** |
+| R2 | Chorus | 8 fixed records of the Sytrus effects-unit library; dry/wet `1 − (5^x − 1)/4`; x87 kernel (⌊D⌋) on the test machine **[DECOMP + DATA + EXEC −127…−∞ dB]** |
+| R3 | Delay | 3 records (normal; ping-pong with +1 ms R / +20 ms L); time p95/192 beat; vol `(11^x−1)/10`; fb ramp **[DECOMP + DATA + EXEC bit-identical]** |
+| R4 | Reverb | Shared `Reverb_x64.dll` with 6 fixed records; wet `0.5·(11^x−1)/10` **[DECOMP + DATA + EXEC −129…−136 dB]** |
+| R5 | Compressor | hosted `SG_x64.dll` loaded with Harmless's `Data/Compression/<n>.fst` (Maximus states), p98 = parameter 5 (band mix) **[DECOMP + EXEC ≤ −95 dB]** |
+| R6 | Maximus | low cut, ×2 oversampling, LR crossovers with polarity, per band: separation matrix, peak-window detector, √-scaled release / attack / release-2 one-poles, drawn-curve gain table (tension types 0 and 7), lookahead, saturation A, band mix; master limiter **[DECOMP + EXEC −91…−123 dB]** |
+| R7 | Demo channels (model incl. rack vs DLL) | 135/139 ≤ −60 dB (median −79.8), the 4 others are round 32's Freq-phaser channels **[EXEC + model]** |
+| R8 | Harmor | same chorus/delay/reverb code, same SG + `.fst` mechanism (own presets) **[DATA]**; its parameter mapping not analysed |
+| R9 | Correction | earlier "0.976 caps" measurement used SG's default state because the harness did not answer the plugin's data-file request |
+
+---
+
+## 5. For LYNX (what was implemented)
+
+`src/core/HarmlessFx.{h,cpp}` (namespace `lynx::hlfx`), used by `src/core/Harmless.cpp`:
+
+1. **Import** (`FlpImport.cpp`): when compression type n > 0, read `%FLStudioFactoryData%\Plugins\Fruity\Generators\
+   Harmless\Data\Compression\<n>.fst` from the user's installation, extract the Maximus state (`maximusStateFromFst`) and
+   append it to `modelParams` (`harmlessCompIndex`: byte count, then one byte per float). Missing → the compressor stays
+   off and the report lists "Harmless compressor (preset not found)".
+2. **Configure** (message thread): `makeMaximusPreset` builds everything rate-independent (gain tables, saturation
+   tables, matrices); unsupported states are rejected. **Prepare/rebuild**: `Rack::prepare` (chorus/delay/reverb from
+   the records above, the delay at the project tempo; Maximus coefficients at the sample rate).
+3. **Render:** the voice mix is converted to float, `Rack::process` runs in place (voices flag = records existed at the
+   block start), then it is added to the output. The instrument stays non-idle until the rack has been below −140 dB
+   for longer than its longest delay; while idle, `Rack::advance` keeps the chorus phases, the delay ramp and the
+   compressor's silence counter running (FL calls Gen_Render continuously).
+4. Arithmetic follows the reference's float/double order (FMA contraction off); CPU-feature choice: the x87 kernels of
+   the test machine.
+5. Tests: `tests/tests.cpp` `harmless_rack` (rack goldens from the reference model, delay laws, two Maximus states of our
+   own, `.fst` extraction, rejection of an RMS state) and the real-file check (all 134 demo channels with a compressor
+   get their preset from the installation).
+6. **Costs** (one core, 44.1 kHz, `rackcmp` on 60 s of noise): Maximus presets 1 / 2 / 3 / 4 = 0.18 / 0.77 / 0.87 /
+   0.53 % of real time, chorus type 8 (18 taps) 0.47 %, delay 0.08 %, reverb 0.13 %.
+
+---
+
+## Evidence index
+
+| Function / data | What it shows | Marker |
+|---|---|---|
+| Harmless `FUN_007886b0` | rack order, tail counter, chorus/delay/reverb/compressor calls | DECOMP |
+| Harmless `FUN_0077f630` cases 0x5a…0x62 | parameter → set-up dispatch, p98 → SG parameter 5 | DECOMP |
+| `FUN_00789570`, `FUN_00789080`, `FUN_00789280`, `FUN_00789800` | chorus / delay / reverb / compressor set-ups and laws | DECOMP |
+| tables `0x7ee73c`, `0x7ee67c` | chorus, delay and reverb records | DATA |
+| `FUN_0074a9b0`, `FUN_0074b180`/`230`, `FUN_0074b440`/`600`, `PTR_DAT_007f0870[0x16]` | chorus laws, x87/SSE kernels, CPU byte = 0 | DECOMP + EXEC |
+| `FUN_007471d0`, `FUN_00747070`, `FUN_00747510`, `FUN_007475a0`/`7477f0`, `FUN_007474d0` | delay ring, kernels, ramp start | DECOMP + EXEC |
+| `FUN_00749540`, `FUN_00749b60`, `FUN_0074a540`; Reverb_x64 `FUN_180002980` | shared reverb and its parameter block | DECOMP + EXEC |
+| `FUN_0076f2c0`, `FUN_0076f7f0`, `FUN_0073f1e0` | SG sub-plugin, `.fst` state, data-file request 0x3fc | DECOMP + EXEC |
+| `Harmless/Data/Compression/1…4.fst` | Maximus v7 states | DATA |
+| SG `FUN_00843a40` | Maximus block flow | DECOMP |
+| SG `FUN_0083ef50`, `FUN_00841b40`, `FUN_008417e0`, `FUN_00616320` | state, parameters, modes, separation matrix | DECOMP + EXEC peeks |
+| SG `FUN_00844e10`, `FUN_00624b50`, `FUN_00624580`, `FUN_00624e90`, `FUN_00627cc0`, table `0x8b8bbc` | crossover design, biquad, state rounding, polarity | DECOMP + EXEC |
+| SG `FUN_00840c80`, `FUN_006052f0`, `FUN_00605410`, `FUN_0040c3d0` (sqrt) | time constants, √-scaled stages, smoother | DECOMP + EXEC peeks |
+| SG `FUN_00629710`, `FUN_007806b0`, `FUN_0077f350` | peak window, lookahead delay | DECOMP + EXEC |
+| SG `FUN_00845b50`, `FUN_007876c0`, `FUN_007885d0`, `FUN_0060dfd0`, point preparation `0x7854f0…` | curve evaluation and gain table | DECOMP + EXEC |
+| SG `FUN_00841380`, `FUN_0062a240`, IPP `Powx_64f_A53`, `Atan_64f_A53` | saturation A | DECOMP + EXEC |
+| SG `FUN_00847ce0`, `FUN_0083aef0`/`af90`, `FUN_0083a9c0`/`ab90`, table `0x8cd028` | oversampling | DECOMP + EXEC |
+| SG `FUN_00840b40`, `FUN_0083a5c0`, table `0x8b8580` | low cut | DECOMP + DATA + EXEC |
+| SG `FUN_00845940`, `FUN_00629890`, `FUN_00840a00` | reset, silence, latency | DECOMP + EXEC |
+| Harmor byte search | shared code/strings/presets | DATA |
+| `r36/py/t1.py`, `t2.py`, `maxtest.py`, `syntest.py`, `t48.py`, `batrack.py`, `cpptest.py` | §3 | EXEC + model |
+
+### Open questions
+
+- Which chorus/delay kernel (x87 truncating vs SSE rounding) FL uses on CPUs where the feature byte `[0x16]` is set
+  (its meaning was not identified).
+- FL's call order (sample rate vs state load) decides whether a fresh delay starts its feedback ramp at 0.5 or at the
+  state's value (the harness order gives the latter).
+- FL's actual answer to the data-file request `0x3fc` (inferred to be the installation file).
+- Maximus features not used by Harmless's presets (§2.9); Harmor's own rack mapping (§4).

+ 1 - 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/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/HarmlessFx.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)

+ 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/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/HarmlessFx.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)..."

+ 20 - 0
src/core/FlpImport.cpp

@@ -1,6 +1,7 @@
 #include "core/FlpImport.h"
 #include "core/DrumSynthLive.h"
 #include "core/Harmless.h"
+#include "core/HarmlessFx.h"
 #include "core/PhysicalModels.h"
 
 #include "core/Effects.h"
@@ -795,6 +796,25 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
                     def.instrument = InstrumentKind::harmless;
                     def.modelParams = std::move (*params);
                     adoptedFromPlugin = true;
+                    // rack compressor: Harmless's own preset <n>.fst from the user's installation (REA_rodada36 §2)
+                    const auto compType = (int) def.modelParams[(std::size_t) harmlessComboIndex + 3];
+                    if (compType > 0)
+                    {
+                        const auto path = resolveFlPath ("%FLStudioFactoryData%\\Plugins\\Fruity\\Generators\\Harmless\\Data\\Compression\\"
+                                                             + std::to_string (compType) + ".fst",
+                                                         options.roots);
+                        std::optional<std::vector<std::uint8_t>> state;
+                        if (! path.empty() && options.readFile && (! options.fileExists || options.fileExists (path)))
+                            state = hlfx::maximusStateFromFst (options.readFile (path));
+                        if (state && hlfx::makeMaximusPreset (*state) != nullptr)
+                        {
+                            def.modelParams.push_back ((float) state->size());
+                            for (const auto byte : *state)
+                                def.modelParams.push_back ((float) byte);
+                        }
+                        else if (options.report != nullptr)
+                            ++options.report->droppedEffects["Harmless compressor (preset not found)"];
+                    }
                 }
                 else if (synthFromHarmless (c.pluginState, song.bpm, fromPlugin, pluginGain))
                     adopt();

+ 41 - 8
src/core/Harmless.cpp

@@ -1,4 +1,5 @@
 #include "core/Harmless.h"
+#include "core/HarmlessFx.h"
 #include "core/Song.h"
 
 #include <algorithm>
@@ -950,6 +951,7 @@ public:
     Patch P;
     Globals G;
     Random random;
+    hlfx::Rack rack;          // the effects rack on the mix (REA_rodada36)
     long long N = 0;          // plugin sample counter
     double tremPrev = 0.0;
     int slot = -1;            // current note of the channel
@@ -1208,11 +1210,24 @@ public:
                     v.env.kill();
             }
         }
-        for (int j = 0; j < n; ++j)
+        if (rack.enabled())
         {
-            left[j] += (float) mixL[(std::size_t) j];
-            right[j] += (float) mixR[(std::size_t) j];
+            // the DLL mixes the voices into a float buffer and runs the rack on it in place
+            for (int j = 0; j < n; ++j)
+                rackL[(std::size_t) j] = (float) mixL[(std::size_t) j], rackR[(std::size_t) j] = (float) mixR[(std::size_t) j];
+            rack.process (rackL.data(), rackR.data(), n, live);
+            for (int j = 0; j < n; ++j)
+            {
+                left[j] += rackL[(std::size_t) j];
+                right[j] += rackR[(std::size_t) j];
+            }
         }
+        else
+            for (int j = 0; j < n; ++j)
+            {
+                left[j] += (float) mixL[(std::size_t) j];
+                right[j] += (float) mixR[(std::size_t) j];
+            }
         G.advance (P, n);
         N += n;
         collect();
@@ -1225,6 +1240,7 @@ private:
     std::vector<Note> notes;
     std::vector<int> order; // notes in creation order (the voice mix order)
     std::array<double, maxHostBlock> mono {}, mixL {}, mixR {}, tremL {}, tremR {}, envBuf {};
+    std::array<float, maxHostBlock> rackL {}, rackR {};
     std::array<double, maxControlBlock + 1> kpow {};
     std::array<double, 8 * maxControlBlock> laneSums {};
     std::array<double, bankSize> amps {}; // the target amplitudes being built in a control block
@@ -2160,6 +2176,7 @@ private:
 struct Settings
 {
     std::array<float, harmlessParamCount> raw {};
+    std::shared_ptr<const hlfx::MaximusPreset> comp; // the rack compressor's preset (built off the audio thread)
     double bpm = 120.0;
     float pitchCents = 0.0f; // channel pitch/fine/root shift, cents relative to C5
 };
@@ -2192,7 +2209,9 @@ Settings defaultSettings() noexcept
 // does not tell an instrument when it renders offline, so FL's quality 2 for rendering (§1.2) is not used.
 // Random sources: deterministic per instrument (see Random); FL's are clock-seeded, so spectral-random phases, Noise
 // resonance and the LFO "voice random" differ from any given FL render by design.
-// The effects rack (chorus/delay/reverb/compressor) is not decoded and is off.
+// Effects rack (REA_rodada36): chorus, delay and reverb from the plugin's own preset tables; the compressor is FL's
+// Maximus engine with Harmless's preset <n>.fst, read by the importer from the user's FL installation (without it the
+// compressor stays off and the import report says so). The delay's time follows the project tempo at load.
 
 class HarmlessInstrument final : public Instrument
 {
@@ -2220,6 +2239,18 @@ public:
                 s.raw[i] = std::isfinite (channel.modelParams[i]) ? channel.modelParams[i] : 0.0f;
         s.bpm = bpm > 0.0 ? bpm : 120.0;
         s.pitchCents = channel.sampler.pitch * 100.0f;
+        const auto& mp = channel.modelParams;
+        if (mp.size() > (std::size_t) harmlessCompIndex)
+        {
+            const auto count = (std::size_t) std::max (0.0f, mp[(std::size_t) harmlessCompIndex]);
+            if (count > 0 && mp.size() >= (std::size_t) harmlessCompIndex + 1 + count)
+            {
+                std::vector<std::uint8_t> state (count);
+                for (std::size_t k = 0; k < count; ++k)
+                    state[k] = (std::uint8_t) std::clamp ((int) mp[(std::size_t) harmlessCompIndex + 1 + k], 0, 255);
+                s.comp = hlfx::makeMaximusPreset (state);
+            }
+        }
         mailbox.write (s);
     }
 
@@ -2249,7 +2280,7 @@ public:
 
     void allNotesOff() noexcept override { engine.allNotesOff(); }
 
-    bool idle() const noexcept override { return engine.idle(); }
+    bool idle() const noexcept override { return engine.idle() && engine.rack.quiet(); }
 
     // the LFO (global mode) and phaser phases follow song-position jumps as FL's song-position event sets them
     // (§1.9, §1.12); continuous playback and a stopped transport leave them running
@@ -2277,14 +2308,15 @@ public:
         sinceTicks += n;
         if (n <= 0)
             return;
-        if (engine.idle())
+        if (engine.idle() && engine.rack.quiet())
         {
-            // nothing sounds: only the plugin-wide phases and counters run
+            // nothing sounds: only the plugin-wide phases and counters run (the rack's included)
             for (int done = 0; done < n; done += Engine::maxHostBlock)
             {
                 const auto m = std::min (Engine::maxHostBlock, n - done);
                 engine.G.advance (engine.P, m);
                 engine.N += m;
+                engine.rack.advance (m);
             }
             engine.tremPrev = engine.P.trem;
             return;
@@ -2302,7 +2334,7 @@ private:
         if (mailbox.read (incoming))
         {
             const auto changed = std::memcmp (incoming.raw.data(), settings.raw.data(), sizeof (float) * settings.raw.size()) != 0
-                                 || incoming.bpm != settings.bpm;
+                                 || incoming.bpm != settings.bpm || incoming.comp != settings.comp;
             settings = incoming;
             if (changed)
                 rebuild();
@@ -2313,6 +2345,7 @@ private:
     {
         const auto& raw = settings.raw;
         engine.P.build (raw.data(), rate, (int) std::lround (raw[(std::size_t) harmlessComboIndex + 6]), settings.bpm);
+        engine.rack.prepare (engine.P.p, engine.P.t, rate, settings.bpm, settings.comp);
     }
 
     Engine engine;

+ 6 - 3
src/core/Harmless.h

@@ -5,13 +5,15 @@
 // up to 528 sine partials (self-oscillation, Sub 1/3/4, 524 harmonics) whose target amplitudes are rebuilt every
 // control block (88/44/8 samples at 44.1 kHz for quality 0/1/2) from colour × timbre EQ → mask → filter → resonance
 // → phaser → pluck → low-harmonics protection → subs → band limit, with FL's envelopes, LFO, vibrato, tremolo,
-// unison, portamento/mono/legato and voice stealing. The effects rack (chorus/delay/reverb/compressor) is not
-// decoded and stays off.
+// unison, portamento/mono/legato and voice stealing, followed by the effects rack of docs/analise/REA_rodada36.md
+// (chorus → delay → reverb → compressor; core/HarmlessFx).
 //
 // ChannelDef::modelParams layout (harmlessParamCount floats): the 100 raw parameters p0…p99 (integers as floats; p99
 // is 0 for states older than version 9), then the 7 combo integers (filter type, resonance type, phaser type,
 // compressor type, colour, threaded flag, quality), then 1 when a Custom colour table is present (0 otherwise), then
-// the Custom table: 524 harmonic amplitudes followed by 524 phases (cycles), zero-padded.
+// the Custom table: 524 harmonic amplitudes followed by 524 phases (cycles), zero-padded. Optionally followed by the
+// rack compressor's preset (read by the importer from the user's FL installation, Harmless/Data/Compression/<n>.fst):
+// its byte count, then the Maximus state, one byte per float.
 
 #include <cstdint>
 #include <memory>
@@ -28,6 +30,7 @@ constexpr int harmlessCustomFlagIndex = 107;
 constexpr int harmlessCustomIndex = 108;
 constexpr int harmlessCustomSize = 1048;       // 524 amplitudes + 524 phases
 constexpr int harmlessParamCount = harmlessCustomIndex + harmlessCustomSize;
+constexpr int harmlessCompIndex = harmlessParamCount; // optional: byte count, then the bytes of the Maximus state
 
 // FL project state (plugin record 0xD5, versions 4…12) → modelParams (layout above); nullopt if it can't be parsed
 std::optional<std::vector<float>> harmlessParams (const std::vector<std::uint8_t>& state);

+ 1419 - 0
src/core/HarmlessFx.cpp

@@ -0,0 +1,1419 @@
+#include "core/HarmlessFx.h"
+
+#include <algorithm>
+#include <cmath>
+#include <cstring>
+#include <deque>
+
+// Specified as float32 / double operations in the order of the reference model (REA_rodada36); contraction of a·b + c
+// into one FMA would change the roundings, so it stays off in this file.
+#if defined(__clang__)
+#pragma clang fp contract(off)
+#elif defined(__GNUC__)
+#pragma GCC optimize ("fp-contract=off")
+#endif
+
+namespace lynx::hlfx
+{
+namespace
+{
+constexpr double pi = 3.141592653589793;
+constexpr float flushLevel = 5.960464477539063e-08f; // 2^-24: FL's denormal guard
+const double ln001 = std::log (0.01);
+
+inline float f32 (double x) noexcept { return (float) x; }
+inline double rint (double x) noexcept { return std::nearbyint (x); } // round half to even (cvtsd2si)
+inline float flush (double v) noexcept
+{
+    const auto f = (float) v;
+    return std::fabs (f) < flushLevel ? 0.0f : f;
+}
+
+// (11^x − 1)/10, exactly 1 at x = 1 (ln 11 as the float of the plugin's run-time global)
+float g11 (float x) noexcept
+{
+    if (x == 1.0f)
+        return 1.0f;
+    return f32 ((std::exp ((double) x * (double) (float) std::log (11.0)) - 1.0) * (double) 0.1f);
+}
+
+// 1 − (5^x − 1)/4 (chorus dry and wet gains)
+float g5 (float x) noexcept
+{
+    return f32 (1.0 - (double) f32 (std::exp ((double) x * std::log (5.0)) - 1.0) * 0.25);
+}
+
+// FUN_00612db0: start value, per-sample step (limited to maxStep) and new current value
+struct Ramp
+{
+    double start = 0.0, step = 0.0, end = 0.0;
+};
+
+Ramp ramp (double cur, double target, int n, double maxStep) noexcept
+{
+    const auto d = (double) f32 (target - cur);
+    if (d == 0.0)
+        return { cur, 0.0, cur };
+    auto step = (double) f32 (d / n);
+    auto end = target;
+    if (std::fabs (step) > maxStep)
+    {
+        step = std::copysign (maxStep, step);
+        end = (double) f32 (cur + step * n);
+    }
+    return { cur, step, end };
+}
+
+std::int32_t i32At (const std::vector<std::uint8_t>& d, std::size_t at) noexcept
+{
+    std::int32_t v = 0;
+    if (at + 4 <= d.size())
+        std::memcpy (&v, d.data() + at, 4);
+    return v;
+}
+} // namespace
+
+// =================================================================================================================
+// Maximus (REA_rodada36 §2)
+// =================================================================================================================
+
+namespace
+{
+// 2·(501^(v/10000) − 1) ms, kept as the float of (501^x − 1)
+double tms (int v) noexcept
+{
+    return (double) f32 (std::exp ((double) f32 ((float) v * 0.0001f) * std::log (501.0)) - 1.0);
+}
+
+// L7: (7^x − 1)/6, exactly 1 at x = 1
+float l7 (int v) noexcept
+{
+    const auto x = (float) v * 0.001f;
+    if (x == 1.0f)
+        return 1.0f;
+    return f32 ((std::exp ((double) (x * (float) std::log (7.0))) - 1.0) * (double) (1.0f / 6.0f));
+}
+
+double coefFor (double n) noexcept // 1 % in n samples
+{
+    return n > 0.0 ? std::exp (ln001 / std::max (1.0, n)) : 0.0;
+}
+
+struct Point
+{
+    double dx = 0.0;
+    float y = 0.0f, tension = 0.0f, q = 0.0f, b = 0.0f, c = 0.0f;
+    int type = 0, sign = 0;
+};
+
+// one drawn envelope (the compression curve) and its incremental evaluation (FUN_007885d0)
+class Curve
+{
+public:
+    explicit Curve (std::vector<Point> pts) : p (std::move (pts)) {}
+
+    bool supported() const noexcept
+    {
+        if (p.empty())
+            return false;
+        for (std::size_t i = 1; i < p.size(); ++i)
+            if (p[i].type != 0 && p[i].type != 7)
+                return false;
+        return true;
+    }
+
+    void start() noexcept
+    {
+        idx = 0;
+        y0 = p[0].y;
+        dy = 0.0;
+        if (p[0].dx == 0.0)
+            rate = 1.0, t = 1.0;
+        else
+            rate = 1.0 / p[0].dx, t = 0.0;
+    }
+
+    double step (double dx) noexcept
+    {
+        const auto n = (int) p.size();
+        t += dx * rate;
+        while (t >= 1.0)
+        {
+            const auto old = idx;
+            t = rate == 0.0 ? dx : (t - 1.0) / rate;
+            y0 = p[(std::size_t) idx].y;
+            if (idx < n - 1)
+                ++idx;
+            dy = (double) p[(std::size_t) idx].y - y0;
+            if (old == idx)
+                t = 0.0, rate = 0.0;
+            else if (const auto d = p[(std::size_t) idx].dx; d <= 0.0)
+                rate = 1.0, t += 1.0;
+            else
+                rate = 1.0 / d, t *= rate;
+        }
+        auto s = t;
+        const auto& pt = p[(std::size_t) idx];
+        if (pt.sign != 2)
+        {
+            if (pt.type == 0)
+            {
+                if (pt.q > 0.0f)
+                    s = 1.0 - (std::exp ((1.0 - s) * (double) pt.c) - 1.0) * (double) pt.b;
+                else if (pt.q < 0.0f)
+                    s = (std::exp (s * (double) pt.c) - 1.0) * (double) pt.b;
+            }
+            else // type 7
+            {
+                const auto u = pt.sign > 0 ? 1.0 - s : s;
+                const auto u3 = u * u * u;
+                s = s - (u3 * u3 - u) * (double) pt.tension;
+            }
+        }
+        return y0 + s * dy;
+    }
+
+private:
+    std::vector<Point> p;
+    int idx = 0;
+    double t = 0.0, rate = 0.0, y0 = 0.0, dy = 0.0;
+};
+} // namespace
+
+struct MaximusPreset
+{
+    std::array<int, 59> p {};
+    int oversampling = 0; // order: ×2^order
+    float scale = 0.975f; // output ceiling of the curves (−0.22 dB)
+    struct Band
+    {
+        std::vector<float> gain;  // static gain (output / input) for input levels i/8192
+        int size = 0;             // last entry before the curve reaches the ceiling
+        double end = 0.0, peak = 1.0;
+        std::vector<float> sat;   // soft-saturation table (mode A), 65 538 entries; empty = none
+        float satOut = 0.0f, satIn = 0.0f;
+        float pre = 1.0f, post = 1.0f, g20 = 1.0f;
+        std::array<float, 4> matrix { 1.0f, 1.0f, 0.0f, 0.0f };
+    };
+    std::array<Band, 4> band {};
+    bool valid = false;
+};
+
+namespace
+{
+std::vector<Point> readCurve (const std::vector<std::uint8_t>& d, std::size_t& pos, bool& ok)
+{
+    std::vector<Point> pts;
+    const auto n = i32At (d, pos + 8);
+    if (n < 1 || n > 4096 || pos + 12 + 24 * (std::size_t) n + 20 > d.size())
+    {
+        ok = false;
+        return pts;
+    }
+    for (int k = 0; k < n; ++k)
+    {
+        const auto at = pos + 12 + 24 * (std::size_t) k;
+        double dx = 0.0, y = 0.0;
+        float ten = 0.0f;
+        std::memcpy (&dx, d.data() + at, 8);
+        std::memcpy (&y, d.data() + at + 8, 8);
+        std::memcpy (&ten, d.data() + at + 16, 4);
+        Point pt;
+        pt.dx = std::isfinite (dx) && dx > 0.0 ? dx : 0.0;
+        pt.y = std::isfinite (y) ? (float) y : 0.0f;
+        pt.tension = std::isfinite (ten) ? ten : 0.0f;
+        pt.type = d[at + 20];
+        pt.sign = pt.tension == 0.0f ? 0 : (pt.tension < 0.0f ? -1 : 1);
+        if (k > 0)
+        {
+            if (pt.type < 2)
+            {
+                auto q = f32 (std::exp ((double) std::fabs (pt.tension) * std::log (1000001.0)) - 1.0);
+                if (pt.tension < 0.0f)
+                    q = -q;
+                pt.q = q;
+                if (q != 0.0f)
+                {
+                    pt.b = f32 (1.0 / std::fabs ((double) q));
+                    pt.c = f32 (std::log (std::fabs ((double) q) + 1.0));
+                }
+            }
+            if ((pt.type == 0 || pt.type == 7) && pt.tension == 0.0f)
+                pt.sign = 2; // straight segment
+        }
+        pts.push_back (pt);
+    }
+    pos += 12 + 24 * (std::size_t) n + 20;
+    return pts;
+}
+
+// FUN_00845b50
+void buildGainTable (Curve& curve, float scale, MaximusPreset::Band& b)
+{
+    curve.start();
+    b.gain.assign (32770, 0.0f);
+    const auto dv9 = 0.5 / std::log (3.0), dv10 = std::log (3.0) * 2.0, dv14 = (double) scale * 0.5;
+    double prev = 0.0, out = 0.0, mx = 0.0;
+    int lastOk = 0;
+    for (int i = 0; i < 32769; ++i)
+    {
+        const auto lv = (double) std::max (i, 1);
+        const auto c = std::log (lv * 0.0001220703125 * 2.0 + 1.0) * dv9;
+        const auto y = curve.step (c - prev);
+        prev = c;
+        out = (std::exp (y * dv10) - 1.0) * dv14;
+        auto idx = i;
+        if (std::fabs (out - (double) scale) < 5.960464477539063e-08)
+            out = (double) scale, idx = lastOk;
+        mx = std::max (mx, out);
+        b.gain[(std::size_t) i] = f32 (out / (lv * 0.0001220703125));
+        lastOk = idx;
+    }
+    b.gain[(std::size_t) lastOk + 1] = b.gain[(std::size_t) lastOk];
+    b.gain.resize ((std::size_t) lastOk + 2);
+    b.size = lastOk;
+    b.end = out;
+    b.peak = mx / (double) scale;
+}
+
+// FUN_00841380, mode A (threshold < 0)
+void buildSaturation (int thr, float ceil, double top, MaximusPreset::Band& b)
+{
+    const auto p = (double) f32 ((float) (20.0f - f32 ((float) std::log ((double) f32 (f32 (thr * -0.1) + 1.0f)) / std::log (101.0)) * 19.0f));
+    const auto ip = 1.0 / p;
+    auto d = 1.0;
+    if (ceil > 0.0f)
+        d = top / ((double) ceil * 65536.0);
+    const auto norm = 1.0 / std::pow (std::atan (std::pow (d * 65536.0, p)), ip);
+    b.sat.assign (65538, 0.0f);
+    for (int i = 0; i <= 65536; ++i)
+    {
+        auto v = std::pow (std::atan (std::pow (i * d, p)), ip) * norm;
+        if (v < 5.960464477539063e-08)
+            v = 0.0;
+        b.sat[(std::size_t) i] = (float) v;
+    }
+    b.sat[65537] = b.sat[65536];
+    b.satOut = ceil;
+    b.satIn = f32 (1.0 / top);
+}
+} // namespace
+
+std::optional<std::vector<std::uint8_t>> maximusStateFromFst (const std::vector<std::uint8_t>& b)
+{
+    if (b.size() < 22 || std::memcmp (b.data(), "FLhd", 4) != 0)
+        return std::nullopt;
+    auto pos = 8 + (std::size_t) std::max (0, i32At (b, 4));
+    if (pos + 8 > b.size() || std::memcmp (b.data() + pos, "FLdt", 4) != 0)
+        return std::nullopt;
+    pos += 8;
+    while (pos < b.size())
+    {
+        const auto id = b[pos++];
+        std::size_t len = 0;
+        if (id < 64)
+            len = 1;
+        else if (id < 128)
+            len = 2;
+        else if (id < 192)
+            len = 4;
+        else
+        {
+            int shift = 0;
+            while (pos < b.size())
+            {
+                const auto c = b[pos++];
+                len |= (std::size_t) (c & 0x7f) << shift;
+                shift += 7;
+                if (! (c & 0x80) || shift > 28)
+                    break;
+            }
+        }
+        if (pos + len > b.size())
+            return std::nullopt;
+        if (id == 0xD5)
+            return std::vector<std::uint8_t> (b.begin() + (std::ptrdiff_t) pos, b.begin() + (std::ptrdiff_t) (pos + len));
+        pos += len;
+    }
+    return std::nullopt;
+}
+
+std::shared_ptr<const MaximusPreset> makeMaximusPreset (const std::vector<std::uint8_t>& d)
+{
+    if (d.size() < 0x1fe + 12)
+        return nullptr;
+    auto m = std::make_shared<MaximusPreset>();
+    const auto header = (std::uint32_t) i32At (d, 0);
+    const auto version = header > 0xFFFFu ? (int) (header >> 16) : (int) header;
+    if (version < 7)
+        return nullptr; // older layouts are not used by Harmless's presets
+    for (int i = 0; i < 59; ++i)
+        m->p[(std::size_t) i] = i32At (d, 4 + 4 * (std::size_t) i);
+    m->oversampling = i32At (d, 0x1f4);
+    if (m->oversampling < 0 || m->oversampling > 1)
+        return nullptr; // only ×1 and ×2 are used by Harmless's presets
+    std::size_t pos = 0x1fe;
+    if (version >= 14)
+    {
+        if ((d[pos + 8] & 0x40) != 0)
+            m->scale = 1.0f;
+        pos += 9 + 20;
+    }
+    if (version >= 15)
+        pos += 4;
+    std::array<std::vector<Point>, 8> env;
+    bool ok = true;
+    for (auto& e : env)
+        if (ok)
+            e = readCurve (d, pos, ok);
+    if (! ok)
+        return nullptr;
+
+    const auto& p = m->p;
+    for (int b = 0; b < 4; ++b)
+    {
+        auto q = [&] (int j) { return p[(std::size_t) (13 * b + j)]; };
+        auto& B = m->band[(std::size_t) b];
+        const auto mode = q (7);
+        B.pre = l7 (q (8));
+        B.post = l7 (q (9));
+        // stereo separation (FUN_00616320 with pan 0, volume 1): positive narrows toward mono, negative widens
+        if (const auto sep = (float) q (10) * 0.001f; sep != 0.0f)
+        {
+            auto s = sep < 0.0f ? sep : f32 ((double) f32 (std::exp ((double) sep * std::log (5.0)) - 1.0) * 0.25);
+            s = std::min (1.0f, s);
+            const auto h = s * 0.5f;
+            B.matrix = { 1.0f - h, 1.0f - h, h, h };
+        }
+        Curve curve (env[(std::size_t) (2 * b)]);
+        if (! curve.supported())
+            return nullptr;
+        buildGainTable (curve, m->scale, B);
+        B.g20 = (B.pre * B.post) * B.gain[0];
+        const auto thr = q (11);
+        if (thr > 0 || (q (19) != 0 && mode == 0))
+            return nullptr; // saturation mode B, RMS detector: not decoded (not used by Harmless's presets)
+        if (thr < 0)
+        {
+            const auto top0 = (q (19) == 0 && mode < 1) ? B.peak : 4.0;
+            const auto ceil = l7 (q (12));
+            buildSaturation (thr, ceil, std::max (top0 * (double) B.post, (double) ceil), B);
+        }
+    }
+    m->valid = true;
+    return m;
+}
+
+namespace
+{
+// FUN_00624580 (types 1 low-pass, 4 high-pass, 5 all-pass) + FUN_00624e90 (stereo direct form I in double, the
+// states rounded to float at the end of every block)
+struct Biquad
+{
+    int type = 1;
+    double b0 = 0, b1 = 0, b2 = 0, a1 = 0, a2 = 0;
+    std::array<double, 8> s {}; // per channel: x1 x2 y1 y2
+
+    void design (int kind, double w, double alpha) noexcept
+    {
+        type = kind;
+        const auto sn = std::sin (w), cs = std::cos (w);
+        const auto a = alpha * sn;
+        const auto norm = 1.0 / (a + 1.0);
+        a1 = norm * cs * -2.0;
+        a2 = norm * (1.0 - a);
+        if (kind == 1)
+            b1 = norm * (1.0 - cs), b0 = b1 * 0.5, b2 = b0;
+        else if (kind == 4)
+            b1 = norm * -(cs + 1.0), b0 = -b1 * 0.5, b2 = b0;
+        else
+            b1 = a1, b0 = a2, b2 = 1.0;
+    }
+
+    void reset() noexcept { s = {}; }
+
+    void process (const float* inL, const float* inR, float* outL, float* outR, int n) noexcept
+    {
+        // both channels in one loop (two independent recursions; the same arithmetic per channel)
+        auto lx1 = s[0], lx2 = s[1], ly1 = s[2], ly2 = s[3], rx1 = s[4], rx2 = s[5], ry1 = s[6], ry2 = s[7];
+        for (int i = 0; i < n; ++i)
+        {
+            const auto xl = (double) inL[i], xr = (double) inR[i];
+            const auto yl = xl * b0 + (((lx1 * b1 - ly2 * a2) + lx2 * b2) - ly1 * a1);
+            const auto yr = xr * b0 + (((rx1 * b1 - ry2 * a2) + rx2 * b2) - ry1 * a1);
+            outL[i] = (float) yl, outR[i] = (float) yr;
+            lx2 = lx1, lx1 = xl, ly2 = ly1, ly1 = yl;
+            rx2 = rx1, rx1 = xr, ry2 = ry1, ry1 = yr;
+        }
+        s = { flush (lx1), flush (lx2), flush (ly1), flush (ly2), flush (rx1), flush (rx2), flush (ry1), flush (ry2) };
+    }
+};
+
+// alpha = sin·k: order 0 (12 dB stage) k = 1, order 1 (24 dB, two stages) k = 1/√2
+double crossoverAlpha (int order) noexcept { return order == 1 ? 0.70710678118654746 : 1.0; }
+
+// one 2:1 stage (FUN_0083a9c0 up, FUN_0083ab90 down): two cascades of three first-order all-passes
+struct Halfband
+{
+    static constexpr double ka[3] { 0.14737711360104661, 0.48246854276970014, 0.88300502576937312 };
+    static constexpr double kb[3] { 0.039151597734460045, 0.30264684832849342, 0.6746159185469639 };
+    std::array<double, 24> s {}; // per channel 12: A outputs, A inputs, B outputs, B inputs
+
+    void reset() noexcept { s = {}; }
+
+    static double chain (double* st, double x, const double* k) noexcept
+    {
+        const auto y1 = st[3] + (x - st[0]) * k[0];
+        st[3] = x;
+        const auto y2 = st[4] + (y1 - st[1]) * k[1];
+        st[4] = y1;
+        const auto y3 = st[5] + (y2 - st[2]) * k[2];
+        st[5] = y2;
+        st[0] = y1, st[1] = y2, st[2] = y3;
+        return y3;
+    }
+
+    void endBlock() noexcept
+    {
+        for (int c = 0; c < 2; ++c)
+            for (int k : { 0, 1, 2, 6, 7, 8 })
+                s[(std::size_t) (12 * c + k)] = flush (s[(std::size_t) (12 * c + k)]);
+    }
+
+    void up (const float* inL, const float* inR, float* outL, float* outR, int n) noexcept
+    {
+        const float* in[2] { inL, inR };
+        float* out[2] { outL, outR };
+        for (int c = 0; c < 2; ++c)
+        {
+            auto* st = s.data() + 12 * c;
+            for (int i = 0; i < n; ++i)
+            {
+                const auto v = (double) in[c][i];
+                const auto a = chain (st, v, ka);
+                const auto b = chain (st + 6, v, kb);
+                out[c][2 * i] = (float) b;
+                out[c][2 * i + 1] = (float) a;
+            }
+        }
+        endBlock();
+    }
+
+    void down (const float* inL, const float* inR, float* outL, float* outR, int n) noexcept // n output frames
+    {
+        const float* in[2] { inL, inR };
+        float* out[2] { outL, outR };
+        for (int c = 0; c < 2; ++c)
+        {
+            auto* st = s.data() + 12 * c;
+            for (int i = 0; i < n; ++i)
+            {
+                const auto a = chain (st, (double) in[c][2 * i], ka);
+                const auto b = chain (st + 6, (double) in[c][2 * i + 1], kb);
+                out[c][i] = (float) ((b + a) * 0.5);
+            }
+        }
+        endBlock();
+    }
+};
+
+// FUN_00605410: one-pole on a control signal, c0 while the input is ≥ the state, c1 otherwise
+struct Smoother
+{
+    float c0 = 0.0f, c1 = 0.0f, s = 0.0f;
+
+    void run (float* x, int n) noexcept
+    {
+        auto st = s;
+        if (c0 == c1)
+            for (int i = 0; i < n; ++i)
+                st = (st - x[i]) * c0 + x[i], x[i] = st;
+        else
+            for (int i = 0; i < n; ++i)
+            {
+                const auto c = st <= x[i] ? c0 : c1;
+                st = x[i] + c * (st - x[i]);
+                x[i] = st;
+            }
+        s = std::fabs (st) > flushLevel ? st : 0.0f;
+    }
+};
+
+// FUN_00629710 + FUN_007806b0: max(|L|, |R|), then the running maximum over the last W samples
+struct PeakWindow
+{
+    int W = 1, pos = 0, head = 0, tail = 0, count = 0;
+    std::vector<std::int32_t> ring, dq;
+
+    void setLength (int w)
+    {
+        W = std::max (1, w);
+        ring.assign ((std::size_t) W, 0);
+        dq.assign ((std::size_t) W, 0);
+        pos = 0, head = W > 1 ? 1 : 0, tail = 0, count = 0;
+    }
+
+    void run (const float* L, const float* R, float* out, int n) noexcept
+    {
+        for (int i = 0; i < n; ++i)
+            out[i] = std::max (std::fabs (L[i]), std::fabs (R[i]));
+        if (W <= 1)
+            return;
+        for (int i = 0; i < n; ++i)
+        {
+            std::int32_t x = 0;
+            std::memcpy (&x, out + i, 4);
+            auto next = pos + 1;
+            if (next >= W)
+                next = 0;
+            const auto old = count < 1 ? ring[(std::size_t) pos] : ring[(std::size_t) dq[(std::size_t) head]];
+            if (ring[(std::size_t) pos] < x)
+            {
+                while (count > 0)
+                {
+                    if (x <= ring[(std::size_t) dq[(std::size_t) tail]])
+                    {
+                        const auto j = dq[(std::size_t) head] - 1;
+                        if (next == j || next == j + W)
+                        {
+                            --count;
+                            if (++head >= W)
+                                head = 0;
+                        }
+                        break;
+                    }
+                    --count;
+                    if (--tail < 0)
+                        tail = W - 1;
+                }
+            }
+            else
+            {
+                if (++tail >= W)
+                    tail = 0;
+                dq[(std::size_t) tail] = pos;
+                const auto j = dq[(std::size_t) head] - 1;
+                if (next == j || next == j + W)
+                {
+                    if (++head >= W)
+                        head = 0;
+                }
+                else
+                    ++count;
+            }
+            ring[(std::size_t) next] = x;
+            if (x < old)
+                x = old;
+            std::memcpy (out + i, &x, 4);
+            pos = next;
+        }
+    }
+};
+
+// FUN_0077f350: L-frame delay (swap ring)
+struct FrameDelay
+{
+    std::vector<float> l, r;
+    int L = 0, p = 0;
+
+    void setLength (int n)
+    {
+        L = std::max (0, n);
+        l.assign ((std::size_t) std::max (1, L), 0.0f);
+        r.assign ((std::size_t) std::max (1, L), 0.0f);
+        p = 0;
+    }
+
+    void reset() noexcept
+    {
+        std::fill (l.begin(), l.end(), 0.0f);
+        std::fill (r.begin(), r.end(), 0.0f);
+        p = 0;
+    }
+
+    void run (float* xl, float* xr, int n) noexcept
+    {
+        if (L == 0)
+            return;
+        for (int i = 0; i < n; ++i)
+        {
+            std::swap (xl[i], l[(std::size_t) p]);
+            std::swap (xr[i], r[(std::size_t) p]);
+            if (++p >= L)
+                p = 0;
+        }
+    }
+};
+} // namespace
+
+class Maximus
+{
+public:
+    static constexpr int maxFrames = Rack::maxBlock * 8;
+
+    void prepare (std::shared_ptr<const MaximusPreset> preset, double rate, int mixParam)
+    {
+        pr = std::move (preset);
+        fs = rate;
+        const auto& P = *pr;
+        const auto& p = P.p;
+        K = 1 << P.oversampling;
+        mix = (float) mixParam * 0.001f;
+        mixOn = mix != 1.0f;
+        std::array<int, 4> mode {};
+        for (int b = 0; b < 4; ++b)
+            mode[(std::size_t) b] = p[(std::size_t) (7 + 13 * b)];
+        const auto anyComp = mode[0] < 1 || mode[1] < 1 || mode[2] < 1;
+        int latency = 0;
+        for (int b = 0; b < 4; ++b)
+        {
+            auto q = [&] (int j) { return p[(std::size_t) (13 * b + j)]; };
+            auto& B = band[(std::size_t) b];
+            B.mode = mode[(std::size_t) b];
+            const auto k = b == 3 ? 1 : K;
+            int L = 0;
+            if (B.mode < 2 && (b != 3 || B.mode < 1) && (b > 2 || anyComp))
+                L = (int) rint (tms (b == 3 ? q (13) : p[4]) * 2.0 * 0.001 * fs) * k;
+            B.L = L;
+            if (b < 3)
+                latency = std::max (latency, L);
+            const auto a = q (13);
+            const auto A = a == 0 ? (double) L : tms (a) * 2.0 * 0.001 * fs * k;
+            const auto na = std::max (1, q (15));
+            const auto attN = (A * 0.800000011920929) / std::sqrt ((double) na);
+            const auto rel2N = q (14) == 0 ? attN : (tms (q (14)) * 2.0 * 0.001 * fs * k * 2.0) / std::sqrt ((double) na);
+            const auto sus = (int) rint (tms (q (18)) * 2.0 * 0.001 * fs);
+            B.det.setLength (std::max (std::max (L, 1), sus * k));
+            B.att.assign ((std::size_t) na, Smoother { f32 (coefFor (rel2N)), f32 (coefFor (attN)), 0.0f });
+            const auto R = tms (q (16)) * 2.0 * 0.001 * fs * k;
+            B.rel.clear();
+            if (R > 0.0)
+            {
+                const auto nr = std::max (1, q (17));
+                B.rel.assign ((std::size_t) nr, Smoother { 0.0f, f32 (coefFor ((R * 2.0) / std::sqrt ((double) nr))), 0.0f });
+            }
+            B.delay.setLength (L);
+        }
+        latency = latency / K + band[3].L;
+        tailLength = latency + (int) rint (fs * 1.5);
+
+        // crossover (FUN_00844e10)
+        auto freq = [&] (int v) { return f32 (std::exp ((double) v * 0.00013822774794088088 * 0.69314718055994529) * 30.0); };
+        auto fL = freq (p[0]), fH = freq (p[2]);
+        const auto sL = mode[0] != 3 ? std::clamp (p[1], 0, 1) : -1;
+        const auto sH = mode[2] != 3 ? std::clamp (p[3], 0, 1) : -1;
+        if (sL >= 0 && sH >= 0 && fH < fL)
+            std::swap (fL, fH);
+        first = 1;
+        for (int b = 0; b < 3; ++b)
+            if (mode[(std::size_t) b] != 3)
+            {
+                first = b;
+                break;
+            }
+        auto polarity = [] (int s) { return s < 0 ? 0.0f : s == 0 ? -1.0f : 1.0f; };
+        band[0].g18 = polarity (sL), band[1].g18 = 1.0f, band[2].g18 = polarity (sH), band[3].g18 = 1.0f;
+        const auto rateB = fs * K, fmax = (double) f32 (0.4999 * rateB), w = 2.0 * pi / rateB;
+        auto stage = [&] (int type, float f, int order) {
+            Biquad q;
+            const auto fc = std::min ((double) f, fmax);
+            q.design (type, fc * w, crossoverAlpha (order));
+            return q;
+        };
+        for (auto& s : stages)
+            s.clear();
+        const auto n0 = sL + (sH > 0 ? 1 : 0) + 1;
+        for (int i = 0; i < n0; ++i)
+            stages[0].push_back (i == n0 - 1 && sH > 0 ? stage (5, fH, 0) : stage (1, fL, sL));
+        for (int i = 0; i <= sL; ++i)
+            stages[1].push_back (stage (4, fL, sL));
+        for (int i = 0; i <= sH; ++i)
+            stages[1].push_back (stage (1, fH, sH));
+        for (int i = 0; i <= sH; ++i)
+            stages[2].push_back (stage (4, fH, sH));
+        inPlaceStages = std::min (sL + 1, (int) stages[1].size() - 1);
+
+        // low cut: four high-pass stages at 0.8·f (FUN_00840b40, FUN_0083a5c0)
+        lowCut.clear();
+        if (p[6] >= 0)
+        {
+            const auto f = f32 (std::exp ((double) p[6] * 6.103515625e-05 * 0.69314718055994529) * 5.0);
+            for (const auto k : { 0.19771184027194977, 0.61932772397995, 0.6768445372581482, 1.0793569087982178 })
+            {
+                Biquad q;
+                q.design (4, ((double) f * 0.8) * (2.0 * pi / fs), k);
+                lowCut.push_back (q);
+            }
+        }
+        for (auto& h : up)
+            h.reset();
+        for (auto& h : down)
+            h.reset();
+        reset();
+        counter = -1073741823;
+    }
+
+    void reset() noexcept
+    {
+        for (int b = 0; b < 4; ++b)
+        {
+            auto& B = band[(std::size_t) b];
+            for (auto& s : B.att)
+                s.s = pr->band[(std::size_t) b].g20;
+            for (auto& s : B.rel)
+                s.s = 0.0f;
+            B.delay.reset();
+        }
+        for (auto& st : stages)
+            for (auto& q : st)
+                q.reset();
+        for (auto& q : lowCut)
+            q.reset();
+        for (auto& h : up)
+            h.reset();
+        for (auto& h : down)
+            h.reset();
+    }
+
+    // silence fed while the rack is idle (Eff_Render's silent-block counter, then the reset after 1.5 s)
+    void silence (int n) noexcept
+    {
+        counter -= n;
+        if (! (counter > -n))
+        {
+            if (counter > -0x3fffffff)
+                reset();
+            counter = -1073741823;
+        }
+    }
+
+    void process (float* L, float* R, int n) noexcept
+    {
+        bool silent = true;
+        for (int i = 0; i < n && silent; ++i)
+            silent = std::fabs (L[i]) <= 9.999999974752427e-07f && std::fabs (R[i]) <= 9.999999974752427e-07f;
+        if (! silent)
+            counter = tailLength;
+        else
+            counter -= n;
+        if (! (counter > -n))
+        {
+            if (counter > -0x3fffffff)
+                reset();
+            counter = -1073741823;
+            return;
+        }
+        for (auto& q : lowCut)
+            q.process (L, R, L, R, n);
+        // X: the signal being split (at the band rate)
+        const auto nb = n * K;
+        float* XL = L;
+        float* XR = R;
+        if (K > 1)
+        {
+            up[0].up (L, R, xl.data(), xr.data(), n);
+            XL = xl.data(), XR = xr.data();
+        }
+        bool haveSum = false;
+        for (int b = 0; b < 3; ++b)
+        {
+            auto& st = stages[(std::size_t) b];
+            float* yl = bl.data();
+            float* yr = br.data();
+            if (st.empty())
+                std::copy (XL, XL + nb, yl), std::copy (XR, XR + nb, yr);
+            else if (b == 1 && b != first)
+            {
+                const float* sl = XL;
+                const float* sr = XR;
+                for (int k = 0; k < (int) st.size(); ++k)
+                {
+                    float* dl = k < inPlaceStages ? XL : yl;
+                    float* dr = k < inPlaceStages ? XR : yr;
+                    st[(std::size_t) k].process (sl, sr, dl, dr, nb);
+                    sl = dl, sr = dr;
+                }
+                if (st.size() <= (std::size_t) inPlaceStages) // (not reached with the presets: kept literal)
+                    std::copy (sl, sl + nb, yl), std::copy (sr, sr + nb, yr);
+            }
+            else
+            {
+                const float* sl = XL;
+                const float* sr = XR;
+                for (auto& q : st)
+                {
+                    q.process (sl, sr, yl, yr, nb);
+                    sl = yl, sr = yr;
+                }
+            }
+            auto& B = band[(std::size_t) b];
+            processBand (b, yl, yr, nb);
+            if (B.mode < 2)
+            {
+                if (! haveSum)
+                    std::copy (yl, yl + nb, sl.data()), std::copy (yr, yr + nb, sr.data()), haveSum = true;
+                else
+                    for (int i = 0; i < nb; ++i)
+                        sl[(std::size_t) i] = sl[(std::size_t) i] + yl[i], sr[(std::size_t) i] = sr[(std::size_t) i] + yr[i];
+            }
+            else if (b == first)
+            {
+                std::fill (sl.begin(), sl.begin() + nb, 0.0f), std::fill (sr.begin(), sr.begin() + nb, 0.0f);
+                haveSum = true;
+            }
+        }
+        if (! haveSum)
+            std::fill (sl.begin(), sl.begin() + nb, 0.0f), std::fill (sr.begin(), sr.begin() + nb, 0.0f);
+        if (K > 1)
+            down[0].down (sl.data(), sr.data(), L, R, n);
+        else
+            std::copy (sl.begin(), sl.begin() + n, L), std::copy (sr.begin(), sr.begin() + n, R);
+        processBand (3, L, R, n);
+    }
+
+private:
+    struct BandState
+    {
+        int mode = 3, L = 0;
+        float g18 = 1.0f;
+        PeakWindow det;
+        std::vector<Smoother> att, rel;
+        FrameDelay delay;
+    };
+
+    void processBand (int b, float* xl, float* xr, int n) noexcept
+    {
+        auto& B = band[(std::size_t) b];
+        const auto& S = pr->band[(std::size_t) b];
+        if (B.mode < 2)
+        {
+            const auto& m = S.matrix;
+            if (m[2] != 0.0f || m[3] != 0.0f)
+                for (int i = 0; i < n; ++i)
+                {
+                    const auto l = xl[i], r = xr[i];
+                    xl[i] = l * m[0] + r * m[2];
+                    xr[i] = r * m[1] + l * m[3];
+                }
+            else if (m[0] != 1.0f || m[1] != 1.0f)
+                for (int i = 0; i < n; ++i)
+                    xl[i] = xl[i] * m[0], xr[i] = xr[i] * m[1];
+        }
+        float* g = gain.data();
+        if (B.mode == 0)
+        {
+            B.det.run (xl, xr, g, n);
+            for (auto& s : B.rel)
+                s.run (g, n);
+            const auto k = f32 ((double) S.pre * 8192.25);
+            const auto pp = S.pre * S.post;
+            const auto hiGain = f32 (S.end * (double) S.post);
+            const auto* t = S.gain.data();
+            for (int i = 0; i < n; ++i)
+            {
+                const auto lv = g[i];
+                const auto idxf = lv * k;
+                auto idx = (int) idxf; // ippsConvert_32f32s_Sfs, rounding toward zero
+                if (idx < 0)
+                    idx = 0;
+                if (idx > S.size)
+                    g[i] = hiGain / lv;
+                else
+                {
+                    const auto fr = idxf - (float) idx;
+                    g[i] = (t[idx] + (t[idx + 1] - t[idx]) * fr) * pp;
+                }
+            }
+            for (auto& s : B.att)
+                s.run (g, n);
+        }
+        B.delay.run (xl, xr, n);
+        const auto keepDry = mixOn && b < 3;
+        if (keepDry)
+            std::copy (xl, xl + n, dl.data()), std::copy (xr, xr + n, dr.data());
+        if (B.mode == 0)
+            for (int i = 0; i < n; ++i)
+                xl[i] = xl[i] * g[i], xr[i] = xr[i] * g[i];
+        else
+            for (int i = 0; i < n; ++i)
+                xl[i] = xl[i] * S.post, xr[i] = xr[i] * S.post;
+        if (! S.sat.empty() && B.mode < 2)
+        {
+            // FUN_0062a240 (x87, truncating control word): odd table read with linear interpolation
+            const auto k = (double) S.satIn * 65536.0;
+            const auto* t = S.sat.data();
+            auto sat = [&] (float x) {
+                const auto v = (double) x * k;
+                const auto a = std::fabs (v);
+                auto i = (long long) a;
+                const auto fr = a - (double) i;
+                i = std::min<long long> (i, 65536);
+                const auto y = (double) t[i] + ((double) t[i + 1] - (double) t[i]) * fr;
+                return (float) ((v < 0.0 ? -y : y) * (double) S.satOut);
+            };
+            for (int i = 0; i < n; ++i)
+                xl[i] = sat (xl[i]), xr[i] = sat (xr[i]);
+        }
+        if (b == 3)
+        {
+            if (B.mode == 2)
+                std::fill (xl, xl + n, 0.0f), std::fill (xr, xr + n, 0.0f);
+            return;
+        }
+        if (B.mode < 2)
+        {
+            if (mixOn)
+            {
+                const auto a = mix * B.g18, d = (1.0f - mix) * B.g18;
+                for (int i = 0; i < n; ++i)
+                {
+                    xl[i] = xl[i] * a + dl[(std::size_t) i] * d;
+                    xr[i] = xr[i] * a + dr[(std::size_t) i] * d;
+                }
+            }
+            else if (B.g18 == -1.0f)
+                for (int i = 0; i < n; ++i)
+                    xl[i] = -xl[i], xr[i] = -xr[i];
+        }
+    }
+
+    std::shared_ptr<const MaximusPreset> pr;
+    double fs = 44100.0;
+    int K = 1, first = 0, inPlaceStages = 0, tailLength = 0, counter = 0;
+    float mix = 1.0f;
+    bool mixOn = false;
+    std::array<BandState, 4> band {};
+    std::array<std::vector<Biquad>, 3> stages {};
+    std::vector<Biquad> lowCut;
+    std::array<Halfband, 1> up {}, down {};
+    std::array<float, maxFrames> xl {}, xr {}, bl {}, br {}, sl {}, sr {}, dl {}, dr {}, gain {};
+};
+
+// =================================================================================================================
+// Chorus, delay, reverb (REA_rodada36 §1)
+// =================================================================================================================
+
+// chorus records (table 0x7ee73c + 0x20·type, DATA): order, depth/1024, speed/1024, delay/128, spread/128, cross/128
+struct Rack::Chorus
+{
+    struct Tap
+    {
+        int ch = 0;
+        float gl = 0, gr = 0, p3 = 0, p8 = 0, p9 = 0, p10 = 0;
+        std::uint32_t phase = 0, inc = 0;
+    };
+    std::vector<Tap> taps;
+    float dry = 1.0f;
+    int maxDelay = 0;
+    std::vector<float> ringL, ringR; // input history, power-of-two length
+    int mask = 0, w = 0;
+
+    Chorus (int type, float mixKnob, double fs)
+    {
+        static constexpr int rec[8][6] { { 4, 512, 768, 8, 128, -32 }, { 5, 1024, 856, 0, 128, 68 }, { 7, 512, 512, 128, 128, 54 },
+                                         { 6, 561, 854, 0, 0, 38 },    { 1, 136, 312, 0, 0, 128 },   { 2, 86, 632, 0, 0, 0 },
+                                         { 1, 42, 944, 0, 0, -22 },    { 9, 81, 170, 0, 0, -66 } };
+        static constexpr float q[20] { 0.967f, 1.039f, 1.021f, 0.1013f, 0.977f, 1.033f, 0.997f, 0.971f, 1.061f, 0.947f,
+                                       1.031f, 0.1009f, 1.063f, 0.953f, 0.991f, 1.049f, 0.983f, 1.051f, 1.019f, 1.069f };
+        const auto* r = rec[std::clamp (type, 1, 8) - 1];
+        const auto N = r[0];
+        const auto depth = (float) r[1] * 0.0009765625f, speed = (float) r[2] * 0.0009765625f;
+        const auto dly = (float) r[3] * 0.0078125f, spread = (float) r[4] * 0.0078125f, cross = (float) r[5] * 0.0078125f;
+        dry = g5 (mixKnob);
+        const auto vol = g5 (f32 (1.0 - (double) mixKnob));
+        const auto A = f32 ((std::pow (11.0, (double) depth) - 1.0) * (1092.5 / 10.0));
+        const auto B = (2147483648.0 / ((double) f32 (std::pow (101.0, (double) f32 (1.0f - speed)) - 1.0) * 75000.0 + 50000.0)) * 500.0;
+        const auto C = f32 ((std::pow (11.0, (double) dly) - 1.0) * (4410.0 / 10.0));
+        const auto sg = f32 (f32 (std::pow (1001.0, (double) spread) - 1.0) / 1000.0f);
+        auto mixf = [&] (double a, double b) { return a * (double) sg + b * (1.0 - (double) sg); };
+        const auto fsr = f32 (44100.0 / fs);
+        float sumAbs = 0.0f, mx = 0.0f;
+        for (int i = 0; i < 2 * N; ++i)
+        {
+            Tap t;
+            float f = 0.0f;
+            std::uint32_t ph = 0;
+            if (i < N)
+                f = (float) i, t.ch = 0;
+            else
+                f = (float) (2 * N - 1 - i), t.ch = 1, ph = 0x80000000u;
+            const auto wv = 1.0f - f / (float) N;
+            const auto rr = q[i % 20];
+            const auto dV = f32 (mixf ((double) (rr * rr), 1.0));
+            float gl = 1.0f, gr = cross * wv;
+            if (t.ch)
+                std::swap (gl, gr);
+            sumAbs = f32 ((double) sumAbs + std::fabs ((double) gl) + std::fabs ((double) gr));
+            auto p0 = A * wv + 10.0f;
+            const auto d11 = mixf (B * (double) dV / (double) p0, B / (double) (A + 10.0f));
+            auto p3 = f32 (mixf ((double) ((C * wv) * dV), (double) C));
+            ph += (std::uint32_t) ((std::int64_t) rint ((double) ((wv * sg) * 2147483648.0f) / 256.0) << 8);
+            t.phase = ph;
+            t.inc = (std::uint32_t) (std::int64_t) rint (d11 * (double) fsr);
+            p0 = p0 / fsr;
+            auto t3 = p3 / fsr;
+            if (! (t3 > 8.0f))
+                t3 = 8.0f;
+            p3 = p0 + t3;
+            if (p3 + p0 > mx)
+                mx = p3 + p0;
+            const auto qq = std::sqrt ((double) (p0 * 4.0f));
+            t.gl = gl, t.gr = gr, t.p3 = p3;
+            t.p8 = f32 (qq / 2147483648.0), t.p9 = f32 (qq), t.p10 = f32 (qq / 2.0);
+            taps.push_back (t);
+        }
+        const auto norm = f32 ((double) (1.0f - f32 ((double) f32 (std::pow (1001.0, (double) (1.0f - 1.0f / sumAbs)) - 1.0) / 1000.0)) * (double) vol);
+        for (auto& t : taps)
+            t.gl = t.gl * norm, t.gr = t.gr * norm;
+        maxDelay = (int) rint ((double) mx) + 8;
+        int size = 1;
+        while (size < maxDelay + Rack::maxBlock + 8)
+            size <<= 1;
+        ringL.assign ((std::size_t) size, 0.0f);
+        ringR.assign ((std::size_t) size, 0.0f);
+        mask = size - 1;
+    }
+
+    void advance (int n) noexcept
+    {
+        for (auto& t : taps)
+            t.phase += t.inc * (std::uint32_t) n;
+    }
+
+    // out = Σ taps (no dry); in: this block of the mix
+    void process (const float* inL, const float* inR, float* outL, float* outR, int n) noexcept
+    {
+        for (int i = 0; i < n; ++i)
+            ringL[(std::size_t) ((w + i) & mask)] = inL[i], ringR[(std::size_t) ((w + i) & mask)] = inR[i];
+        std::fill (outL, outL + n, 0.0f);
+        std::fill (outR, outR + n, 0.0f);
+        bool firstTap = true;
+        for (auto& t : taps)
+        {
+            const auto& ring = t.ch ? ringR : ringL;
+            auto ph = t.phase;
+            for (int i = 0; i < n; ++i)
+            {
+                const auto sp = (double) (std::int32_t) ph;
+                auto v = std::fabs (sp * (double) t.p8) - (double) t.p10;
+                v = ((double) t.p9 - std::fabs (v)) * v + (double) t.p3;
+                ph += t.inc;
+                const auto k = (int) v; // x87 fistl with the truncating control word (v > 0)
+                const auto at = w + i - k;
+                const auto a = (double) ring[(std::size_t) (at & mask)], b = (double) ring[(std::size_t) ((at - 1) & mask)];
+                const auto s = (b - a) * (v - (double) k) + a;
+                if (firstTap)
+                    outL[i] = (float) (s * (double) t.gl), outR[i] = (float) (s * (double) t.gr);
+                else
+                    outL[i] = (float) (s * (double) t.gl + (double) outL[i]), outR[i] = (float) (s * (double) t.gr + (double) outR[i]);
+            }
+            t.phase = ph;
+            firstTap = false;
+        }
+        w = (w + n) & mask;
+    }
+};
+
+// delay records (table 0x7ee67c + 8·type, DATA): stereo offset in ms (sign = side), ping-pong
+struct Rack::Delay
+{
+    std::vector<float> l, r;
+    int S = 1, rp = 0, D = 1, oL = 0, oR = 0;
+    bool pingPong = false;
+    float vol = 0.0f, fb = 0.0f;
+    double cur = 0.0, maxStep = 0.001;
+
+    Delay (int type, int volKnob, int fbKnob, int time, double fs, double bpm)
+    {
+        static constexpr int rec[3][2] { { 0, 0 }, { 1, 2 }, { -20, 2 } };
+        const auto* rc = rec[std::clamp (type, 1, 3) - 1];
+        const auto o = (int) rint (std::abs (rc[0]) * 0.001 * fs);
+        if (rc[0] > 0)
+            oR = o;
+        else
+            oL = o;
+        pingPong = rc[1] != 0;
+        D = std::max (1, (int) rint ((double) time * fs * 0.3125 / std::max (1.0, bpm)));
+        vol = g11 ((float) volKnob * 0.001f);
+        fb = (float) fbKnob * 0.001f;
+        cur = fb; // the feedback ramp starts at its target (EXEC with the plugin's state loaded before the rate is set)
+        maxStep = (double) f32 (0.001 * 44100.0 / fs);
+        S = D + o + Rack::maxBlock + 8;
+        l.assign ((std::size_t) S, 0.0f);
+        r.assign ((std::size_t) S, 0.0f);
+    }
+
+    void write (const float* inL, const float* inR, int n) noexcept
+    {
+        const auto w = rp + D;
+        for (int i = 0; i < n; ++i)
+        {
+            auto& a = l[(std::size_t) ((w + oL + i) % S)];
+            a = a + inL[i] * vol;
+            auto& b = r[(std::size_t) ((w + oR + i) % S)];
+            b = b + inR[i] * vol;
+        }
+    }
+
+    void advance (int n) noexcept { cur = ramp (cur, fb, n, maxStep).end; }
+
+    void process (float* outL, float* outR, int n) noexcept
+    {
+        const auto rr = ramp (cur, fb, n, maxStep);
+        cur = rr.end;
+        auto g = rr.start;
+        for (int i = 0; i < n; ++i)
+        {
+            const auto a = l[(std::size_t) rp], b = r[(std::size_t) rp];
+            l[(std::size_t) rp] = 0.0f, r[(std::size_t) rp] = 0.0f;
+            const auto w = (rp + D) % S;
+            float fl = a, fr = b;
+            if (pingPong)
+                outL[i] = b, outR[i] = a, fl = b, fr = a;
+            else
+                outL[i] = a, outR[i] = b;
+            auto u = (float) ((double) fl * g + (double) l[(std::size_t) w]);
+            auto v = (float) ((double) fr * g + (double) r[(std::size_t) w]);
+            l[(std::size_t) w] = std::fabs (u) < flushLevel ? 0.0f : u;
+            r[(std::size_t) w] = std::fabs (v) < flushLevel ? 0.0f : v;
+            g += rr.step;
+            if (++rp >= S)
+                rp = 0;
+        }
+    }
+};
+
+// reverb records (table 0x7ee67c + 0x20·type, DATA): lowcut Hz, highcut ×100 Hz, predelay, room, diffusion,
+// decay ×0.1 s, damping ×100 Hz, colour; DSP of the shared Reverb_x64.dll (REA_rodada31 §7.5)
+struct Rack::Reverb
+{
+    std::array<std::vector<float>, 12> buf;
+    std::array<int, 12> L {}, P {};
+    std::array<int, 7> tl {}, tr {};
+    std::vector<float> pre;
+    int pp = 0;
+    float cHc = 1, cLc = 0, cDamp = 1, cIn = 0, c1 = 0, c2 = 0, g = 0, c48 = 0, c44 = 0;
+    float s10 = 0, s14 = 0, s18 = 0, s3c = 0, s40 = 0, s4c = 0, s50 = 0, s54 = 0, s58 = 0;
+
+    Reverb (int type, double fs)
+    {
+        static constexpr int rec[6][8] { { 75, 40, 0, 40, 100, 15, 40, 2 },  { 0, 115, 18, 40, 100, 22, 50, 2 },
+                                         { 34, 21, 27, 90, 100, 45, 31, 3 }, { 400, 60, 31, 60, 65, 23, 37, 1 },
+                                         { 100, 36, 0, 35, 100, 6, 36, 2 },  { 100, 60, 0, 17, 100, 5, 30, 2 } };
+        static constexpr int lines[12] { 142, 107, 379, 277, 672, 4453, 1800, 3720, 908, 4217, 2656, 3163 };
+        static constexpr int tapsL[7] { 266, 2974, 1913, 2496, 1690, 187, 1566 };
+        static constexpr int tapsR[7] { 353, 3627, 1728, 3173, 1811, 335, 621 };
+        static constexpr double colour[5] { 0.2, 0.6, 1.0, 1.5, 3.0 };
+        const auto* r = rec[std::clamp (type, 1, 6) - 1];
+        const auto rate = (long long) fs;
+        const auto preS = (int) rint ((double) r[2] * (double) rate / 384.0);
+        const auto decay = (double) f32 ((double) r[5] * (double) rate / 10.0);
+        const auto f17 = (double) f32 (1.0 / (double) rate), half = (double) f32 ((double) rate * 0.5);
+        if (r[0] != 0)
+        {
+            const auto t = (double) f32 (std::tan (std::min ((double) r[0], half) * pi * f17));
+            cLc = f32 ((t - 1.0) / (t + 1.0));
+        }
+        auto lp = [&] (int v) {
+            if (v == 0)
+                return 1.0f;
+            const auto x = (double) f32 (2.0 - std::cos (std::min ((double) v, half) * 628.3185307179587 * f17));
+            return f32 (1.0 - (x - std::sqrt (x * x - 1.0)));
+        };
+        cHc = lp (r[1]);
+        cDamp = lp (r[6]);
+        auto muldiv = [] (long long a, long long b, long long c) { return (int) ((a * b) / c); };
+        const auto sc = muldiv (rate, r[3] + 15, 115);
+        for (int i = 0; i < 12; ++i)
+        {
+            L[(std::size_t) i] = std::max (1, muldiv (lines[i], sc, 20000));
+            buf[(std::size_t) i].assign ((std::size_t) L[(std::size_t) i], 0.0f);
+        }
+        for (int i = 0; i < 7; ++i)
+            tl[(std::size_t) i] = muldiv (tapsL[i], sc, 20000), tr[(std::size_t) i] = muldiv (tapsR[i], sc, 20000);
+        const auto dv = (double) f32 (r[4] * 0.01), f13 = (double) f32 (f17 * 0.5);
+        if (dv != 0.0)
+        {
+            auto e = [&] (int a, int b, double k) { return f32 (std::exp (std::log (0.001) * (double) f32 ((a + b) * f13) / (dv * k))); };
+            cIn = e (L[0], L[1], 0.07), c1 = e (L[4], L[8], 0.35), c2 = e (L[6], L[10], 0.51);
+        }
+        const auto ssum = (double) (L[5] + L[7] + L[9] + L[11]);
+        g = f32 (std::pow (std::exp (std::log (0.001) * ssum / decay), 0.25));
+        auto r2 = (double) f32 ((double) f32 (std::pow (std::exp (std::log (0.001) * ssum / (double) f32 (decay * colour[std::clamp (r[7], 0, 4)])), 0.25)) / (double) g);
+        c48 = f32 ((r2 - 1.0) * 0.5);
+        if (r2 > 1.0)
+            r2 = 1.0;
+        const auto t = (double) f32 (std::tan (500.0 * pi * f17));
+        c44 = f32 ((t - r2) / (t + r2));
+        pre.assign ((std::size_t) std::max (1, preS), 0.0f);
+    }
+
+    float ap (int i, float v, float c) noexcept
+    {
+        auto& p = P[(std::size_t) i];
+        auto& b = buf[(std::size_t) i];
+        const auto w = b[(std::size_t) p] - c * v;
+        b[(std::size_t) p] = c * w + v;
+        p = p > 0 ? p - 1 : L[(std::size_t) i] - 1;
+        return w;
+    }
+
+    float dl (int i, float v) noexcept
+    {
+        auto& p = P[(std::size_t) i];
+        auto& b = buf[(std::size_t) i];
+        const auto r = b[(std::size_t) p];
+        b[(std::size_t) p] = v;
+        p = p > 0 ? p - 1 : L[(std::size_t) i] - 1;
+        return r;
+    }
+
+    float tap (int i, int off) const noexcept
+    {
+        const auto k = off + P[(std::size_t) i];
+        return buf[(std::size_t) i][(std::size_t) (k >= L[(std::size_t) i] ? k - L[(std::size_t) i] : k)];
+    }
+
+    void process (const float* x, float* outL, float* outR, int n) noexcept
+    {
+        const auto t1 = 1.0f - g;
+        const auto w74 = t1 * 0.6f + g, w6c = t1 * 0.25f + g, w78 = t1 * 0.7f + g, w68 = t1 * 0.2f + g, w70 = t1 * 0.5f + g;
+        for (int i = 0; i < n; ++i)
+        {
+            auto a = ((x[i] + 1.0e-30f) - s10) * cHc + s10;
+            s10 = a;
+            const auto h = (a - s14) * cLc + s18;
+            s18 = a, s14 = h;
+            if (cLc != 0.0f)
+                a = (a - h) * 0.5f + 1.0e-30f;
+            for (int k = 0; k < 4; ++k)
+                a = ap (k, a, cIn);
+            const auto z = pre[(std::size_t) pp];
+            pre[(std::size_t) pp] = a;
+            pp = pp > 0 ? pp - 1 : (int) pre.size() - 1;
+            // half 1
+            auto u = buf[11][(std::size_t) P[11]] * g;
+            auto f = (u - s50) * c44 + s4c;
+            s4c = u, s50 = f;
+            auto v = (((f + u) * c48 + u + z) - s3c) * cDamp + s3c;
+            s3c = v;
+            auto w = ap (4, v, c1);
+            auto r = dl (5, w) * g;
+            auto w2 = ap (6, r, c2);
+            buf[7][(std::size_t) P[7]] = w2;
+            P[7] = P[7] > 0 ? P[7] - 1 : L[7] - 1;
+            // half 2
+            u = buf[7][(std::size_t) P[7]] * g;
+            f = (u - s58) * c44 + s54;
+            s54 = u, s58 = f;
+            v = (((f + u) * c48 + u + z) - s40) * cDamp + s40;
+            s40 = v;
+            w = ap (8, v, c1);
+            r = dl (9, w) * g;
+            w2 = ap (10, r, c2);
+            buf[11][(std::size_t) P[11]] = w2;
+            P[11] = P[11] > 0 ? P[11] - 1 : L[11] - 1;
+            outL[i] = (((tap (9, tl[0]) - w6c * tap (9, tl[1])) - w78 * tap (10, tl[2])) - w68 * tap (11, tl[3]))
+                      + w74 * tap (5, tl[4]) + tap (6, tl[5]) + w70 * tap (7, tl[6]);
+            outR[i] = ((((w6c * tap (5, tr[1]) + tap (5, tr[0])) - w78 * tap (6, tr[2])) - w68 * tap (7, tr[3]))
+                       - w74 * tap (9, tr[4])) + tap (10, tr[5]) + w70 * tap (11, tr[6]);
+        }
+    }
+};
+
+Rack::Rack() = default;
+Rack::~Rack() = default;
+
+void Rack::prepare (const std::array<int, 100>& p, const std::array<int, 7>& t, double fs, double bpm,
+                    std::shared_ptr<const MaximusPreset> preset)
+{
+    chorus.reset();
+    delay.reset();
+    reverb.reset();
+    comp.reset();
+    compPreset.reset();
+    if (p[90] > 0)
+        chorus = std::make_unique<Chorus> (p[90], (float) p[91] * 0.001f, fs);
+    if (p[92] > 0)
+        delay = std::make_unique<Delay> (p[92], p[93], p[94], p[95], fs, bpm);
+    if (p[96] > 0)
+        reverb = std::make_unique<Reverb> (p[96], fs);
+    wet = f32 ((double) g11 ((float) p[97] * 0.001f) * 0.5);
+    if (t[3] > 0 && preset != nullptr && preset->valid)
+    {
+        compPreset = std::move (preset);
+        comp = std::make_unique<Maximus>();
+        comp->prepare (compPreset, fs, p[98]);
+    }
+    on = chorus || delay || reverb || comp;
+    tailLength = (int) rint (fs * 0.004) + (chorus ? maxBlock + chorus->maxDelay : 0);
+    tail = 0;
+    quietNeeded = (long long) (0.25 * fs) + (chorus ? chorus->maxDelay : 0)
+                  + (delay ? (long long) delay->D * 2 + delay->oL + delay->oR : 0)
+                  + (reverb ? (long long) reverb->pre.size() + reverb->L[5] + reverb->L[9] : 0);
+    quietFor = quietNeeded; // a new rack holds no sound
+}
+
+void Rack::process (float* left, float* right, int n, bool voices) noexcept
+{
+    if (! on || n <= 0)
+        return;
+    if (voices)
+        tail = tailLength;
+    else if (tail > 0)
+        tail -= n;
+    if (chorus)
+    {
+        if (tail < 1)
+            chorus->advance (n);
+        else
+        {
+            chorus->process (left, right, scratchL.data(), scratchR.data(), n);
+            if (chorus->dry != 1.0f)
+                for (int i = 0; i < n; ++i)
+                    left[i] = left[i] * chorus->dry, right[i] = right[i] * chorus->dry;
+            for (int i = 0; i < n; ++i)
+                left[i] = left[i] + scratchL[(std::size_t) i], right[i] = right[i] + scratchR[(std::size_t) i];
+        }
+    }
+    if (delay)
+    {
+        if (tail > 0)
+            delay->write (left, right, n);
+        delay->process (scratchL.data(), scratchR.data(), n);
+        for (int i = 0; i < n; ++i)
+            left[i] = left[i] + scratchL[(std::size_t) i], right[i] = right[i] + scratchR[(std::size_t) i];
+    }
+    if (reverb)
+    {
+        for (int i = 0; i < n; ++i)
+            mono[(std::size_t) i] = left[i] + right[i];
+        reverb->process (mono.data(), scratchL.data(), scratchR.data(), n);
+        for (int i = 0; i < n; ++i)
+            left[i] = left[i] + scratchL[(std::size_t) i] * wet, right[i] = right[i] + scratchR[(std::size_t) i] * wet;
+    }
+    if (comp)
+        comp->process (left, right, n);
+    float peak = 0.0f;
+    for (int i = 0; i < n; ++i)
+        peak = std::max (peak, std::max (std::fabs (left[i]), std::fabs (right[i])));
+    if (voices || peak > 1.0e-7f)
+        quietFor = 0;
+    else
+        quietFor += n;
+}
+
+void Rack::advance (int n) noexcept
+{
+    if (! on || n <= 0)
+        return;
+    if (tail > 0)
+        tail -= n;
+    if (chorus)
+        chorus->advance (n);
+    if (delay)
+        delay->advance (n);
+    if (comp)
+        comp->silence (n);
+}
+} // namespace lynx::hlfx

+ 70 - 0
src/core/HarmlessFx.h

@@ -0,0 +1,70 @@
+#pragma once
+
+// FL Studio Harmless's built-in effects rack, rebuilt from docs/analise/REA_rodada36.md (clean-room; a port of our own
+// reference model, which was checked against the installation's Harmless_x64.dll, Reverb_x64.dll and SG_x64.dll).
+//
+// Order on the mix of all voices (Gen_Render): chorus → delay → reverb → compressor. The chorus, delay and reverb
+// are fixed presets selected by the rack's type combos (tables read in Harmless_x64.dll); the compressor is FL's
+// Maximus engine (hosted through Shared/SG_x64.dll) loaded with Harmless's own preset
+// Plugins/Fruity/Generators/Harmless/Data/Compression/<type>.fst, whose processed/original band mix is the rack's
+// "Mix" knob. The preset files are read at run time from the user's FL installation; nothing of them is stored here.
+
+#include <array>
+#include <cstdint>
+#include <memory>
+#include <optional>
+#include <vector>
+
+namespace lynx::hlfx
+{
+// the Maximus state (plugin record 0xD5) inside an FL preset file (.fst); nullopt if there is none
+std::optional<std::vector<std::uint8_t>> maximusStateFromFst (const std::vector<std::uint8_t>& fst);
+
+// Everything of a Maximus state that does not depend on the sample rate (parameters, envelope gain tables,
+// saturation tables). Built off the audio thread; shared read-only by the instruments that use it.
+struct MaximusPreset;
+std::shared_ptr<const MaximusPreset> makeMaximusPreset (const std::vector<std::uint8_t>& state);
+
+class Maximus;
+
+// The whole rack of one Harmless instance (state lives here; the presets are shared)
+class Rack
+{
+public:
+    Rack();
+    ~Rack();
+    Rack (const Rack&) = delete;
+    Rack& operator= (const Rack&) = delete;
+
+    // p: the 100 parameters, t: the 7 combo integers; comp: the compression preset (null: compressor off)
+    void prepare (const std::array<int, 100>& p, const std::array<int, 7>& t, double fs, double bpm,
+                  std::shared_ptr<const MaximusPreset> comp);
+    bool enabled() const noexcept { return on; }
+
+    // in place on the float mix of one host block (n ≤ maxBlock); voices: records existed at the start of the block
+    void process (float* left, float* right, int n, bool voices) noexcept;
+
+    // no voices and the rack has gone quiet: only its free-running counters and phases advance
+    void advance (int n) noexcept;
+
+    // true once the rack's output has stayed below −140 dB for longer than its longest internal delay
+    bool quiet() const noexcept { return ! on || quietFor >= quietNeeded; }
+
+    static constexpr int maxBlock = 512;
+
+private:
+    struct Chorus;
+    struct Delay;
+    struct Reverb;
+    std::unique_ptr<Chorus> chorus;
+    std::unique_ptr<Delay> delay;
+    std::unique_ptr<Reverb> reverb;
+    std::unique_ptr<Maximus> comp;
+    std::shared_ptr<const MaximusPreset> compPreset;
+    float wet = 0.0f;
+    int tail = 0, tailLength = 0;
+    long long quietFor = 0, quietNeeded = 0;
+    bool on = false;
+    std::array<float, maxBlock> scratchL {}, scratchR {}, mono {};
+};
+} // namespace lynx::hlfx

+ 161 - 0
tests/tests.cpp

@@ -25,6 +25,7 @@
 #include "core/WavPack.h"
 #include "core/FlWrapper.h"
 #include "core/Harmless.h"
+#include "core/HarmlessFx.h"
 #include "core/LiveEventQueue.h"
 #include "core/RackRenderer.h"
 #include "core/Scheduler.h"
@@ -739,6 +740,7 @@ TEST (flp_real_files)
     int ogunTrumpet = 0; // Ogun channels whose spectrum matches the REA "Trumpet" reference
     int peqSlots = 0, peqShaped = 0, reverbs = 0, reverbsDryless = 0, reverbsLowCut = 0;
     int dwChannels = 0, dwZones = 0, fpcKits = 0, padChannels = 0, padNotes = 0;
+    int harmlessCompWanted = 0, harmlessCompLoaded = 0; // Harmless rack compressors / presets read from the installation
     // import with the installation's samples (realFlpDir is ...\Data): for DirectWave/FPC
     lynx::FlpImportOptions withFiles;
     const auto flRoot = std::filesystem::path (realFlpDir).parent_path().string();
@@ -786,6 +788,12 @@ TEST (flp_real_files)
                     hasFpc = hasFpc || c.pluginName == "FPC";
                 for (const auto& c : full.channels)
                 {
+                    if (c.instrument == lynx::InstrumentKind::harmless && c.modelParams.size() >= (std::size_t) lynx::harmlessParamCount
+                        && c.modelParams[(std::size_t) lynx::harmlessComboIndex + 3] > 0.5f)
+                    {
+                        ++harmlessCompWanted;
+                        harmlessCompLoaded += c.modelParams.size() > (std::size_t) lynx::harmlessCompIndex + 1000 ? 1 : 0;
+                    }
                     flKeysChannels += c.zones.size() == 30 && c.zones.front().path.find ("CHANGPIANO") != std::string::npos ? 1 : 0;
                     if (c.sampler.slices.size() >= 4)
                     {
@@ -1333,6 +1341,8 @@ TEST (flp_real_files)
     CHECK (harmlessDecoded == harmless && harmless > 100);
     std::printf ("  Harmless: %d states parsed for the engine, %d channels imported as Harmless\n", harmlessParsed, harmlessKind);
     CHECK (harmlessParsed == harmless && harmlessKind >= harmless);
+    std::printf ("  Harmless rack compressor: %d of %d presets read from the installation\n", harmlessCompLoaded, harmlessCompWanted);
+    CHECK (harmlessCompLoaded == harmlessCompWanted && harmlessCompWanted > 100);
 
     // 3x Osc channel presets shipped with FL (.fst): all become synth settings
     int presets = 0, presetsDecoded = 0;
@@ -5490,6 +5500,157 @@ TEST (kepler_lfo_bpm_sync)
     CHECK (lynx::synthFromKepler (state, s, gain) && ! s.lfo[lynx::lfoPitch].sync);
 }
 
+// our own Maximus v7 state (layout REA_rodada8 §1.1): 7 globals, 4 × 13 band parameters, 8 envelopes (dx, y, tension, type)
+static std::vector<std::uint8_t> maximusTestState (const std::array<int, 7>& g, const std::array<std::array<int, 13>, 4>& bands,
+                                                   const std::array<std::vector<std::array<double, 4>>, 8>& envs, int oversampling)
+{
+    std::vector<std::uint8_t> d;
+    auto put = [&] (const void* v, std::size_t n) { d.insert (d.end(), (const std::uint8_t*) v, (const std::uint8_t*) v + n); };
+    auto i32 = [&] (std::int32_t v) { put (&v, 4); };
+    i32 (7);
+    for (int copy = 0; copy < 2; ++copy)
+    {
+        for (auto v : g)
+            i32 (v);
+        for (const auto& b : bands)
+            for (auto v : b)
+                i32 (v);
+    }
+    d.resize (0x1fe, 0);
+    std::memcpy (d.data() + 0x1f4, &oversampling, 4);
+    for (const auto& e : envs)
+    {
+        i32 (3), i32 (2), i32 ((std::int32_t) e.size());
+        for (const auto& pt : e)
+        {
+            const double dx = pt[0], y = pt[1];
+            const float t = (float) pt[2];
+            put (&dx, 8), put (&y, 8), put (&t, 4);
+            const std::uint8_t flags[4] { (std::uint8_t) pt[3], 0, 0, 0 };
+            put (flags, 4);
+        }
+        i32 (0), i32 (-1), i32 (-1), i32 (-1), i32 (-1);
+    }
+    return d;
+}
+
+TEST (harmless_rack)
+{
+    // REA_rodada36: Harmless's effects rack against our reference model (rack.py / maxmodel.py, which match the
+    // installation's Harmless_x64.dll and SG_x64.dll), 44.1 kHz, host blocks of 512
+    std::vector<float> inL (8192), inR (8192);
+    for (int i = 0; i < 4096; ++i)
+    {
+        inL[(std::size_t) i] = (float) (1.5 * std::sin (2.0 * 3.141592653589793 * 440.0 * i / 44100.0) * std::min (1.0, i / 400.0));
+        inR[(std::size_t) i] = (float) (1.2 * std::sin (2.0 * 3.141592653589793 * 660.0 * i / 44100.0));
+    }
+    auto run = [&] (const std::array<int, 100>& p, int compType, std::shared_ptr<const lynx::hlfx::MaximusPreset> comp, int total, int voicesUntil) {
+        lynx::hlfx::Rack rack;
+        std::array<int, 7> t {};
+        t[3] = compType;
+        rack.prepare (p, t, 44100.0, 120.0, std::move (comp));
+        std::vector<float> l (inL.begin(), inL.begin() + total), r (inR.begin(), inR.begin() + total);
+        for (int s = 0; s < total; s += 512)
+            rack.process (l.data() + s, r.data() + s, std::min (512, total - s), s < voicesUntil);
+        return std::make_pair (l, r);
+    };
+    {
+        // chorus type 3 (mix 400), ping-pong delay type 2 (vol 600, feedback 500, 1/4 beat), reverb type 4 (vol 700)
+        std::array<int, 100> p {};
+        p[90] = 3, p[91] = 400, p[92] = 2, p[93] = 600, p[94] = 500, p[95] = 48, p[96] = 4, p[97] = 700;
+        const auto [l, r] = run (p, 0, nullptr, 8192, 4096);
+        const std::tuple<int, float, float> golden[] { { 0, 0.0f, 0.0f }, { 500, -0.25248247f, 0.15141529f }, { 3000, -0.65128994f, -0.64854866f },
+                                                       { 5000, -0.54308629f, -0.36827448f }, { 6000, -0.98378551f, -0.72790027f },
+                                                       { 8191, 0.50599128f, -0.43637198f } };
+        for (const auto& [i, gl, gr] : golden)
+            CHECK (std::abs (l[(std::size_t) i] - gl) < 2e-6f && std::abs (r[(std::size_t) i] - gr) < 2e-6f);
+    }
+    {
+        // the delay alone: an impulse comes back after round(time·fs·0.3125/bpm) samples × (11^0.6 − 1)/10, then × feedback
+        std::array<int, 100> p {};
+        p[92] = 1, p[93] = 600, p[94] = 500, p[95] = 48;
+        lynx::hlfx::Rack rack;
+        rack.prepare (p, {}, 44100.0, 120.0, nullptr);
+        std::vector<float> l (16384), r (16384);
+        l[0] = 1.0f;
+        for (int s = 0; s < 16384; s += 512)
+            rack.process (l.data() + s, r.data() + s, 512, s == 0);
+        const auto D = 5512; // 48·44100·0.3125/120 = 5512.5 → 5512 (round half to even)
+        const auto vol = (float) ((std::exp ((double) (600 * 0.001f) * (double) (float) std::log (11.0)) - 1.0) * (double) 0.1f);
+        CHECK (std::abs (l[(std::size_t) D] - vol) < 1e-7f && std::abs (l[(std::size_t) D - 1]) < 1e-12f);
+        // the feedback ramps from 0.5 toward 0.5: the second echo is vol·0.5
+        CHECK (std::abs (l[(std::size_t) (2 * D)] - vol * 0.5f) < 1e-7f && std::abs (r[(std::size_t) D]) < 1e-12f);
+    }
+    // the compressor: Maximus states of our own (no preset data), checked against SG_x64.dll by REA round 36
+    using Env = std::vector<std::array<double, 4>>;
+    const Env def { { 0.0, 0.0, 0.0, 0 }, { 0.5, 0.5, 0.0, 0 }, { 0.5, 0.5, 0.0, 0 } };
+    auto band = [] (int mode, int pre = 1000, int post = 1000, int sep = 0, int sat = 0, int ceil = 1000, int att = 1115, int rel2 = 0,
+                    int sus = 2882) { return std::array<int, 13> { mode, pre, post, sep, sat, ceil, att, rel2, 2, 5000, 3, sus, 0 }; };
+    {
+        // master brickwall at −0.22 dB only (bands off / compression off)
+        const auto st = maximusTestState ({ 19800, 1, 48065, 1, 1115, 1000, -1 }, { band (3), band (1), band (3), band (0) },
+                                          { def, def, def, def, def, def, def, def }, 0);
+        const auto preset = lynx::hlfx::makeMaximusPreset (st);
+        CHECK (preset != nullptr);
+        std::array<int, 100> p {};
+        p[98] = 1000;
+        const auto [l, r] = run (p, 1, preset, 4096, 4096);
+        const std::tuple<int, float, float> golden[] { { 100, 0.02499794f, 0.88166064f }, { 1000, 0.56971455f, -0.62808162f },
+                                                       { 2047, -0.27541649f, 0.70913559f }, { 3000, 0.32431602f, -0.37985173f },
+                                                       { 4095, -0.12743534f, -0.15237498f } };
+        for (const auto& [i, gl, gr] : golden)
+            CHECK (std::abs (l[(std::size_t) i] - gl) < 2e-6f && std::abs (r[(std::size_t) i] - gr) < 2e-6f);
+        float peak = 0.0f;
+        for (int i = 2048; i < 4096; ++i)
+            peak = std::max ({ peak, std::abs (l[(std::size_t) i]), std::abs (r[(std::size_t) i]) });
+        CHECK (peak < 0.9751f);
+    }
+    {
+        // 24 dB crossovers, ×2 oversampling, low cut, stereo separation, saturation A, a knee with tension (type 7) and
+        // exponential tensions (type 0), release 2 on the master, band mix 600
+        const Env knee { { 0.0, 0.0, 0.0, 0 }, { 0.35, 0.35, 0.0, 0 }, { 0.65, 0.6, 0.36, 7 } };
+        const Env t0 { { 0.0, 0.0, 0.0, 0 }, { 0.5, 0.5, 0.14, 0 }, { 0.5, 0.5, 0.0, 0 } };
+        const Env m0 { { 0.0, 0.0, 0.0, 0 }, { 0.5, 0.5, 0.0, 0 }, { 0.5, 0.6, 0.085, 0 } };
+        const auto st = maximusTestState ({ 19800, 1, 48065, 1, 891, 600, 32768 },
+                                          { band (1, 1264, 1296, 500, -500, 1200), band (0, 1340, 1000, -348, 0, 1000, 1115, 0, 1570),
+                                            band (0, 1364, 1152, 0, 0, 1000, 1115, 0, 1186), band (0, 1000, 1000, 0, -196, 1000, 1115, 4464, 1538) },
+                                          { def, def, knee, def, t0, def, m0, def }, 1);
+        const auto preset = lynx::hlfx::makeMaximusPreset (st);
+        CHECK (preset != nullptr);
+        std::array<int, 100> p {};
+        p[98] = 600;
+        const auto [l, r] = run (p, 2, preset, 4096, 4096);
+        const std::tuple<int, float, float> golden[] { { 100, 0.0f, 0.0f }, { 1000, -0.46856275f, -0.63261062f },
+                                                       { 2047, 0.20268074f, 0.5414567f }, { 3000, -0.25614089f, -0.49984524f },
+                                                       { 4095, 0.10172816f, 0.0505573f } };
+        for (const auto& [i, gl, gr] : golden)
+            CHECK (std::abs (l[(std::size_t) i] - gl) < 2e-6f && std::abs (r[(std::size_t) i] - gr) < 2e-6f);
+    }
+    {
+        // an .fst wrapper around a state is found; unsupported states are rejected
+        const auto st = maximusTestState ({ 19800, 1, 48065, 1, 1115, 1000, -1 }, { band (3), band (1), band (3), band (0) },
+                                          { def, def, def, def, def, def, def, def }, 0);
+        std::vector<std::uint8_t> fst { 'F', 'L', 'h', 'd', 6, 0, 0, 0, 0, 0, 1, 0, 0x60, 0, 'F', 'L', 'd', 't' };
+        std::vector<std::uint8_t> body { 0xC9, 8, 'M', 'a', 'x', 'i', 'm', 'u', 's', 0, 0xD5 };
+        for (auto n = st.size(); ; n >>= 7)
+        {
+            body.push_back ((std::uint8_t) ((n & 0x7f) | (n >= 0x80 ? 0x80 : 0)));
+            if (n < 0x80)
+                break;
+        }
+        body.insert (body.end(), st.begin(), st.end());
+        const auto len = (std::uint32_t) body.size();
+        for (int k = 0; k < 4; ++k)
+            fst.push_back ((std::uint8_t) (len >> (8 * k)));
+        fst.insert (fst.end(), body.begin(), body.end());
+        const auto found = lynx::hlfx::maximusStateFromFst (fst);
+        CHECK (found && *found == st);
+        auto rms = st;
+        rms[4 + 4 * (7 + 13 * 3 + 12)] = 1; // RMS detector on the master: not decoded
+        CHECK (lynx::hlfx::makeMaximusPreset (rms) == nullptr);
+    }
+}
+
 TEST (harmless_engine)
 {
     // REA_rodada32: state parsing, the additive engine against our reference model (hlmodel.py), host levels, voice end