Bläddra i källkod

Merge origin/main (WaveShaper, Soft Clipper) into feature/delay3

Ka1-S 1 månad sedan
förälder
incheckning
192c8ac8e8

+ 1 - 0
CMakeLists.txt

@@ -53,6 +53,7 @@ add_library(lynx_core STATIC
     src/core/Vocodex.cpp
     src/core/MaximusFx.cpp
     src/core/FruityDynamics.cpp
+    src/core/FruityShapers.cpp
     src/core/FruityDelay.cpp
     src/core/FlPatcher.cpp
     src/core/Inflate.cpp

+ 10 - 1
docs/STATUS.md

@@ -66,7 +66,7 @@ exports the 30 demo projects shipped with FL Studio 2026.
   controller links (Peak Controller, Envelope/Keyboard Controller, X-Y/Control Surface as constants).
 - Mixer: routing and levels, sidechain links (level-0 routes), track EQ, colours, names, and native effects with
   their saved settings: Parametric EQ 2, Limiter (incl. its compressor and sidechain), Compressor, Reeverb 2,
-  Delay 2/3, Maximus, Soundgoodizer, Fast Dist, Fruity Filter, Flangus, Soft Clipper, Gross Beat, Effector,
+  Delay 2/3, Maximus, Soundgoodizer, Fast Dist, Fruity Filter, Flangus, Soft Clipper, WaveShaper, Gross Beat, Effector,
   Love Philter, Frequency Splitter, Stereo Shaper, Balance/PanOMatic, Pitch Shifter, Frequency Shifter,
   Emphasis, Low Lifter, Send, Transporter, Squeeze, Pitcher, Fruity Vocoder; Patcher graphs of any shape are
   reduced to series/parallel chains.
@@ -307,6 +307,13 @@ accordingly. Highlights of what is **confirmed and applied**:
   Soundgoodizer runs the older engine copy of its own DLL with the preset `a…d.dat` read from the user's installation
   at import and Amount as the band mix. Within −139 dB of Maximus_x64.dll on 96 of the 100 demo states (53
   bit-identical) and within −126 dB of Soundgoodizer_x64.dll on every preset/amount; latency reported to PDC.
+- **Fruity WaveShaper and Fruity Soft Clipper:** FL's exact engines as mixer effects (`core/FruityShapers`, REA round
+  51). WaveShaper: the curve from FL's saved map (load-time normalisation, all 13 segment modes, FL's incremental
+  evaluator, 16-bit table), pre/mix/post laws, nearest and interpolated x87 kernels (the latter rounding toward zero),
+  polyphase IIR half-band oversampling ×2…×16, per-sample smoothing, CENTER DC removal; exports use FL's rendering
+  behaviour (interpolated table, ×16 when oversampling is on). Soft Clipper: FL's exponential knee in x87 precision
+  and its post law. Controls are editable LYNX parameters. Bit-identical to both DLLs on every installation state
+  (57 WaveShaper states live and rendering, at 44.1 and 48 kHz; 12 Soft Clipper states plus edge cases).
 - **Fruity Delay 2 and Fruity Delay 3:** FL's exact engines as mixer effects (`core/FruityDelay`, REA round 52),
   FL's raw controls as editable parameters. Delay 2: time in 1/192 beat, input pan/volume ramps, stereo offset,
   normal/swapped/ping-pong loop with its one-pole cutoff in x87 precision. Delay 3 (the hosted third-party engine):
@@ -355,6 +362,8 @@ accordingly. Highlights of what is **confirmed and applied**:
   in FL (shared by every instance), LYNX starts one per instance like a fresh FL process, so random phases differ from a
   given FL render by design; FL's max-polyphony event value and its rate-before-state order at channel creation are taken
   from the GMS findings (inference).
+- Fruity WaveShaper (REA round 51 §5): every LYNX export is treated as FL's rendering mode (the process-mode value FL
+  sends when it exports was not observed); the editor-only toggle stored by layout ≥ 2 is not identified.
 - Kepler (REA round 46 §6–§7): single-ulp differences of the DLL library's pow inside the render remain (−125…−135 dB
   on the signal; self-oscillating patches — Resonance 1 — amplify them to audible phase differences of the
   self-oscillation, 10 of 277 presets, no demo); LYNX applies the channel volume as an output gain (how FL applies it

+ 258 - 0
docs/analise/REA_rodada51.md

@@ -0,0 +1,258 @@
+# Behavioural analysis of FL Studio 2026: round 51 (REA) — Fruity WaveShaper and Fruity Soft Clipper
+
+> **Nature of this document.** Continuation of `REA_rodada8.md` §6 (Soft Clipper state and curve, confirmed here at
+> the bit level) and first decoding of the Fruity WaveShaper. *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 (the WaveShaper curve travels inside the
+> user's own project state; the `Data\Maps\*.fnv` files shipped with the plugin are not used).
+>
+> **Rule for this round: no speculation.** Every value comes from decompilation (**[DECOMP]**), from the data
+> (**[DATA]**) or from running the installation's own DLLs, unmodified (**[EXEC]**). Inferences are marked as such;
+> what could not be established is marked "not confirmed".
+
+| Marker | Meaning |
+|---|---|
+| **[DECOMP]** | read in the decompiled/disassembled code |
+| **[DATA]** | checked in `.flp` files, or a value read from a DLL's data section |
+| **[EXEC]** | result obtained by running the installation's own DLL (without modifying it) |
+
+- **Date:** 2026-10-15. Scratch directory (paths below are relative to it): `/home/kauan/.claude/jobs/f8789b49/tmp/r51/`.
+- **Targets:**
+
+  | File | SHA-256 |
+  |---|---|
+  | `Plugins/Fruity/Effects/Fruity Soft Clipper/Fruity Soft Clipper_x64.dll` | `50aac72859d241664e2cd3cbe62c10ca87d63ed184c8582c43136dcc1ce772c6` (= round 8) |
+  | `Plugins/Fruity/Effects/Fruity WaveShaper/Fruity WaveShaper_x64.dll` | `7c5bf09601ce77e4343805447b9ce27199b2efd65fae5e78f686c1bb8529da01` |
+
+- **Tools:** headless Ghidra 12.1.4 (projects outside the scratch tree, `~/ghproj/r51`; scripts `gh/scripts/DecRange.java`),
+  `objdump -M intel` for the x87/SSE operation order.
+- **EXEC harness:** `run/ws.c` → `ws_<n>.exe` (zig cc 0.14.1, x86_64-windows-gnu): round 38/49's effect harness
+  (unmodified DLL, `SetErrorMode`, vectored fault handler, `TerminateProcess`, `timeout`; state restored through the
+  plugin's own SaveRestoreState, Dispatcher sample rate / block size, Eff_Render), extended this round with: plugin
+  VMT dump (`vt=1`), double-indirect function pointers (`fpp=`), raw bytes behind a global pointer (`gx=`), 16-bit
+  array dumps (type `h`, used for the shaping table), and the thread's MXCSR / x87 control word around the render.
+- **Drivers (our own code):** `py/survey51.py` (every Soft Clipper / WaveShaper mixer state in the installation's
+  `.flp` files → `data/states51.pkl`), `py/ws.py` (runs the harness; test signals), `py/scmodel.py` and
+  `py/wsmodel.py` (Python models built only from the facts below), `py/t_ws.py` / `t_ws48.py` (model vs DLL),
+  `py/t_modes.py` (shaping tables of synthetic curves with every segment mode vs DLL), `py/t_cpp.py` (LYNX's C++
+  engines vs DLL), `py/gold.py` (goldens of `tests/tests.cpp`), `cpp/wscmp.cpp` (LYNX's engines on a float file).
+
+Error measure everywhere: `20·log₁₀(‖LYNX − DLL‖ / ‖DLL‖)` over both channels, 44.1 kHz, blocks of 512 unless stated;
+"−∞" = bit-identical.
+
+**Installation usage [DATA]:** Fruity Soft Clipper in 27 mixer slots (21 in *Demo projects*, 17 + 6 files), 12
+distinct states, threshold 100 in 16 of them, 1 in 4; Fruity WaveShaper in 73 slots (62 in *Demo projects*, 19 + 10
+files), 57 distinct states, layout versions 2 (22) and 4 (51). Before this round LYNX imported both as its generic
+distortion: the WaveShaper's state was never read (default drive, a level FL never applies) and the Soft Clipper ran
+as a zero-drive distortion with an output correction.
+
+---
+
+## 1. Fruity Soft Clipper
+
+### 1.1 State and controls **[DECOMP `FUN_006beb00`, `FUN_006bee60`, `FUN_005dfd00` + EXEC]**
+
+- Record `0xD5` = two `i32` copied raw into the plugin (threshold, post); after the copy every parameter is read back
+  and re-sent through ProcessParam, so the derived values below are rebuilt; no clamping, no version field.
+- Controls: threshold 1…127 (default 100), post 0…160 (default 128) **[EXEC: control objects' min/max/default]**.
+- Threshold: `t = float(v) · (1/128)` (float), ceiling 1.0f; range `r = 1 − t` (float), replaced by 2⁻¹⁶ when
+  `r ≤ 0`; `inv = 1/r` (float).
+- Post: `n = float(v) · (1/128)` (float); gain 1 exactly when `n = 1`, otherwise
+  `g = float((exp(double(float(n · 2.39789534f))) − 1) · double(0.1f))` — FL's level law L11 evaluated with a float
+  ln 11 and a float 0.1.
+
+### 1.2 Render **[DECOMP `FUN_006bf330` + EXEC]**
+
+1. Input copied to the output buffer (when they differ); the curve then runs in place over the 2n interleaved samples.
+2. **Curve** (the default kernel, x87): a sample is left unchanged unless its magnitude's bit pattern is greater than
+   the threshold's, compared as signed 32-bit integers (so with a negative threshold every sample is processed).
+   Otherwise, in extended precision, `y = (1 − e^{(t − |x|)·inv})·r + t` (the exponential through `f2xm1`/`fscale`),
+   stored as a float, and the input's sign bit is OR-ed into the result's bits.
+3. A peak meter (editor only) when the editor is open.
+4. When `g ≠ 1`: every sample multiplied by `g` in float.
+
+The kernel is taken from a function table filled at load time: x87 versions by default, SSE versions (an `exp`
+call in double, a float `(t − |x|)·inv`) only when a byte of the DLL's CPU record is non-zero; no instruction in the
+DLL writes that byte and it is 0 at EXEC, so the x87 kernel is the one used **[DECOMP `FUN_005e1f00…22d0` + EXEC]**.
+
+### 1.3 Run-time environment **[EXEC]**
+
+After the plugin is created the thread runs with MXCSR `0x9FE0` (flush-to-zero and denormals-are-zero set) and the x87
+control word `0x037F` (64-bit precision, round to nearest). Whether FL's audio thread has the same settings is not
+confirmed (LYNX renders with FTZ/DAZ, and its x87 kernels set the control word explicitly).
+
+---
+
+## 2. Fruity WaveShaper
+
+### 2.1 State **[DECOMP `FUN_00831040` + DATA]**
+
+| Field | Type | Content |
+|---|---|---|
+| version | i32 | `0x00040003` today; the high word is the layout (2…4; a plain 3 is read as layout 3); > `0x40003` is rejected |
+| pre, mix, post | 3 × i32 | the three wheels, raw (ranges in §2.2) |
+| unipolar | u8 | the curve's polarity button (`PolarBtn`, hint "Unipolar / bipolar mode") |
+| center | u8 | `CenterBtn` ("CENTER", hint "Remove DC offset") |
+| oversampling | i32 | `OverSelect`, 0…4 |
+| map | — | FL's envelope-editor map: `i32 kind (3)`, `i32 version (3)`, `i32 n`, n × (`f64 Δt`, `f64 level`, `f32 tension`, `u8 mode`, 3 bytes), then a 20-byte header (flags, enabled, decay, loop, sustain points) |
+| layout ≥ 2 | i32 | bit 0: an editor-only toggle (the form control at `+0x768`; not referenced by the audio path — which button it is, not confirmed) |
+| layout ≥ 3 | u8 | `HqCheckBox` (hint "Don't truncate below −85dB") |
+| layout ≥ 4 | u8 | `SmoothCheckBox` |
+
+Demo usage: unipolar 5 slots, CENTER 7, oversampling 1/2/4 in 3/5/1, HQ 5, smooth 4.
+
+### 2.2 Controls and gains **[DECOMP `FUN_00831c40` + EXEC]**
+
+Ranges **[EXEC]**: pre 64…192, mix 0…128, post 0…128 (defaults 128 each), oversampling 0…4 (default 0). Any change
+recomputes, in float unless stated, with `k = 1/128`:
+
+- `pre = float(exp(double(float(v_pre)·k) · ln 4) − 1) / 3` (so 1 at 128, 1/3 at 64, 7/3 at 192);
+- `g` = the post law of §1.1 applied to `v_post`;
+- `wet = (float(v_mix)·k) · g`;
+- `dry = ((g − wet) · pre) · g`.
+
+The output is `dry·x + wet·shape(pre·x)` (§2.5): the dry part is taken from the un-amplified input but scaled by the
+pre gain.
+
+### 2.3 Shaping table **[DECOMP `FUN_00832ba0` + EXEC: table dumps]**
+
+- N = 16 383 (bipolar) or 32 767 (unipolar); the table holds N + 3 signed 16-bit entries, indices −1…N+1.
+- Entry i (0…N) = `clamp(round(double(v_i) · S), −32768, 32767)` with S = 32 767 (bipolar) or 65 535 (unipolar),
+  round-half-even, `v_i` = the map evaluator's float output after i steps of `1/N` (double); entry −1 copies entry 0
+  and N+1 copies N.
+- The map's levels are offset by −0.5 in unipolar mode (the curve then spans −0.5…0.5).
+
+### 2.4 The map (FL's shared envelope library) **[DECOMP `FUN_00776550`, `FUN_007797f0`, `FUN_0077a330`, `FUN_0077c550`, `FUN_0077d490`, `FUN_0077bd20` + EXEC]**
+
+- **Load:** Δt and level are kept as floats; a NaN level takes the previous point's. The map's time range is fixed
+  at 1: when the first point starts after 0 a point (0, first level) is inserted; then every Δt is scaled by
+  `1/Σ Δt` (sum in double of the floats; skipped when the factor is exactly 1), as `float(Δt · factor)`; a map whose
+  total time is 0 gets a point at time 1 with the last level. Negative Δt become 0.
+- **Per-point preparation (point i > 0, the segment from i−1 to i):** sign = sign of the tension (0 when none).
+  - modes 0/1 (single / double curve): `k = float(exp(|t|·ln 1 000 001) − 1)·sign`, `1/|k|` and `ln(|k|+1)` as floats;
+  - modes 3–6 (steps / smooth steps / pulse / wave): a count `round(float(exp(float(1 − 0.6|t|)·ln 1 000 001) − 1) · 0.001)`
+    (+1 for mode 3 with t ≥ 0), from which mode 3 takes `count + 1` and `1/(count + 1 − sign)` with an offset ±0.5,
+    mode 4 `count + 1` and its inverse, mode 5 `2(count + 1)` with ±0.5, mode 6 `count + 0.5` (with count 0 and a
+    positive tension it is linear);
+  - modes 7/8: the tension; mode 9: |tension|;
+  - mode 10 (smooth): a monotone cubic Hermite segment whose two end slopes are weighted harmonic means of the
+    neighbouring segments' slopes (only neighbours that are themselves mode 10 count; the weights are float sums
+    `2·r + 1` and `r + 2` of the neighbour/segment duration ratio `r`, floored at 2⁻²⁴); flat segments are linear;
+    the third parameter is `1 − |tension|`;
+  - modes 11/12: from `u = 1 − max(0.9|t|, 2⁻¹⁶)`, `p = 1 − u³`, `(1 − p)/p` and its signed variants (halved for 12);
+  - modes 0, 1, 7, 8, 9, 11, 12 with no tension are linear.
+- **Evaluator:** a stepper with a segment index, a phase and a rate. Start: index 0, the first level, rate 1 and
+  phase 1 when the first Δt is 0 (time scale / Δt and phase 0 otherwise). A step of `dx` adds `dx·rate` to the
+  phase; while the phase is ≥ 1 it moves to the next segment: the leftover phase is turned back into time
+  (`(phase − 1)/rate`), the start level becomes `float(level(i))`, the index advances (it stays on the last point at
+  the end, where the phase and rate become 0), the segment's span is `float(level(i+1) − start)`, and the new rate is
+  `1/Δt` (phase multiplied by it) — or rate 1 and phase + 1 when Δt is 0. The value is
+  `start + shape(phase)·span` in float, `shape` being each mode's formula (double, rounded to float; hold / unknown
+  modes give 0).
+
+EXEC: all 57 demo curves give tables identical to the DLL's; so do 168 synthetic curves (every mode 0…13, six
+tensions including ±1, bipolar and unipolar, totals ≠ 1).
+
+### 2.5 Kernels **[DECOMP `FUN_00629d80`, `…9e00`, `…9f50`, `…9fd0` (x87) + EXEC]**
+
+All four compute `dry·x + T(pre·x)·wet·2⁻¹⁵` in x87 extended precision and store a float.
+
+| Kernel | Used when | Table read |
+|---|---|---|
+| bipolar, nearest | HQ off and not rendering | index `round(x·pre·N)` (current rounding = nearest-even), odd-symmetric (`−T[min(−i, N)]` for i < 0) |
+| bipolar, interpolated | HQ on, or rendering | `i = trunc(x·pre·N)`, `T[i] + (T[i+1] − T[i])·frac` with the same odd symmetry |
+| unipolar, nearest | as above | index `round(x·pre·N/2 + N/2)` clamped to 0…N |
+| unipolar, interpolated | as above | `i = trunc(x·pre·N/2 + N/2)` clamped to −1…N, linear |
+
+The interpolating kernels load the control word `0x0F3F` for their duration: **every rounding inside them —
+products, sums and the final float store — is toward zero**; the others keep the host's (round to nearest). An index
+outside the 32-bit range (x87 "integer indefinite") gives the end entry, negated, in the nearest bipolar kernel and
+0 in the interpolated one.
+
+### 2.6 Oversampling **[DECOMP `FUN_00832300`, `FUN_008300a0`, `FUN_00830140`, `FUN_0082fb70`, `FUN_0082fd40`, `FUN_00627920` + EXEC]**
+
+- Order k from the state (factor 2^k); **when FL renders (§2.9) the order becomes 4 (×16), but only if the state's
+  order is not 0** (with 0 the render path is not oversampled at all).
+- Each order is a 2× stage, separate for up- and down-sampling, built from a polyphase IIR half-band: two chains of
+  three first-order all-passes `y = x[n−1] + (x − y[n−1])·a` in double, coefficients
+  {0.14737711360104660, 0.48246854276970014, 0.88300502576937310} and
+  {0.03915159773446005, 0.30264684832849340, 0.67461591854696390} **[DATA]**.
+  Up: each input sample feeds both chains; the second chain's output is the even output sample, the first chain's
+  the odd one (floats). Down: even samples feed the first chain, odd samples the second; the output is
+  `float((second + first)·0.5)`.
+- After each stage call (each host block) the six all-pass outputs (per channel) with magnitude < 2⁻²⁴ are zeroed;
+  the input-delay states are not. Stage states are cleared when the order changes or the plugin is flushed.
+
+### 2.7 Smooth **[DECOMP `FUN_00832390`, Dispatcher `FUN_00830bf0` id 4]**
+
+With the smooth option, the three gains glide per (oversampled) frame: `s += (target − s)·c` in float, pre / wet /
+dry in that order, starting at 0 when the plugin is created; `c = float(1 − 0.1^{1/(double(float(fs)·0.005f))})`
+(Delphi `Power` = `exp(y·ln x)`), with fs the host rate. Each frame then runs the kernel on its two samples.
+
+### 2.8 CENTER (DC removal) **[DECOMP `FUN_00627af0`, `FUN_006278c0`, `FUN_00836010` + EXEC at 44.1 and 48 kHz]**
+
+After down-sampling, at the host rate, per channel: `v += (x − p)·a; p += v; v ·= b; y = x − p` in x87 extended
+precision with the two states kept in registers for the whole block, then stored as doubles (zeroed when
+|value| ≤ 2⁻²⁴); `a = float(2.2835·10⁻⁵ · 44100/fs)`, `b = 0.96f`.
+
+### 2.9 Process modes **[DECOMP Dispatcher id 1]**
+
+FL's process-mode notification sets a "rendering" flag from **bit 1 of its value** (`PM_HQ_NonRealtime` in FL's SDK
+naming — the name is an inference from the SDK; which value FL sends during an export was not observed). With the
+flag: interpolated kernels and the ×16 order of §2.6. EXEC uses the value 2.
+
+### 2.10 Render order **[DECOMP `FUN_00832390`]**
+
+Peak meter (editor only) → up-sampling (order > 0) → kernel (whole block, or per frame with smooth) →
+down-sampling → CENTER. Environment as in §1.3 (MXCSR FTZ+DAZ: denormal results of the SSE stages are flushed).
+
+---
+
+## 3. What LYNX does
+
+- **`EffectKind::fruitySoftClipper`** and **`EffectKind::fruityWaveShaper`** (`core/FruityShapers.{h,cpp}`): mixer
+  effects whose parameters are FL's controls over their ranges (Soft Clipper: threshold, post; WaveShaper: pre, mix,
+  post, oversampling, HQ, smooth, CENTER, unipolar), so the LYNX editor and automation can change them; the
+  WaveShaper keeps FL's saved state in `EffectSlot::state` for its curve (the controls in the state are copied into
+  the parameters at import). Both tables (bipolar and unipolar) are built when the effect is created.
+- Exports (`offlineRendering()`) take FL's rendering behaviour (§2.9); live playback uses the state's options.
+- The x87 kernels run in `long double` with the control word set explicitly (nearest, or toward zero for the
+  interpolating kernels); host blocks longer than 512 frames are split into 512-frame engine calls.
+- FL automation of the WaveShaper's pre/mix/post and the Soft Clipper's threshold/post maps onto the same parameters.
+- **Fallbacks:** a state that cannot be read keeps the previous distortion approximation, and the import report
+  lists it.
+
+---
+
+## 4. Verification **[EXEC]**
+
+| Check | Cases | Result |
+|---|---|---|
+| Soft Clipper model (`scmodel.py`) and LYNX (`t_cpp.py sc`) vs DLL, music / loud / noise bursts | 12 demo states + 6 edge states (threshold 0, −20, 300, …) × 3 signals | all bit-identical |
+| WaveShaper tables, model vs DLL | 57 demo curves; 168 synthetic curves (modes 0…13) | all identical |
+| WaveShaper model (`t_ws.py`) vs DLL, live and rendering | 57 states × 2 | all bit-identical |
+| LYNX (`t_cpp.py ws`) vs DLL, 3 s music, 44.1 kHz / 512 | 57 states × live / rendering | all 114 bit-identical |
+| LYNX vs DLL, 48 kHz / blocks of 300 | 57 states × 2 | all 114 bit-identical |
+| Unit test `fruity_waveshaper_and_soft_clipper` | 3 Soft Clipper goldens, 3 WaveShaper states of our own × live/render, tables, import, fallback | goldens within 2·10⁻⁷ (bit-identical on the test machine) |
+
+Import (`tests.cpp`, demo-project battery): all 73 WaveShaper and 27 Soft Clipper mixer slots of the installation's
+projects become the exact effects (plus WaveShaper nodes inside Patcher graphs).
+
+**Cost** (one core, 44.1 kHz, 20 s of stereo noise, `cpp/wscmp`, file I/O included): a demo state without oversampling
+< 0.5 % of real time; ×4 oversampling 1 %; the ×16 rendering path 3.7 %.
+
+Without FTZ/DAZ the oversampled states differ from the DLL only in samples below the float normal range
+(≈ −790 dB); LYNX's renderer runs with FTZ/DAZ, as the plugin does.
+
+---
+
+## 5. Open items
+
+- Which process-mode value FL sends when it exports (and whether "HQ for all plugins" matters) was not observed; LYNX
+  treats every export as FL's rendering mode (§2.9).
+- The MXCSR / x87 control word of FL's own audio thread is not confirmed (§1.3); the results above hold for the
+  plugin's own settings.
+- Library-function differences (`exp`, `log`, `sin` of another C library, e.g. on Windows builds) could change single
+  table entries or output ulps; not observed on the test machine.
+- The editor-only state toggle of layout ≥ 2 (§2.1) is not identified.

+ 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/Vocodex.cpp src/core/MaximusFx.cpp src/core/FruityDelay.cpp src/core/FruityDynamics.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/SytrusEngine.cpp src/core/Harmless.cpp src/core/HarmlessFx.cpp src/core/Harmor.cpp src/core/Gms.cpp src/core/Morphine.cpp src/core/Ogun.cpp src/core/Toxic.cpp src/core/ToxicFx.cpp src/core/FruitKick.cpp src/core/BassDrum.cpp src/core/MiniSynth.cpp src/core/Dx10.cpp src/core/Kepler.cpp src/core/PoiZone.cpp src/core/FlPatcher.cpp src/core/Inflate.cpp src/core/WavPack.cpp src/core/Scheduler.cpp src/core/Instruments.cpp src/core/RackRenderer.cpp src/core/FlpImport.cpp src/core/Effects.cpp"
+CORE="src/flp/Flp.cpp src/core/Song.cpp src/core/NoteEdit.cpp src/core/Recorder.cpp src/core/Pdc.cpp src/core/WorkerPool.cpp src/core/TimeStretch.cpp src/core/Arpeggiator.cpp src/core/SynthPresets.cpp src/core/Slicer.cpp src/core/Templates.cpp src/core/FlWrapper.cpp src/core/FlEffects.cpp src/core/Effector.cpp src/core/VintagePhaser.cpp src/core/Vocodex.cpp src/core/MaximusFx.cpp src/core/FruityDelay.cpp src/core/FruityShapers.cpp src/core/FruityDynamics.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/SytrusEngine.cpp src/core/Harmless.cpp src/core/HarmlessFx.cpp src/core/Harmor.cpp src/core/Gms.cpp src/core/Morphine.cpp src/core/Ogun.cpp src/core/Toxic.cpp src/core/ToxicFx.cpp src/core/FruitKick.cpp src/core/BassDrum.cpp src/core/MiniSynth.cpp src/core/Dx10.cpp src/core/Kepler.cpp src/core/PoiZone.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
 # workflow shell (key map, workspace layout, rack operations)

+ 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/ui/Theme.cpp src/ui/Icons.cpp src/ui/I18n.cpp src/ui/EditorTools.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/Vocodex.cpp src/core/MaximusFx.cpp src/core/FruityDelay.cpp src/core/FruityDynamics.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/SytrusEngine.cpp src/core/Harmless.cpp src/core/HarmlessFx.cpp src/core/Harmor.cpp src/core/Gms.cpp src/core/Morphine.cpp src/core/Ogun.cpp src/core/Toxic.cpp src/core/ToxicFx.cpp src/core/FruitKick.cpp src/core/BassDrum.cpp src/core/MiniSynth.cpp src/core/Dx10.cpp src/core/Kepler.cpp src/core/PoiZone.cpp src/core/FlPatcher.cpp src/core/Inflate.cpp src/core/WavPack.cpp src/flp/Flp.cpp
+             src/core/FlpImport.cpp src/core/Effects.cpp src/core/NoteEdit.cpp src/core/Recorder.cpp src/core/Pdc.cpp src/core/WorkerPool.cpp src/core/TimeStretch.cpp src/core/Arpeggiator.cpp src/core/SynthPresets.cpp src/core/Slicer.cpp src/core/Templates.cpp src/core/FlWrapper.cpp src/core/FlEffects.cpp src/core/Effector.cpp src/core/VintagePhaser.cpp src/core/Vocodex.cpp src/core/MaximusFx.cpp src/core/FruityDelay.cpp src/core/FruityShapers.cpp src/core/FruityDynamics.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/SytrusEngine.cpp src/core/Harmless.cpp src/core/HarmlessFx.cpp src/core/Harmor.cpp src/core/Gms.cpp src/core/Morphine.cpp src/core/Ogun.cpp src/core/Toxic.cpp src/core/ToxicFx.cpp src/core/FruitKick.cpp src/core/BassDrum.cpp src/core/MiniSynth.cpp src/core/Dx10.cpp src/core/Kepler.cpp src/core/PoiZone.cpp src/core/FlPatcher.cpp src/core/Inflate.cpp src/core/WavPack.cpp src/flp/Flp.cpp
              src/platform/MingwFixes.cpp)
 
 # workflow shell: core (key map, workspace layout, rack operations) and UI (workspace desktop, control contract)

+ 17 - 0
src/core/Effects.cpp

@@ -6,6 +6,7 @@
 #include "core/Vocodex.h"
 #include "core/MaximusFx.h"
 #include "core/FruityDynamics.h"
+#include "core/FruityShapers.h"
 #include "core/FruityDelay.h"
 
 #include "core/Biquad.h"
@@ -2150,6 +2151,11 @@ const EffectInfo& effectInfo (EffectKind kind)
         info.params.push_back ({ fldyn::compressorParamName (fldyn::compressorControls), 1.0f });
         return info;
     }();
+    // FL's controls over their ranges (core/FruityShapers.h); defaults = a new FL instance; the curve is in EffectSlot::state
+    static const EffectInfo waveShaperInfo { "Fruity WaveShaper", { { "Pre amp", 0.5f }, { "Mix", 1.0f }, { "Post gain", 1.0f },
+                                                                    { "Oversampling", 0.0f }, { "HQ", 0.0f }, { "Smooth", 0.0f },
+                                                                    { "Center", 0.0f }, { "Unipolar", 0.0f } } };
+    static const EffectInfo softClipperInfo { "Fruity Soft Clipper", { { "Threshold", 99.0f / 126.0f }, { "Post", 128.0f / 160.0f } } };
     // FL's raw controls normalised over their ranges (core/FruityDelay.h); defaults = FL's "Default" presets
     static const EffectInfo fruityDelay2Info = [] {
         EffectInfo info { "Fruity Delay 2", {} };
@@ -2262,6 +2268,8 @@ const EffectInfo& effectInfo (EffectKind kind)
         case EffectKind::maximus: return maximusInfo;
         case EffectKind::fruityLimiter: return fruityLimiterInfo;
         case EffectKind::fruityCompressor: return fruityCompressorInfo;
+        case EffectKind::fruityWaveShaper: return waveShaperInfo;
+        case EffectKind::fruitySoftClipper: return softClipperInfo;
         case EffectKind::fruityDelay2: return fruityDelay2Info;
         case EffectKind::fruityDelay3: return fruityDelay3Info;
     }
@@ -2535,6 +2543,11 @@ std::string formatEffectParam (EffectKind kind, int param, float v, double bpm)
 
         case EffectKind::fruityCompressor:
             return fldyn::compressorParamText (param, v);
+        case EffectKind::fruityWaveShaper:
+            return flshape::waveShaperParamText (param, v);
+
+        case EffectKind::fruitySoftClipper:
+            return flshape::softClipperParamText (param, v);
 
         case EffectKind::fruityDelay2:
             return fldelay::delay2ParamText (param, v);
@@ -2577,6 +2590,8 @@ std::unique_ptr<Effect> makeEffect (const EffectSlot& slot)
         return vocodex::make (slot.state);
     if (slot.kind == EffectKind::maximus)
         return maximusfx::make (slot.state);
+    if (slot.kind == EffectKind::fruityWaveShaper)
+        return flshape::makeWaveShaper (slot.state);
     return makeEffect (slot.kind);
 }
 
@@ -2611,6 +2626,8 @@ std::unique_ptr<Effect> makeEffect (EffectKind kind)
         case EffectKind::maximus: return maximusfx::make ({}); // without a state: passes the signal; use makeEffect (slot)
         case EffectKind::fruityLimiter: return fldyn::makeLimiter();
         case EffectKind::fruityCompressor: return fldyn::makeCompressor();
+        case EffectKind::fruityWaveShaper: return flshape::makeWaveShaper ({}); // FL's default curve; use makeEffect (slot)
+        case EffectKind::fruitySoftClipper: return flshape::makeSoftClipper();
         case EffectKind::fruityDelay2: return fldelay::makeDelay2();
         case EffectKind::fruityDelay3: return fldelay::makeDelay3();
         case EffectKind::pitchCorrect: return std::make_unique<PitchCorrect>();

+ 31 - 1
src/core/FlEffects.cpp

@@ -3,6 +3,7 @@
 #include "core/Vocodex.h"
 #include "core/MaximusFx.h"
 #include "core/FruityDynamics.h"
+#include "core/FruityShapers.h"
 #include "core/FruityDelay.h"
 #include "core/SytrusEngine.h"
 #include "core/FlSynths.h"
@@ -949,6 +950,28 @@ std::optional<EffectSlot> fruityDynamicsExact (const std::string& pluginName, co
     return std::nullopt;
 }
 
+std::optional<EffectSlot> fruityShaperExact (const std::string& pluginName, const std::vector<std::uint8_t>& state)
+{
+    // FL's own Fruity WaveShaper / Fruity Soft Clipper engines from the saved state (REA_rodada51); the distortion
+    // approximations of REA_rodada8 remain for states that cannot be read
+    if (pluginName == "Fruity WaveShaper")
+        if (const auto s = flshape::parseWaveShaper (state))
+        {
+            auto slot = makeEffectSlot (EffectKind::fruityWaveShaper);
+            flshape::waveShaperToParams (*s, slot.params.data());
+            slot.state = state; // the curve
+            return slot;
+        }
+    if (pluginName == "Fruity Soft Clipper")
+        if (const auto s = flshape::parseSoftClipper (state))
+        {
+            auto slot = makeEffectSlot (EffectKind::fruitySoftClipper);
+            flshape::softClipperToParams (*s, slot.params.data());
+            return slot;
+        }
+    return std::nullopt;
+}
+
 std::optional<EffectSlot> fruityDelayExact (const std::string& pluginName, const std::vector<std::uint8_t>& state)
 {
     // FL's own Fruity Delay 2 / Delay 3 engines from the saved controls (REA_rodada52); the approximations of
@@ -978,6 +1001,8 @@ std::optional<EffectSlot> effectFromFl (const std::string& pluginName, const std
         return exact;
     if (auto exact = fruityDynamicsExact (pluginName, state))
         return exact;
+    if (auto exact = fruityShaperExact (pluginName, state))
+        return exact;
     if (pluginName == "Maximus") // FL's own engine from the saved state (REA_rodada36/38); the approximation otherwise
         if (auto exact = maximusExact (state))
             return exact;
@@ -1138,6 +1163,8 @@ std::vector<std::string> flPluginsForEffect (EffectKind kind)
         case EffectKind::parametricEq: return { "Fruity Parametric EQ 2" };
         case EffectKind::fruityLimiter: return { "Fruity Limiter" };
         case EffectKind::fruityCompressor: return { "Fruity Compressor" };
+        case EffectKind::fruityWaveShaper: return { "Fruity WaveShaper" };
+        case EffectKind::fruitySoftClipper: return { "Fruity Soft Clipper" };
         case EffectKind::limiter:
         case EffectKind::compressor: return { "Fruity Limiter", "Fruity Compressor" };
         case EffectKind::reverb: return { "Fruity Reeverb 2" };
@@ -1157,7 +1184,10 @@ std::optional<FlParamMap> effectParamFromFl (const std::string& pluginName, int
         return FlParamMap { k, [] (float v) { return std::clamp (v, 0.0f, 1.0f); } };
     if (is ("Fruity Compressor") && k >= 0 && k < fldyn::compressorControls)
         return FlParamMap { k, [] (float v) { return std::clamp (v, 0.0f, 1.0f); } };
-    // the exact Fruity Delay 2 / 3 likewise
+    // the exact WaveShaper (pre, mix, post) and Soft Clipper (threshold, post) take FL's controls over their ranges
+    if ((is ("Fruity WaveShaper") && k >= 0 && k < 3) || (is ("Fruity Soft Clipper") && k >= 0 && k < 2))
+        return FlParamMap { k, [] (float v) { return std::clamp (v, 0.0f, 1.0f); } };
+    // the exact Fruity Delay 2 / 3 likewise (every control)
     if (is ("Fruity Delay 2") && k >= 0 && k < fldelay::delay2Controls)
         return FlParamMap { k, [] (float v) { return std::clamp (v, 0.0f, 1.0f); } };
     if (is ("Fruity Delay 3") && k >= 0 && k < fldelay::delay3Controls)

+ 3 - 0
src/core/FlpImport.cpp

@@ -1406,6 +1406,9 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
                  || (plugin == "Fruity Delay 2" && fx.kind != EffectKind::fruityDelay2)
                  || (plugin == "Fruity Delay 3" && fx.kind != EffectKind::fruityDelay3))
             ++options.report->droppedEffects[plugin + " (state not readable: approximated)"];
+        else if ((plugin == "Fruity WaveShaper" && fx.kind != EffectKind::fruityWaveShaper)
+                 || (plugin == "Fruity Soft Clipper" && fx.kind != EffectKind::fruitySoftClipper))
+            ++options.report->droppedEffects[plugin + " (state not readable: approximated)"];
     };
 
     for (const auto& insert : project.mixer)

+ 1014 - 0
src/core/FruityShapers.cpp

@@ -0,0 +1,1014 @@
+#include "core/FruityShapers.h"
+
+// Fruity WaveShaper and Fruity Soft Clipper, exact engines (docs/analise/REA_rodada51.md). Clean-room: written from
+// the behaviour, formulas and data layouts described there; nothing of Image-Line's code or data is copied.
+//
+// Arithmetic follows the plugins operation by operation: float/double steps in their order with one rounding each
+// (no contraction), and the x87 kernels in 80-bit long double under the control word the plugins use (round to
+// nearest, or toward zero in the interpolating WaveShaper kernels).
+
+#include <algorithm>
+#include <array>
+#include <cmath>
+#include <cstdio>
+#include <cstring>
+
+#include "core/Instruments.h"
+
+#if defined(__clang__)
+#pragma clang fp contract(off)
+#pragma STDC FENV_ACCESS ON
+#elif defined(__GNUC__)
+#pragma GCC optimize("fp-contract=off", "rounding-math")
+#endif
+
+namespace lynx::flshape
+{
+namespace
+{
+using ld = long double;
+
+// ------------------------------------------------------------------------------------------- x87 control word (§1.3)
+#if (defined(__x86_64__) || defined(__i386__)) && (defined(__GNUC__) || defined(__clang__))
+struct X87Mode
+{
+    unsigned short saved = 0;
+    explicit X87Mode (bool truncate) noexcept
+    {
+        asm volatile ("fnstcw %0" : "=m"(saved) : : "memory");
+        unsigned short cw = (unsigned short) ((saved & ~0x0F00u) | 0x0300u | (truncate ? 0x0C00u : 0u));
+        asm volatile ("fldcw %0" : : "m"(cw) : "memory");
+    }
+    ~X87Mode() { asm volatile ("fldcw %0" : : "m"(saved) : "memory"); }
+    X87Mode (const X87Mode&) = delete;
+    X87Mode& operator= (const X87Mode&) = delete;
+};
+#else
+struct X87Mode
+{
+    explicit X87Mode (bool) noexcept {}
+};
+#endif
+
+// long double → integer in the current x87 rounding mode (what the plugins' fist/fistp do), without the control-word
+// round trip a C++ conversion makes; |v| < 2^63
+#if (defined(__x86_64__) || defined(__i386__)) && (defined(__GNUC__) || defined(__clang__))
+inline long long x87Int (long double v) noexcept
+{
+    long long r;
+    asm ("fistpll %0" : "=m"(r) : "t"(v) : "st");
+    return r;
+}
+#else
+inline long long x87Int (long double v) noexcept { return (long long) std::nearbyint (v); }
+#endif
+
+inline float F (double v) noexcept { return (float) v; }
+inline std::int32_t i32At (const std::vector<std::uint8_t>& d, std::size_t o) noexcept
+{
+    std::int32_t v = 0;
+    std::memcpy (&v, d.data() + o, 4);
+    return v;
+}
+inline double f64At (const std::vector<std::uint8_t>& d, std::size_t o) noexcept
+{
+    double v = 0;
+    std::memcpy (&v, d.data() + o, 8);
+    return v;
+}
+inline float f32At (const std::vector<std::uint8_t>& d, std::size_t o) noexcept
+{
+    float v = 0;
+    std::memcpy (&v, d.data() + o, 4);
+    return v;
+}
+int rawFrom (float v, int lo, int hi) noexcept
+{
+    return lo + (int) std::lround (std::clamp ((double) v, 0.0, 1.0) * (hi - lo));
+}
+float norm (int raw, int lo, int hi) noexcept { return (float) std::clamp ((double) (raw - lo) / (hi - lo), 0.0, 1.0); }
+
+// FL's level law L11: (11^x − 1)/10 with 1 kept exact (both plugins' post gains, §1.1 / §2.1)
+float postGain (int raw) noexcept
+{
+    const float n = (float) raw * 0.0078125f;
+    if (n == 1.0f)
+        return 1.0f;
+    return F ((std::exp ((double) (n * 2.39789534f)) - 1.0) * (double) 0.1f);
+}
+
+// ----------------------------------------------------------------------------------------------- map evaluator (§2.4)
+constexpr double kEps = 5.960464477539063e-08; // float 2^-24 (as a double)
+
+struct Pt
+{
+    float dt = 0, y = 0, t = 0;
+    int mode = 0, sign = 0;
+    float k = 0, ilk = 0, L = 0; // modes 0/1: curvature; other modes reuse p4…p6
+    float p4 = 0, p5 = 0, p6 = 0;
+};
+
+int stepCount (const Pt& p) noexcept
+{
+    if (p.mode < 3 || p.mode > 6)
+        return -1;
+    const auto a = F (1.0 - std::abs ((double) p.t) * 0.6);
+    auto n = (int) std::nearbyint ((double) F (std::exp ((double) a * std::log (1000001.0)) - 1.0) * 0.001);
+    if (p.mode == 3 && p.t >= 0.0f)
+        ++n;
+    return n;
+}
+
+void prepareSmooth (std::vector<Pt>& pts, int i) noexcept
+{
+    auto& p = pts[(std::size_t) i];
+    const int n = (int) pts.size();
+    const double h = (double) p.dt > kEps ? (double) p.dt : kEps;
+    const double y1 = p.y;
+    const int j = i - 1;
+    const double y0 = j >= 0 ? (double) pts[(std::size_t) j].y : y1;
+    double rp = 1.0, ypp = y0;
+    if (j >= 0 && pts[(std::size_t) j].mode == 10)
+    {
+        rp = (double) pts[(std::size_t) j].dt / h;
+        if (i - 2 >= 0)
+            ypp = pts[(std::size_t) (i - 2)].y;
+    }
+    double rn = 1.0, yn = y1;
+    if (i + 1 < n && pts[(std::size_t) (i + 1)].mode == 10)
+    {
+        rn = (double) pts[(std::size_t) (i + 1)].dt / h;
+        yn = pts[(std::size_t) (i + 1)].y;
+    }
+    const double d = y1 - y0;
+    if (std::abs (d) < kEps)
+    {
+        p.sign = 2;
+        return;
+    }
+    const double a = (ypp - y0) / d, b = (yn - y0) / d;
+    rp = rp > kEps ? rp : kEps;
+    rn = rn > kEps ? rn : kEps;
+    const double sr = (b - 1.0) / rn, s = 1.0 / 1.0, sl = -a / rp;
+    if (! (F (sr) * F (s) > 0.0f))
+        p.p4 = 0.0f;
+    else
+    {
+        const float w1 = F (rn) * 2.0f + F (1.0), w2 = F (rn) + F (1.0) * 2.0f;
+        p.p4 = (F (sr) * F (s) * (w1 + w2)) / (w1 * F (sr) + w2 * F (s));
+    }
+    if (! (F (s) * F (sl) > 0.0f))
+        p.p5 = 0.0f;
+    else
+    {
+        const float w1 = F (1.0) * 2.0f + F (rp), w2 = F (1.0) + F (rp) * 2.0f;
+        p.p5 = (F (s) * F (sl) * (w1 + w2)) / (w1 * F (s) + w2 * F (sl));
+    }
+    p.p6 = F (1.0 - std::abs ((double) p.t));
+}
+
+std::vector<Pt> preparePoints (const std::vector<WsPoint>& in)
+{
+    std::vector<Pt> pts;
+    for (const auto& q : in)
+    {
+        Pt p;
+        p.dt = q.dt;
+        p.y = q.y;
+        p.t = q.tension;
+        p.mode = q.mode;
+        pts.push_back (p);
+    }
+    for (int i = 0; i < (int) pts.size(); ++i)
+    {
+        auto& p = pts[(std::size_t) i];
+        if (p.dt < 0.0f)
+            p.dt = 0.0f;
+        const float t = p.t;
+        p.sign = t == 0.0f ? 0 : (t > 0.0f ? 1 : -1);
+        if (i == 0)
+            continue;
+        const int m = p.mode;
+        if (m == 0 || m == 1)
+        {
+            const auto e1 = F (std::exp ((double) std::abs (t) * std::log (1000001.0)) - 1.0);
+            const float sg = t > 0.0f ? 1.0f : (t < 0.0f ? -1.0f : 0.0f);
+            p.k = e1 * sg;
+            if (p.k != 0.0f)
+            {
+                p.ilk = F (1.0 / std::abs ((double) p.k));
+                p.L = F (std::log (std::abs ((double) p.k) + 1.0));
+            }
+        }
+        else if (m == 3)
+        {
+            const int sg = t < 0.0f ? -1 : 1;
+            const int c = stepCount (p);
+            p.p6 = (float) sg * 0.5f;
+            p.p4 = (float) (c + 1);
+            p.p5 = 1.0f / (p.p4 - (float) sg);
+        }
+        else if (m == 4)
+        {
+            p.p4 = (float) (stepCount (p) + 1);
+            p.p5 = 1.0f / p.p4;
+        }
+        else if (m == 5)
+        {
+            const int sg = t < 0.0f ? -1 : 1;
+            p.p6 = (float) sg * 0.5f;
+            p.p4 = (float) ((stepCount (p) + 1) * 2);
+            p.p5 = 6.2831855f;
+        }
+        else if (m == 6)
+        {
+            const int c = stepCount (p);
+            p.p4 = F ((double) c + 0.5);
+            p.p5 = 6.2831855f;
+            if (c == 0 && p.sign > 0)
+                p.sign = 2;
+        }
+        else if (m == 7 || m == 8)
+            p.p4 = t;
+        else if (m == 9)
+            p.p4 = F (std::abs ((double) t));
+        else if (m == 10)
+            prepareSmooth (pts, i);
+        else if (m == 11 || m == 12)
+        {
+            auto d = std::abs ((double) t) * 0.9;
+            if (d <= 1.52587890625e-05)
+                d = 1.52587890625e-05;
+            const auto u = 1.0 - d;
+            p.p4 = F (1.0 - u * u * u);
+            p.p5 = (1.0f - p.p4) / p.p4;
+            p.p6 = p.p5;
+            if (p.sign > 0)
+            {
+                p.p5 = -p.p5;
+                p.p6 = p.p5 - 1.0f;
+            }
+            if (m == 12)
+            {
+                p.p5 = F ((double) p.p5 * 0.5);
+                p.p6 = F ((double) p.p6 * 0.5);
+            }
+        }
+        // linear when flat: modes 0, 1, 7, 8, 9, 11, 12 with no tension
+        if (m < 16 && ((0x1b83u >> m) & 1u) != 0 && t == 0.0f)
+            p.sign = 2;
+    }
+    return pts;
+}
+
+double curveK (const Pt& p, double x) noexcept
+{
+    if (p.k == 0.0f)
+        return x;
+    if (p.k > 0.0f)
+        return 1.0 - (std::exp ((1.0 - x) * (double) p.L) - 1.0) * (double) p.ilk;
+    return (std::exp (x * (double) p.L) - 1.0) * (double) p.ilk;
+}
+
+// the shape of the segment ending at p, at phase ph (0…1)
+float shape (const Pt& p, double ph) noexcept
+{
+    if (p.sign == 2)
+        return F (ph);
+    const double p4 = p.p4, p5 = p.p5, p6 = p.p6;
+    switch (p.mode)
+    {
+        case 0: return F (curveK (p, ph));
+        case 1:
+            if (ph < 0.5)
+                return F (curveK (p, ph * 2.0) * 0.5);
+            return F (1.0 - curveK (p, (1.0 - ph) * 2.0) * 0.5);
+        case 3: return (float) (int) std::nearbyint (ph * p4 - p6) * p.p5;
+        case 4:
+        {
+            const auto v = ph * p4 - 0.5;
+            const auto i2 = std::nearbyint (v - 0.5);
+            auto d = (v - i2) * 2.0 - 1.0;
+            if (p.sign < 0)
+            {
+                const auto z = 1.0 - std::abs (d);
+                d = (1.0 - z * z * z) * (std::signbit (d) ? -1.0 : 1.0);
+            }
+            else
+                d = d * d * d;
+            return F ((i2 + d * 0.5 + 1.0) * p5);
+        }
+        case 5: return (float) (((long long) std::nearbyint (ph * p4 - p6)) & 1);
+        case 6:
+        {
+            if (p.sign < 0)
+                return F ((std::sin ((ph * p4 + 0.75) * p5) + 1.0) * 0.5);
+            const auto v = ph * p4 - 0.5;
+            const auto i2 = std::nearbyint (v - 0.5);
+            return F (std::abs ((v - i2) * 2.0 - 1.0));
+        }
+        case 7:
+        {
+            const auto d = p.sign > 0 ? 1.0 - ph : ph;
+            const auto d3 = d * d * d;
+            return F (ph - (d3 * d3 - d) * p4);
+        }
+        case 8:
+        {
+            if (ph < 0.5)
+            {
+                const auto x = ph * 2.0;
+                const auto d = p.sign > 0 ? 1.0 - x : x;
+                const auto d3 = d * d * d;
+                return F ((x - (d3 * d3 - d) * p4) * 0.5);
+            }
+            const auto x = (1.0 - ph) * 2.0;
+            const auto d = p.sign > 0 ? 1.0 - x : x;
+            const auto d3 = d * d * d;
+            return F (1.0 - (x - (d3 * d3 - d) * p4) * 0.5);
+        }
+        case 9:
+        {
+            const auto hp = (double) 1.5707963705062866;
+            const auto d = p.sign > 0 ? std::sin (ph * hp) : 1.0 - std::cos (ph * hp);
+            return F (ph - (ph - d) * p4);
+        }
+        case 10:
+        {
+            const auto x2 = ph * ph, x1 = ph - 1.0;
+            return F (ph + ((((x2 * 3.0 - x2 * 2.0 * ph) + x2 * x1 * p4) + ph * x1 * x1 * p5) - ph) * p6);
+        }
+        case 11:
+            if (p.sign < 1)
+                return F (p5 / (1.0 - p4 * ph) - p6);
+            return F (p5 / (1.0 - p4 * (1.0 - ph)) - p6);
+        case 12:
+            if (ph < 0.5)
+            {
+                if (p.sign < 1)
+                    return F (p5 / (1.0 - p4 * ph * 2.0) - p6);
+                return F (p5 / (1.0 - p4 * (1.0 - ph * 2.0)) - p6);
+            }
+            else
+            {
+                const auto x = (1.0 - ph) * 2.0;
+                if (p.sign < 1)
+                    return F ((1.0 - p5 / (1.0 - p4 * x)) + p6);
+                return F ((1.0 - p5 / (1.0 - p4 * (1.0 - x))) + p6);
+            }
+        default: return 0.0f; // 2 (hold) and unknown modes
+    }
+}
+
+const std::vector<WsPoint>& defaultCurve()
+{
+    static const std::vector<WsPoint> c { { 0.0f, 0.0f, 0.0f, 0 }, { 1.0f, 1.0f, 0.0f, 0 } };
+    return c;
+}
+
+// --------------------------------------------------------------------------------------------- oversampling (§2.6)
+// polyphase IIR half-band: two chains of three first-order all-passes (y = x[n−1] + (x − y[n−1])·a), in double
+constexpr double kA[3] = { 0.1473771136010466, 0.48246854276970014, 0.8830050257693731 };
+constexpr double kB[3] = { 0.039151597734460045, 0.3026468483284934, 0.6746159185469639 };
+
+struct HalfBand
+{
+    // per channel: outputs A1 A2 A3 B1 B2 B3, then the previous inputs of each all-pass
+    double s[12] {};
+    void clear() noexcept { std::fill (std::begin (s), std::end (s), 0.0); }
+    void flush() noexcept
+    {
+        for (int i = 0; i < 6; ++i)
+            if (std::abs (s[i]) < kEps)
+                s[i] = 0.0;
+    }
+    void up (const float* x, float* y, int m) noexcept
+    {
+        for (int n = 0; n < m; ++n)
+        {
+            const double v = x[n];
+            const double a1 = s[6] + (v - s[0]) * kA[0];
+            s[6] = v, s[0] = a1;
+            const double b1 = s[9] + (v - s[3]) * kB[0];
+            s[9] = v, s[3] = b1;
+            const double a2 = s[7] + (s[0] - s[1]) * kA[1];
+            s[7] = s[0], s[1] = a2;
+            const double b2 = s[10] + (s[3] - s[4]) * kB[1];
+            s[10] = s[3], s[4] = b2;
+            const double a3 = s[8] + (s[1] - s[2]) * kA[2];
+            s[2] = a3;
+            const double b3 = s[11] + (s[4] - s[5]) * kB[2];
+            s[5] = b3;
+            s[8] = s[1], s[11] = s[4];
+            y[2 * n] = (float) b3;
+            y[2 * n + 1] = (float) a3;
+        }
+        flush();
+    }
+    void down (const float* x, float* y, int m) noexcept
+    {
+        for (int n = 0; n < m; ++n)
+        {
+            const double e = x[2 * n], o = x[2 * n + 1];
+            const double a1 = s[6] + (e - s[0]) * kA[0];
+            s[6] = e, s[0] = a1;
+            const double b1 = s[9] + (o - s[3]) * kB[0];
+            s[9] = o, s[3] = b1;
+            const double a2 = s[7] + (s[0] - s[1]) * kA[1];
+            s[7] = s[0], s[1] = a2;
+            const double b2 = s[10] + (s[3] - s[4]) * kB[1];
+            s[10] = s[3], s[4] = b2;
+            const double a3 = s[8] + (s[1] - s[2]) * kA[2];
+            s[8] = s[1], s[2] = a3;
+            const double b3 = s[11] + (s[4] - s[5]) * kB[2];
+            s[11] = s[4], s[5] = b3;
+            y[n] = (float) ((b3 + a3) * 0.5);
+        }
+        flush();
+    }
+};
+
+// ------------------------------------------------------------------------------------------------- kernels (§2.5)
+struct KernelArgs
+{
+    const std::int16_t* T = nullptr; // entry k at T[k + 1]
+    int N = 0;
+    float dry = 0, wet = 0, pre = 0;
+    bool unipolar = false;
+};
+
+constexpr ld kTwo31 = 2147483648.0L;
+
+[[gnu::noinline]] void kernelNearest (const float* x, float* y, int m, const KernelArgs& a) noexcept
+{
+    const X87Mode mode (false);
+    const auto* T = a.T + 1;
+    const ld A = a.dry, bK = (ld) a.wet * 3.0517578125e-05L;
+    if (! a.unipolar)
+    {
+        const ld preN = (ld) a.pre * (ld) a.N;
+        for (int k = 0; k < m; ++k)
+        {
+            const ld X = x[k];
+            const ld v = X * preN;
+            const long long i = std::abs (v) >= kTwo31 ? -2147483648LL : x87Int (v);
+            const long long ai = std::min<long long> (i < 0 ? -i : i, a.N);
+            const ld t = i < 0 ? -(ld) T[ai] : (ld) T[ai];
+            y[k] = (float) (X * A + t * bK);
+        }
+        return;
+    }
+    const ld hN = (ld) a.N * 0.5L, pHN = (ld) a.pre * (ld) a.N * 0.5L;
+    for (int k = 0; k < m; ++k)
+    {
+        const ld X = x[k];
+        const ld v = X * pHN + hN;
+        long long i = std::abs (v) >= kTwo31 ? -2147483648LL : x87Int (v);
+        i = std::clamp<long long> (i, 0, a.N);
+        y[k] = (float) (X * A + (ld) T[i] * bK);
+    }
+}
+
+// the interpolating kernels run with the x87 rounding set toward zero: every product, sum and the float store
+[[gnu::noinline]] void kernelInterp (const float* x, float* y, int m, const KernelArgs& a) noexcept
+{
+    const X87Mode mode (true);
+    const auto* T = a.T + 1;
+    volatile float vdry = a.dry, vwet = a.wet, vpre = a.pre; // computed after the mode change
+    const ld A = vdry, bK = (ld) vwet * 3.0517578125e-05L;
+    if (! a.unipolar)
+    {
+        const ld preN = (ld) vpre * (ld) a.N;
+        for (int k = 0; k < m; ++k)
+        {
+            const ld X = x[k];
+            const ld v = X * preN;
+            ld t;
+            if (std::abs (v) >= kTwo31)
+                t = 0.0L;
+            else
+            {
+                const auto i = x87Int (v); // toward zero in this mode
+                const ld fr = v - (ld) i;
+                if (i >= 0)
+                {
+                    const auto j = std::min<long long> (i, a.N);
+                    const ld t0 = T[j], t1 = T[j + 1];
+                    t = t0 + (t1 - t0) * fr;
+                }
+                else
+                {
+                    const auto j = std::min<long long> (-i, a.N);
+                    const ld t0 = T[j], t1 = T[j + 1];
+                    t = -(t0 - (t1 - t0) * fr);
+                }
+            }
+            y[k] = (float) (X * A + t * bK);
+        }
+        return;
+    }
+    const ld hN = (ld) a.N * 0.5L, pHN = (ld) vpre * (ld) a.N * 0.5L;
+    for (int k = 0; k < m; ++k)
+    {
+        const ld X = x[k];
+        const ld v = X * pHN + hN;
+        long long i;
+        ld fr;
+        if (std::abs (v) >= kTwo31)
+        {
+            i = -2147483648LL;
+            fr = v - (ld) i;
+        }
+        else
+        {
+            i = x87Int (v);
+            fr = v - (ld) i;
+        }
+        i = std::clamp<long long> (i, -1, a.N);
+        const ld t0 = T[i], t1 = T[i + 1];
+        y[k] = (float) (X * A + (t0 + (t1 - t0) * fr) * bK);
+    }
+}
+} // namespace
+
+// ================================================================================================== Soft Clipper
+std::optional<SoftClipperState> parseSoftClipper (const std::vector<std::uint8_t>& state)
+{
+    if (state.size() < 8)
+        return std::nullopt;
+    return SoftClipperState { i32At (state, 0), i32At (state, 4) };
+}
+
+void softClipperToParams (const SoftClipperState& s, float* params) noexcept
+{
+    params[0] = norm (s.threshold, 1, 127);
+    params[1] = norm (s.post, 0, 160);
+}
+
+SoftClipperState softClipperFromParams (const float* params) noexcept
+{
+    return { rawFrom (params[0], 1, 127), rawFrom (params[1], 0, 160) };
+}
+
+void softClip (float* x, int n, int threshold, int post) noexcept
+{
+    // threshold t = v/128 (ceiling 1); range 1 − t (2^-16 when ≤ 0); its inverse — all floats (§1.1)
+    const float t = (float) threshold * 0.0078125f;
+    float r = 1.0f - t;
+    if (r <= 0.0f)
+        r = 1.52587890625e-05f;
+    const float inv = 1.0f / r;
+    std::int32_t tb = 0;
+    std::memcpy (&tb, &t, 4);
+    {
+        const X87Mode mode (false);
+        for (int k = 0; k < n; ++k)
+        {
+            std::uint32_t xb = 0;
+            std::memcpy (&xb, x + k, 4);
+            const auto ab = (std::int32_t) (xb & 0x7fffffffu);
+            if (ab <= tb) // compared as integers (|x| > t for every |x| when t < 0)
+                continue;
+            float a = 0;
+            std::memcpy (&a, &ab, 4);
+            const ld e = ((ld) t - (ld) a) * (ld) inv;
+            const auto yv = (float) ((1.0L - std::exp (e)) * (ld) r + (ld) t);
+            std::uint32_t yb = 0;
+            std::memcpy (&yb, &yv, 4);
+            yb |= xb & 0x80000000u;
+            std::memcpy (x + k, &yb, 4);
+        }
+    }
+    const float g = postGain (post);
+    if (g != 1.0f)
+        for (int k = 0; k < n; ++k)
+            x[k] = x[k] * g;
+}
+
+const char* softClipperParamName (int param) noexcept
+{
+    static const char* names[softClipperParams] = { "Threshold", "Post" };
+    return param >= 0 && param < softClipperParams ? names[param] : "";
+}
+
+std::string softClipperParamText (int param, float value01)
+{
+    char text[32];
+    if (param == 0)
+    {
+        const auto v = rawFrom (value01, 1, 127);
+        std::snprintf (text, sizeof (text), "%.1f dB", 20.0 * std::log10 (v / 128.0));
+    }
+    else
+    {
+        const auto g = postGain (rawFrom (value01, 0, 160));
+        if (g <= 0.0f)
+            return "-inf dB";
+        std::snprintf (text, sizeof (text), "%+.1f dB", 20.0 * std::log10 ((double) g));
+    }
+    return text;
+}
+
+namespace
+{
+class SoftClipperEffect final : public Effect
+{
+public:
+    void prepare (double) noexcept override {}
+    void reset() noexcept override {}
+    void process (float* left, float* right, int n, const EffectParams& params, double) noexcept override
+    {
+        const auto s = softClipperFromParams (params.data());
+        softClip (left, n, s.threshold, s.post);
+        softClip (right, n, s.threshold, s.post);
+    }
+};
+} // namespace
+
+std::unique_ptr<Effect> makeSoftClipper() { return std::make_unique<SoftClipperEffect>(); }
+
+// ==================================================================================================== WaveShaper
+std::optional<WaveShaperState> parseWaveShaper (const std::vector<std::uint8_t>& d)
+{
+    // version (low word 3; high word = layout 2…4), pre / mix / post, unipolar, CENTER, oversampling, the map
+    // (kind, version 3, points of 24 bytes, 20-byte header), then the options of later layouts (§2.2)
+    if (d.size() < 34)
+        return std::nullopt;
+    auto v = (std::uint32_t) i32At (d, 0);
+    if ((std::int32_t) v > 0x40003)
+        return std::nullopt;
+    if (v > 0xffff)
+        v >>= 16;
+    WaveShaperState s;
+    s.version = (int) v;
+    s.pre = i32At (d, 4);
+    s.mix = i32At (d, 8);
+    s.post = i32At (d, 12);
+    s.unipolar = d[16] != 0;
+    s.center = d[17] != 0;
+    s.oversampling = i32At (d, 18);
+    std::size_t o = 22;
+    const auto mapVersion = i32At (d, o + 4);
+    const auto n = i32At (d, o + 8);
+    o += 12;
+    if (mapVersion != 3 || n < 0 || n > 100000 || d.size() < o + 24 * (std::size_t) n + 20)
+        return std::nullopt;
+    float prev = 0.0f;
+    for (int i = 0; i < n; ++i, o += 24)
+    {
+        WsPoint p;
+        p.dt = (float) f64At (d, o);
+        p.y = (float) f64At (d, o + 8);
+        if (std::isnan (p.y))
+            p.y = prev;
+        prev = p.y;
+        p.tension = f32At (d, o + 16);
+        p.mode = d[o + 20];
+        s.points.push_back (p);
+    }
+    o += 20;
+    if (v > 1 && d.size() >= o + 4)
+        o += 4; // step-editing flag (editor only)
+    if (v > 2 && d.size() > o)
+        s.hq = d[o++] != 0;
+    if (v > 3 && d.size() > o)
+        s.smooth = d[o++] != 0;
+
+    // the map spans exactly 1: a point at 0 is added if the first starts later; every Δt is scaled by 1/total
+    auto& pts = s.points;
+    if (! pts.empty() && pts[0].dt > 0.0f)
+        pts.insert (pts.begin(), WsPoint { 0.0f, pts[0].y, 0.0f, 0 });
+    double total = 0.0;
+    for (const auto& p : pts)
+        total += (double) p.dt;
+    if (total > 0.0)
+    {
+        const double f = 1.0 / total;
+        if (f != 1.0)
+            for (auto& p : pts)
+                p.dt = (float) ((double) p.dt * f);
+    }
+    else
+        pts.push_back (WsPoint { 1.0f, pts.empty() ? 0.0f : pts.back().y, 0.0f, 0 });
+    return s;
+}
+
+void waveShaperToParams (const WaveShaperState& s, float* params) noexcept
+{
+    params[0] = norm (s.pre, 64, 192);
+    params[1] = norm (s.mix, 0, 128);
+    params[2] = norm (s.post, 0, 128);
+    params[3] = norm (s.oversampling, 0, 4);
+    params[4] = s.hq ? 1.0f : 0.0f;
+    params[5] = s.smooth ? 1.0f : 0.0f;
+    params[6] = s.center ? 1.0f : 0.0f;
+    params[7] = s.unipolar ? 1.0f : 0.0f;
+}
+
+const char* waveShaperParamName (int param) noexcept
+{
+    static const char* names[waveShaperParams] = { "Pre amp", "Mix", "Post gain", "Oversampling", "HQ", "Smooth", "Center", "Unipolar" };
+    return param >= 0 && param < waveShaperParams ? names[param] : "";
+}
+
+std::string waveShaperParamText (int param, float v)
+{
+    char text[32];
+    switch (param)
+    {
+        case 0:
+        {
+            const float s0 = (float) rawFrom (v, 64, 192) * 0.0078125f;
+            const auto g = (std::exp ((double) s0 * std::log (4.0)) - 1.0) / 3.0;
+            std::snprintf (text, sizeof (text), "%+.1f dB", 20.0 * std::log10 (g));
+            return text;
+        }
+        case 1: std::snprintf (text, sizeof (text), "%d%%", (int) std::lround (rawFrom (v, 0, 128) * 100.0 / 128.0)); return text;
+        case 2:
+        {
+            const auto g = postGain (rawFrom (v, 0, 128));
+            if (g <= 0.0f)
+                return "-inf dB";
+            std::snprintf (text, sizeof (text), "%+.1f dB", 20.0 * std::log10 ((double) g));
+            return text;
+        }
+        case 3:
+        {
+            const auto k = rawFrom (v, 0, 4);
+            if (k == 0)
+                return "Off";
+            std::snprintf (text, sizeof (text), "x%d", 1 << k);
+            return text;
+        }
+        default: return v >= 0.5f ? "On" : "Off";
+    }
+}
+
+std::vector<std::int16_t> shaperTable (const std::vector<WsPoint>& points, bool unipolar)
+{
+    // the map read by FL's incremental evaluator in steps of 1/N, each value × (32767 or 65535) rounded (§2.3)
+    auto pts = preparePoints (points.empty() ? defaultCurve() : points);
+    const int n = (int) pts.size();
+    const double off = unipolar ? 0.5 : 0.0;
+    auto level = [&] (int i) { return (double) pts[(std::size_t) i].y - off; };
+    const int N = (unipolar ? 2 : 1) * 0x4000 - 1;
+    const double sc = (double) ((unipolar ? 2 : 1) * 0x8000 - 1);
+    const double dx = 1.0 / N;
+    std::vector<std::int16_t> T ((std::size_t) N + 3, 0);
+
+    int idx = 0;
+    double rate, ph;
+    if (pts[0].dt == 0.0f)
+        rate = 1.0, ph = 1.0;
+    else
+        rate = 1.0 / (double) pts[0].dt, ph = 0.0;
+    float start = F (level (0)), delta = 0.0f, val = start;
+    for (int i = 0; i <= N; ++i)
+    {
+        const auto r = std::nearbyint ((double) val * sc);
+        T[(std::size_t) i + 1] = (std::int16_t) std::clamp (r, -32768.0, 32767.0);
+        ph += dx * rate;
+        while (ph >= 1.0)
+        {
+            const int old = idx;
+            ph = rate == 0.0 ? dx : (ph - 1.0) / rate;
+            start = F (level (idx));
+            if (idx < n - 1)
+                ++idx;
+            delta = F (level (idx) - (double) start);
+            if (old == idx)
+                ph = 0.0, rate = 0.0;
+            else
+            {
+                const double dt = pts[(std::size_t) idx].dt;
+                if (dt <= 0.0)
+                    rate = 1.0, ph += 1.0;
+                else
+                    rate = 1.0 / dt, ph *= rate;
+            }
+        }
+        val = start + shape (pts[(std::size_t) idx], ph) * delta;
+    }
+    T[0] = T[1];
+    T[(std::size_t) N + 2] = T[(std::size_t) N + 1];
+    return T;
+}
+
+// ----------------------------------------------------------------------------------------------------- engine
+struct WaveShaperEngine::Impl
+{
+    static constexpr int maxBlock = 512, maxOrder = 4;
+    std::vector<std::int16_t> tables[2]; // bipolar, unipolar
+    double rate = 44100.0;
+    float smoothC = 0.0f, dcA = 0.0f, dcB = 0.96f;
+    // controls
+    int pre = -1, mix = -1, post = -1, order = 0;
+    bool hq = false, smooth = false, center = false, unipolar = false, render = false;
+    float dry = 0.0f, wet = 1.0f, preGain = 1.0f;
+    float sm[3] {}; // smoothed pre, wet, dry (start at 0, as in FL)
+    int stages = -1;
+    HalfBand up[maxOrder][2], down[maxOrder][2];
+    double dc[2][2] {}; // per channel: position, velocity
+    std::vector<float> a[2], b[2];
+
+    Impl()
+    {
+        for (int c = 0; c < 2; ++c)
+        {
+            a[c].assign ((std::size_t) maxBlock << maxOrder, 0.0f);
+            b[c].assign ((std::size_t) maxBlock << maxOrder, 0.0f);
+        }
+    }
+
+    void computeGains() noexcept
+    {
+        const float k = 0.0078125f;
+        const float s0 = (float) pre * k;
+        preGain = F (std::exp ((double) s0 * std::log (4.0)) - 1.0) / 3.0f;
+        const float g = postGain (post);
+        const float m = (float) mix * k;
+        wet = m * g;
+        dry = ((g - wet) * preGain) * g;
+    }
+
+    void resetStages() noexcept
+    {
+        for (auto& s : up)
+            for (auto& h : s)
+                h.clear();
+        for (auto& s : down)
+            for (auto& h : s)
+                h.clear();
+    }
+
+    void dcBlock (float* x, int m, int c) noexcept
+    {
+        // CENTER: a two-pole tracker subtracted from the signal, x87 state kept in long double within the block
+        const X87Mode mode (false);
+        ld pos = dc[c][0], vel = dc[c][1];
+        const ld A = dcA, B = dcB;
+        for (int k = 0; k < m; ++k)
+        {
+            const ld X = x[k];
+            vel = vel + (X - pos) * A;
+            pos = pos + vel;
+            vel = vel * B;
+            x[k] = (float) (X - pos);
+        }
+        auto fl = [] (ld v) { return std::abs (v) <= (ld) kEps ? 0.0 : (double) v; };
+        dc[c][0] = fl (pos);
+        dc[c][1] = fl (vel);
+    }
+
+    void block (float* L, float* R, int n) noexcept
+    {
+        const int k = order > 0 ? (render ? 4 : order) : 0;
+        if (k != stages)
+        {
+            resetStages();
+            stages = k;
+        }
+        float* io[2] = { L, R };
+        float* buf[2] = { L, R };
+        int m = n;
+        for (int c = 0; c < 2 && k > 0; ++c)
+        {
+            const float* src = io[c];
+            int len = n;
+            float* dst = nullptr;
+            for (int s = k - 1; s >= 0; --s)
+            {
+                dst = ((k - 1 - s) & 1) == 0 ? a[c].data() : b[c].data();
+                up[s][c].up (src, dst, len);
+                src = dst;
+                len *= 2;
+            }
+            buf[c] = dst;
+            m = len;
+        }
+        KernelArgs args;
+        args.unipolar = unipolar;
+        const auto& T = tables[unipolar ? 1 : 0];
+        args.T = T.data();
+        args.N = (int) T.size() - 3;
+        const bool interp = render || hq;
+        auto run = [&] (const float* x, float* y, int len) {
+            if (interp)
+                kernelInterp (x, y, len, args);
+            else
+                kernelNearest (x, y, len, args);
+        };
+        if (! smooth)
+        {
+            args.dry = dry, args.wet = wet, args.pre = preGain;
+            for (int c = 0; c < 2; ++c)
+                run (buf[c], buf[c], m);
+        }
+        else
+            for (int i = 0; i < m; ++i)
+            {
+                sm[0] = sm[0] + (preGain - sm[0]) * smoothC;
+                sm[1] = sm[1] + (wet - sm[1]) * smoothC;
+                sm[2] = sm[2] + (dry - sm[2]) * smoothC;
+                args.pre = sm[0], args.wet = sm[1], args.dry = sm[2];
+                run (buf[0] + i, buf[0] + i, 1);
+                run (buf[1] + i, buf[1] + i, 1);
+            }
+        for (int c = 0; c < 2 && k > 0; ++c)
+        {
+            const float* src = buf[c];
+            int len = m;
+            for (int s = k - 1; s >= 0; --s)
+            {
+                float* dst = s == 0 ? io[c] : (src == a[c].data() ? b[c].data() : a[c].data());
+                len /= 2;
+                down[s][c].down (src, dst, len);
+                src = dst;
+            }
+        }
+        if (center)
+        {
+            dcBlock (L, n, 0);
+            dcBlock (R, n, 1);
+        }
+    }
+};
+
+WaveShaperEngine::WaveShaperEngine() : d (std::make_unique<Impl>())
+{
+    setCurve ({});
+    prepare (44100.0);
+}
+WaveShaperEngine::~WaveShaperEngine() = default;
+
+void WaveShaperEngine::setCurve (const std::vector<WsPoint>& points)
+{
+    d->tables[0] = shaperTable (points, false);
+    d->tables[1] = shaperTable (points, true);
+}
+
+void WaveShaperEngine::prepare (double sampleRate) noexcept
+{
+    d->rate = sampleRate > 0 ? sampleRate : 44100.0;
+    // parameter glide: 1 − 0.1^(1/(fs·0.005)); CENTER: 2.2835e-5·44100/fs and 0.96 (§2.7, §2.8)
+    const double den = (double) ((float) d->rate * 0.005f);
+    d->smoothC = F (1.0 - std::exp ((1.0 / den) * std::log (0.1)));
+    d->dcA = F (44100.0 / d->rate * 2.2835e-05);
+    d->dcB = 0.96f;
+    reset();
+}
+
+void WaveShaperEngine::reset() noexcept
+{
+    d->resetStages();
+    d->stages = -1;
+    for (auto& c : d->dc)
+        c[0] = c[1] = 0.0;
+}
+
+void WaveShaperEngine::setControls (int pre, int mix, int post, int oversampling, bool hq, bool smooth, bool center,
+                                    bool unipolar, bool renderMode) noexcept
+{
+    if (pre != d->pre || mix != d->mix || post != d->post)
+    {
+        d->pre = pre, d->mix = mix, d->post = post;
+        d->computeGains();
+    }
+    d->order = std::clamp (oversampling, 0, Impl::maxOrder);
+    d->hq = hq, d->smooth = smooth, d->center = center, d->unipolar = unipolar, d->render = renderMode;
+}
+
+void WaveShaperEngine::process (float* left, float* right, int n) noexcept
+{
+    for (int i = 0; i < n; i += Impl::maxBlock)
+        d->block (left + i, right + i, std::min (Impl::maxBlock, n - i));
+}
+
+namespace
+{
+class WaveShaperEffect final : public Effect
+{
+public:
+    explicit WaveShaperEffect (const std::vector<WsPoint>& points) { engine.setCurve (points); }
+    void prepare (double sampleRate) noexcept override { engine.prepare (sampleRate); }
+    void reset() noexcept override { engine.reset(); }
+    void process (float* left, float* right, int n, const EffectParams& p, double) noexcept override
+    {
+        engine.setControls (rawFrom (p[0], 64, 192), rawFrom (p[1], 0, 128), rawFrom (p[2], 0, 128), rawFrom (p[3], 0, 4),
+                            p[4] >= 0.5f, p[5] >= 0.5f, p[6] >= 0.5f, p[7] >= 0.5f, offlineRendering());
+        engine.process (left, right, n);
+    }
+
+private:
+    WaveShaperEngine engine;
+};
+} // namespace
+
+std::unique_ptr<Effect> makeWaveShaper (const std::vector<std::uint8_t>& flState)
+{
+    std::vector<WsPoint> points;
+    if (const auto s = parseWaveShaper (flState))
+        points = s->points;
+    return std::make_unique<WaveShaperEffect> (points);
+}
+} // namespace lynx::flshape

+ 88 - 0
src/core/FruityShapers.h

@@ -0,0 +1,88 @@
+#pragma once
+
+// FL Studio's Fruity WaveShaper and Fruity Soft Clipper as LYNX mixer effects, exact engines rebuilt in
+// docs/analise/REA_rodada51.md (clean-room: layouts, formulas and behaviour in our own words; no Image-Line code or
+// data in this repository).
+//
+// Soft Clipper (EffectKind::fruitySoftClipper): stateless. Parameters = FL's two controls over their ranges:
+//   [0] threshold 1…127, [1] post 0…160 (value = (raw − min) / (max − min)).
+//
+// WaveShaper (EffectKind::fruityWaveShaper): the curve (FL's map editor points) travels in EffectSlot::state as FL's
+// own saved state (plugin record 0xD5); the controls are slot parameters so the LYNX UI can change them:
+//   [0] pre amp 64…192, [1] mix 0…128, [2] post gain 0…128, [3] oversampling order 0…4 (×1…×16),
+//   [4] HQ (interpolated table), [5] smooth (per-sample parameter glide), [6] CENTER (DC removal),
+//   [7] unipolar curve. The saved state's own values are copied into the parameters at import.
+// While LYNX exports (offlineRendering()), the WaveShaper behaves as FL's does when it renders: the interpolated
+// table and, when oversampling is on, order 4 (×16).
+
+#include <cstdint>
+#include <memory>
+#include <optional>
+#include <string>
+#include <vector>
+
+#include "core/Effects.h"
+
+namespace lynx::flshape
+{
+// ------------------------------------------------------------------------------------------------- Soft Clipper
+constexpr int softClipperParams = 2;
+struct SoftClipperState
+{
+    int threshold = 100, post = 128; // FL's raw controls (defaults of a new instance)
+};
+// record 0xD5: two i32 (threshold, post)
+std::optional<SoftClipperState> parseSoftClipper (const std::vector<std::uint8_t>& state);
+void softClipperToParams (const SoftClipperState& s, float* params) noexcept;
+SoftClipperState softClipperFromParams (const float* params) noexcept;
+// the engine on one channel, in place (it has no memory)
+void softClip (float* x, int n, int threshold, int post) noexcept;
+const char* softClipperParamName (int param) noexcept;
+std::string softClipperParamText (int param, float value01);
+std::unique_ptr<Effect> makeSoftClipper();
+
+// ------------------------------------------------------------------------------------------------------ WaveShaper
+constexpr int waveShaperParams = 8;
+struct WsPoint
+{
+    float dt = 0.0f, y = 0.0f, tension = 0.0f; // Δt from the previous point (the map spans 1), level 0…1
+    std::uint8_t mode = 0;                     // segment shape (0 single curve … 12), REA_rodada51 §2.4
+};
+struct WaveShaperState
+{
+    int version = 4;
+    int pre = 128, mix = 128, post = 128, oversampling = 0;
+    bool unipolar = false, center = false, hq = false, smooth = false;
+    std::vector<WsPoint> points; // after FL's load-time normalisation (first point at 0, total time 1)
+};
+std::optional<WaveShaperState> parseWaveShaper (const std::vector<std::uint8_t>& state);
+void waveShaperToParams (const WaveShaperState& s, float* params) noexcept;
+const char* waveShaperParamName (int param) noexcept;
+std::string waveShaperParamText (int param, float value01);
+
+// The shaping table: entries −1 … N+1 (stored from index 0), N = 16383 (bipolar) or 32767 (unipolar).
+std::vector<std::int16_t> shaperTable (const std::vector<WsPoint>& points, bool unipolar);
+
+class WaveShaperEngine
+{
+public:
+    WaveShaperEngine();
+    ~WaveShaperEngine();
+    // points: the state's curve (tables for both polarities are built here, off the audio thread)
+    void setCurve (const std::vector<WsPoint>& points);
+    void prepare (double sampleRate) noexcept;
+    void reset() noexcept;
+    // FL's controls (raw values) and options; renderMode = FL's "rendering" process mode
+    void setControls (int pre, int mix, int post, int oversampling, bool hq, bool smooth, bool center, bool unipolar,
+                      bool renderMode) noexcept;
+    // stereo, in place; any n (split into FL-sized blocks of 512 frames)
+    void process (float* left, float* right, int n) noexcept;
+
+private:
+    struct Impl;
+    std::unique_ptr<Impl> d;
+};
+
+// the mixer effect; flState = FL's saved state (an empty or unreadable state gives FL's default curve)
+std::unique_ptr<Effect> makeWaveShaper (const std::vector<std::uint8_t>& flState);
+} // namespace lynx::flshape

+ 2 - 0
src/core/Song.h

@@ -297,6 +297,8 @@ enum class EffectKind : std::uint8_t
     maximus,      // FL's Maximus / Soundgoodizer engine (REA_rodada36/38, core/MaximusFx.h): built from EffectSlot::state
     fruityLimiter,   // FL's Fruity Limiter, exact (REA_rodada48, core/FruityDynamics.h): FL's raw controls / range
     fruityCompressor, // FL's Fruity Compressor, exact (REA_rodada48, core/FruityDynamics.h): FL's raw controls / range
+    fruityWaveShaper, // FL's Fruity WaveShaper, exact (REA_rodada51, core/FruityShapers.h): curve in EffectSlot::state, controls / range
+    fruitySoftClipper, // FL's Fruity Soft Clipper, exact (REA_rodada51, core/FruityShapers.h): threshold, post / range
     fruityDelay2, // FL's Fruity Delay 2, exact (REA_rodada52, core/FruityDelay.h): FL's 8 raw controls / range
     fruityDelay3  // FL's Fruity Delay 3, exact (REA_rodada52, core/FruityDelay.h): FL's 26 raw controls / range
 };

+ 3 - 1
src/engine/ProjectFile.cpp

@@ -147,6 +147,8 @@ const char* effectId (EffectKind k)
         case EffectKind::maximus: return "maximus";
         case EffectKind::fruityLimiter: return "fruityLimiter";
         case EffectKind::fruityCompressor: return "fruityCompressor";
+        case EffectKind::fruityWaveShaper: return "fruityWaveShaper";
+        case EffectKind::fruitySoftClipper: return "fruitySoftClipper";
         case EffectKind::fruityDelay2: return "fruityDelay2";
         case EffectKind::fruityDelay3: return "fruityDelay3";
     }
@@ -290,7 +292,7 @@ std::optional<EffectSlot> effectFromVar (const juce::var& e)
 std::optional<EffectKind> effectFromId (const juce::String& id)
 {
     for (auto k : { EffectKind::eq, EffectKind::compressor, EffectKind::delay, EffectKind::reverb, EffectKind::plugin,
-                    EffectKind::limiter, EffectKind::filter, EffectKind::distortion, EffectKind::chorus, EffectKind::parametricEq, EffectKind::utility, EffectKind::volumeGate, EffectKind::peakController, EffectKind::pitchShift, EffectKind::freqShift, EffectKind::parallel, EffectKind::lofi, EffectKind::effector, EffectKind::crossover, EffectKind::rhythmGain, EffectKind::autoPan, EffectKind::vocoder, EffectKind::pitchCorrect, EffectKind::squeeze, EffectKind::vintagePhaser, EffectKind::vocodex, EffectKind::maximus, EffectKind::fruityLimiter, EffectKind::fruityCompressor, EffectKind::fruityDelay2, EffectKind::fruityDelay3 })
+                    EffectKind::limiter, EffectKind::filter, EffectKind::distortion, EffectKind::chorus, EffectKind::parametricEq, EffectKind::utility, EffectKind::volumeGate, EffectKind::peakController, EffectKind::pitchShift, EffectKind::freqShift, EffectKind::parallel, EffectKind::lofi, EffectKind::effector, EffectKind::crossover, EffectKind::rhythmGain, EffectKind::autoPan, EffectKind::vocoder, EffectKind::pitchCorrect, EffectKind::squeeze, EffectKind::vintagePhaser, EffectKind::vocodex, EffectKind::maximus, EffectKind::fruityLimiter, EffectKind::fruityCompressor, EffectKind::fruityWaveShaper, EffectKind::fruitySoftClipper, EffectKind::fruityDelay2, EffectKind::fruityDelay3 })
         if (id == effectId (k))
             return k;
 

+ 1 - 0
src/ui/MixerComponent.cpp

@@ -1002,6 +1002,7 @@ const EffectKind allEffects[] = { EffectKind::eq,     EffectKind::parametricEq,
                                       EffectKind::distortion, EffectKind::utility, EffectKind::volumeGate,
                                       EffectKind::pitchShift, EffectKind::freqShift, EffectKind::lofi, EffectKind::effector, EffectKind::crossover, EffectKind::autoPan, EffectKind::vocoder, EffectKind::pitchCorrect,
                                       EffectKind::fruityLimiter, EffectKind::fruityCompressor,
+                                      EffectKind::fruityWaveShaper, EffectKind::fruitySoftClipper,
                                       EffectKind::fruityDelay2, EffectKind::fruityDelay3 };
 } // namespace
 

+ 145 - 0
tests/tests.cpp

@@ -43,6 +43,7 @@
 #include "core/HarmlessFx.h"
 #include "core/MaximusFx.h"
 #include "core/FruityDynamics.h"
+#include "core/FruityShapers.h"
 #include "core/FruityDelay.h"
 #include "core/LiveEventQueue.h"
 #include "core/RackRenderer.h"
@@ -787,6 +788,7 @@ TEST (flp_real_files)
     int dwChannels = 0, dwZones = 0, fpcKits = 0, padChannels = 0, padNotes = 0;
     int harmlessCompWanted = 0, harmlessCompLoaded = 0; // Harmless rack compressors / presets read from the installation
     int maximusSlots = 0, maximusExact = 0, sgzSlots = 0, sgzExact = 0, vocodexSlots = 0, vocodexWithData = 0; // REA_rodada40
+    int shaperSlots = 0, shaperExact = 0, clipperSlots = 0, clipperExact = 0; // REA_rodada51
     int delay2Slots = 0, delay2Exact = 0, delay3Slots = 0, delay3Exact = 0; // REA_rodada52
     // import with the installation's samples (realFlpDir is ...\Data): for DirectWave/FPC
     lynx::FlpImportOptions withFiles;
@@ -1033,6 +1035,8 @@ TEST (flp_real_files)
                         delay3Slots += slot.plugin == "Fruity Delay 3";
                         sgzSlots += slot.plugin == "Soundgoodizer";
                         vocodexSlots += slot.plugin == "Vocodex";
+                        shaperSlots += slot.plugin == "Fruity WaveShaper";
+                        clipperSlots += slot.plugin == "Fruity Soft Clipper";
                     }
                 for (const auto& t : full.mixer)
                     for (const auto& fx : t.effects)
@@ -1046,6 +1050,9 @@ TEST (flp_real_files)
                         }
                         if (fx.kind == lynx::EffectKind::vocodex)
                             vocodexWithData += ! lynx::vocodex::splitInstallData (fx.state).second.sgDat.empty();
+                        if (fx.kind == lynx::EffectKind::fruityWaveShaper)
+                            shaperExact += lynx::flshape::parseWaveShaper (fx.state).has_value() ? 1 : 0;
+                        clipperExact += fx.kind == lynx::EffectKind::fruitySoftClipper;
                         delay2Exact += fx.kind == lynx::EffectKind::fruityDelay2;
                         delay3Exact += fx.kind == lynx::EffectKind::fruityDelay3;
                     }
@@ -1696,6 +1703,10 @@ TEST (flp_real_files)
     // option; the other Data folders add states with options not decoded
     CHECK (maximusSlots - maximusExact <= 16 && maximusExact >= 97 && sgzExact == sgzSlots && sgzSlots > 90);
     CHECK (vocodexWithData == vocodexSlots && vocodexSlots >= 10);
+    std::printf ("  Fruity WaveShaper: %d of %d slots on the exact engine; Fruity Soft Clipper: %d of %d\n", shaperExact, shaperSlots,
+                 clipperExact, clipperSlots);
+    // (Patcher graphs add WaveShaper nodes of their own to the imported mixer)
+    CHECK (shaperExact >= shaperSlots && shaperSlots >= 70 && clipperExact >= clipperSlots && clipperSlots >= 25); // REA_rodada51
     std::printf ("  Fruity Delay 2: %d of %d slots on the exact engine; Fruity Delay 3: %d of %d\n", delay2Exact, delay2Slots,
                  delay3Exact, delay3Slots);
     CHECK (delay2Exact == delay2Slots && delay2Slots >= 60 && delay3Exact == delay3Slots && delay3Slots >= 100); // REA_rodada52
@@ -7671,6 +7682,140 @@ TEST (maximus_engine)
     CHECK (lynx::vocodex::splitInstallData (flState).first == flState);
 }
 
+// ---- Fruity WaveShaper / Fruity Soft Clipper (REA_rodada51) ------------------------------------------------------------
+// States written here from our own values (no FL preset data); goldens from the installation's DLLs (EXEC, blocks of 512)
+namespace
+{
+std::vector<std::uint8_t> waveShaperTestState (int pre, int mix, int post, bool uni, bool center, int os, bool hq, bool smooth)
+{
+    std::vector<std::uint8_t> b;
+    auto i32 = [&b] (std::int32_t v) { for (int k = 0; k < 4; ++k) b.push_back ((std::uint8_t) ((std::uint32_t) v >> (8 * k))); };
+    auto f64 = [&b] (double v) { std::uint64_t u; std::memcpy (&u, &v, 8); for (int k = 0; k < 8; ++k) b.push_back ((std::uint8_t) (u >> (8 * k))); };
+    auto f32 = [&b] (float v) { std::uint32_t u; std::memcpy (&u, &v, 4); for (int k = 0; k < 4; ++k) b.push_back ((std::uint8_t) (u >> (8 * k))); };
+    i32 (0x40003);
+    i32 (pre), i32 (mix), i32 (post);
+    b.push_back (uni ? 1 : 0), b.push_back (center ? 1 : 0);
+    i32 (os);
+    const struct { double dt, y; float t; int mode; } pts[] = { { 0.0, 0.1, 0.0f, 0 }, { 0.3, 0.8, 0.4f, 0 }, { 0.25, 0.35, 0.0f, 10 },
+                                                                 { 0.25, 0.9, -0.3f, 3 }, { 0.2, 1.0, 0.5f, 9 } };
+    i32 (3), i32 (3), i32 (5);
+    for (const auto& p : pts)
+    {
+        f64 (p.dt), f64 (p.y), f32 (p.t);
+        b.push_back ((std::uint8_t) p.mode), b.push_back (0), b.push_back (0), b.push_back (0);
+    }
+    i32 (0), i32 (-1), i32 (-1), i32 (-1), i32 (-1);
+    i32 (1);
+    b.push_back (hq ? 1 : 0), b.push_back (smooth ? 1 : 0);
+    return b;
+}
+} // namespace
+
+TEST (fruity_waveshaper_and_soft_clipper)
+{
+    std::vector<float> inL (4096), inR (4096);
+    for (int n = 0; n < 4096; ++n)
+    {
+        inL[(std::size_t) n] = (float) (((n * 37) % 200 - 100) / 60.0);
+        inR[(std::size_t) n] = (float) (((n * 53) % 170 - 85) / 50.0);
+    }
+    struct Gold { int i; float l, r; };
+    auto close = [] (float a, float b) { return std::abs (a - b) <= 2.0e-7f * std::max (1.0f, std::abs (b)); };
+
+    // Soft Clipper: bit-exact against Fruity Soft Clipper_x64.dll
+    auto clip = [&] (int thr, int post, std::initializer_list<Gold> gold) {
+        std::vector<float> l (inL), r (inR);
+        for (int s = 0; s < 4096; s += 512)
+        {
+            lynx::flshape::softClip (l.data() + s, 512, thr, post);
+            lynx::flshape::softClip (r.data() + s, 512, thr, post);
+        }
+        for (const auto& g : gold)
+            CHECK (l[(std::size_t) g.i] == g.l && r[(std::size_t) g.i] == g.r);
+    };
+    clip (100, 128, { { 100, 0.0f, -0.949052989f }, { 1000, -0.99617976f, 0.872887492f }, { 2047, 0.649999976f, -0.944175363f },
+                      { 3000, -0.99617976f, -0.699999988f }, { 4095, 0.25f, 0.600000024f } });
+    clip (1, 150, { { 100, 0.0f, -1.04588532f }, { 1000, -1.27003884f, 0.930835366f }, { 2047, 0.750244498f, -1.03539562f },
+                    { 3000, -1.27003884f, -0.790091455f }, { 4095, 0.347655922f, 0.708338201f } });
+    clip (64, 140, { { 100, 0.0f, -1.08492827f }, { 1000, -1.21535313f, 0.990323186f }, { 2047, 0.804165959f, -1.0770781f },
+                     { 3000, -1.21535313f, -0.849189103f }, { 4095, 0.319320858f, 0.754407823f } });
+    {
+        const std::vector<std::uint8_t> st { 64, 0, 0, 0, 140, 0, 0, 0 };
+        const auto slot = lynx::effectFromFl ("Fruity Soft Clipper", st, 120.0);
+        CHECK (slot && slot->kind == lynx::EffectKind::fruitySoftClipper);
+        if (slot)
+        {
+            const auto s = lynx::flshape::softClipperFromParams (slot->params.data());
+            CHECK (s.threshold == 64 && s.post == 140);
+            auto fx = lynx::makeEffect (*slot);
+            fx->prepare (44100.0);
+            std::vector<float> l (inL), r (inR);
+            fx->process (l.data(), r.data(), 4096, slot->params, 120.0);
+            CHECK (l[3000] == -1.21535313f && r[4095] == 0.754407823f);
+        }
+    }
+
+    // WaveShaper: tables (bipolar / unipolar) and the engine on three of our states, live and as FL renders
+    const auto stA = waveShaperTestState (150, 100, 120, false, true, 1, true, true);  // CENTER, ×2, HQ, smooth
+    const auto stB = waveShaperTestState (100, 128, 128, true, false, 0, false, false); // unipolar
+    const auto stC = waveShaperTestState (192, 90, 100, false, false, 2, false, false); // ×4
+    const auto pA = lynx::flshape::parseWaveShaper (stA);
+    CHECK (pA && pA->points.size() == 5 && pA->pre == 150 && pA->center && pA->hq && pA->smooth && pA->oversampling == 1);
+    if (pA)
+    {
+        const auto T = lynx::flshape::shaperTable (pA->points, false);
+        CHECK (T.size() == 16386 && T[1] == 3277 && T[1001] == 18824 && T[5001] == 26195 && T[9001] == 11469 && T[12001] == 24614
+               && T[16384] == 32767 && T[0] == T[1]);
+        const auto U = lynx::flshape::shaperTable (pA->points, true);
+        CHECK (U.size() == 32770 && U[1] == -26214 && U[1001] == -6408 && U[5001] == 17073 && U[9001] == 19551 && U[12001] == 14549);
+    }
+    auto shape = [&] (const std::vector<std::uint8_t>& st, bool render, std::initializer_list<Gold> gold) {
+        const auto s = lynx::flshape::parseWaveShaper (st);
+        CHECK (s.has_value());
+        if (! s)
+            return;
+        lynx::flshape::WaveShaperEngine e;
+        e.setCurve (s->points);
+        e.prepare (44100.0);
+        e.setControls (s->pre, s->mix, s->post, s->oversampling, s->hq, s->smooth, s->center, s->unipolar, render);
+        std::vector<float> l (inL), r (inR);
+        for (int i = 0; i < 4096; i += 512)
+            e.process (l.data() + i, r.data() + i, 512);
+        for (const auto& g : gold)
+            CHECK (close (l[(std::size_t) g.i], g.l) && close (r[(std::size_t) g.i], g.r));
+    };
+    shape (stA, false, { { 100, 0.59108448f, 0.469315082f }, { 1000, 0.284353405f, 1.02621937f }, { 2047, -0.533613563f, 0.117038473f },
+                         { 3000, 0.22673659f, -1.13572407f }, { 4095, -0.267153352f, 0.822866499f } });
+    shape (stA, true, { { 100, 0.794869065f, -0.127601087f }, { 1000, -0.00841622613f, 0.900729597f }, { 2047, 0.450603426f, -0.325943232f },
+                        { 3000, -0.0530530401f, -0.32303831f }, { 4095, 1.0959363f, 0.946009099f } });
+    shape (stB, false, { { 100, -0.206451416f, 0.502471924f }, { 1000, -0.799987793f, 0.761169434f }, { 2047, 0.411743164f, 0.514160156f },
+                         { 3000, -0.799987793f, 0.596221924f }, { 4095, -0.157653809f, 0.334106445f } });
+    shape (stB, true, { { 100, -0.206390381f, 0.502493739f }, { 1000, -0.799987793f, 0.761169434f }, { 2047, 0.411743164f, 0.514144361f },
+                        { 3000, -0.799987793f, 0.596221924f }, { 4095, -0.157653809f, 0.334106445f } });
+    shape (stC, false, { { 100, 0.317797363f, 0.0483714938f }, { 1000, -0.445489585f, -0.533142388f }, { 2047, 0.634525597f, 0.942175806f },
+                         { 3000, -0.445489585f, 0.514707327f }, { 4095, 0.200391173f, -0.937523127f } });
+    shape (stC, true, { { 100, 0.61165309f, -0.0993360579f }, { 1000, 0.0375693105f, 0.667849183f }, { 2047, 0.353716731f, -0.223758236f },
+                        { 3000, 0.0375693105f, -0.223787636f }, { 4095, 0.843308687f, 0.688474894f } });
+
+    // the mixer effect from the FL import: controls as parameters, the curve in the slot's state; host blocks of any size
+    const auto slot = lynx::effectFromFl ("Fruity WaveShaper", stC, 120.0);
+    CHECK (slot && slot->kind == lynx::EffectKind::fruityWaveShaper && slot->state == stC);
+    if (slot)
+    {
+        auto fx = lynx::makeEffect (*slot);
+        fx->prepare (44100.0);
+        std::vector<float> l (inL), r (inR);
+        fx->process (l.data(), r.data(), 1024, slot->params, 120.0);
+        fx->process (l.data() + 1024, r.data() + 1024, 1024, slot->params, 120.0);
+        fx->process (l.data() + 2048, r.data() + 2048, 2048, slot->params, 120.0);
+        CHECK (close (l[1000], -0.445489585f) && close (r[2047], 0.942175806f) && close (l[4095], 0.200391173f));
+        CHECK (lynx::formatEffectParam (lynx::EffectKind::fruityWaveShaper, 3, slot->params[3], 120.0) == "x4");
+    }
+    // an unreadable state keeps the old approximation
+    CHECK (lynx::effectFromFl ("Fruity WaveShaper", { 1, 2, 3 }, 120.0)->kind == lynx::EffectKind::distortion);
+    CHECK (lynx::effectFromFl ("Fruity Soft Clipper", { 1, 2, 3 }, 120.0)->kind == lynx::EffectKind::distortion);
+}
+
 // ---- Sytrus (REA_rodada31) -------------------------------------------------------------------------------------------
 // A Sytrus state built from scratch (version 25 layout, our own values — no FL preset data), zlib "stored" blocks.
 namespace