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

Kilohearts Nonlinear Filter: a hidden law on Effector with LYNX's own half-band (round 190oc)

- kHs Nonlinear Filter now opens on FL's Effector (Type: Filter) with a hidden Kilohearts law, code 49 / 64 (the code
  round 190nh kept for it): DirtyFilterDsp read in HeartCore 2.4.6 and restated as formulas - a Chamberlin
  state-variable filter at 8x (g from g + g^3/24 = w, k = (1 - e^(g/Q)) / g), the nine modes (clean, saturated, tubular,
  clipped, warm, biased, fuzzy, metallic, digital) with their drive and gain laws, five types, coefficient ramps across a
  block; up 2x through a half-band, 4x by Catmull-Rom, down through a 6th-order Chebyshev II (85 dB from 1.5 fs) and the
  half-band, then a 17 Hz high pass. A slot saved with the earlier Filter stand-in keeps it.
- The plug-in's half-band is a fixed table and is not used: LYNX designs its own at first use (the elliptic
  Valenzuela-Constantinides formulas, its own spec: 8 coefficients, transition band 0.054, 109 dB), chosen black-box on
  the references.
- Round 190nb's 56 references: 4.62 -> 9.43 (bypass 2.18), 55 up / 1 same / 0 down; gold 192 / 192 renders identical
  (every older law and stand-in); about 4 % of a core per instance (the plug-in's own 8x design).
- Tests: tests/Parity190ocKhsTests.inc (translation, the half-band's response, the five types, the nine modes bounded and
  deterministic). Docs: docs/analise/REA_rodada190oc.md, PLUGIN_FALLBACK.md.
Ka1-S 1 неделя назад
Родитель
Сommit
06bbe37fe9

+ 2 - 1
docs/PLUGIN_FALLBACK.md

@@ -184,7 +184,7 @@ matches by name).
 | kHs Gain, Channel Mixer, Stereo | Utility (round 190ln) | names | gain (stored linear); the 2 × 2 matrix; width / mid as the M/S matrix, pan as balance [DATA] |
 | kHs Haas | Stereo Shaper (round 190ln) | name | delayed channel, delay [DATA] |
 | kHs Filter, 3-Band EQ, Formant Filter | Facet EQ (round 190ln) | names | type, cutoff, Q, gain, slope (×n = 12n dB/oct); split shelves around the mid gain; Formant Filter (round 190nb): two cookbook biquads — peaks of 20·log10 Q dB at both cutoffs, or a high / low pass when Lows / Highs are off [STATIC] |
-| kHs Ladder Filter, Nonlinear Filter | Filter (round 190ln) | names | type, cutoff, resonance / Q (ladder: 24 dB/oct) [DATA] |
+| kHs Ladder Filter | Filter (round 190ln) | names | type, cutoff, resonance (24 dB/oct) [DATA] |
 | kHs Compressor, Compactor, Dynamics | Compressor (round 190ln) | names | threshold, ratio, attack, release, make-up (Dynamics: the downward part) [DATA] |
 | kHs Limiter, Clipper, Gate | Limiter / Fruity Soft Clipper / Sentry Gate (round 190ln) | names | input / output gains folded into gain and ceiling; threshold, knee-less clip; gate threshold, times, range, look-ahead [DATA] |
 | kHs Transient Shaper | Strike Shaper (round 190ln) | name | attack (±100 % → ±12 dB), clip [DATA]; round 190nb: sustain = a steady-state gain of 17.93 dB × sustain [MEASURED], on Strike's Output (−20 … +6 dB) |
@@ -196,6 +196,7 @@ matches by name).
 | kHs Ring Mod, Reverser, Resonator, Phase Distortion, Shaper | Effector with a hidden Kilohearts law (round 190nb; bypass before) | names | Ring Mod: frequency, spread, bias, rectify, mix; Reverser: time or steps × note (song-locked), crossfade, mix; Resonator: pitch, decay, intensity, timbre, mix; Phase Distortion: drive, spread, normalize, tone, bias, mix; Shaper: drive, loop mode, DC filter, the curve's points, mix [STATIC + MEASURED] (REA_rodada190nb) |
 | kHs Tape Stop | Pocket Tape Stop (round 190ln) | name | play, times [DATA] |
 | kHs Comb Filter, Chorus, Trance Gate, Phaser, Distortion, Bitcrush, Frequency Shifter, Ensemble | Effector with a hidden Kilohearts law (round 190nh; Pocket Comb Filter / Chorus / Volume gate / Fruity Phaser / Distortion / Lo-fi / Frequency shifter before) | names | Comb Filter: cutoff, polarity, stereo, mix (16-tap windowed-sinc read, 7 samples of latency); Chorus: delay, rate, depth, spread, two / three taps, mix (float LFO, HeartCore's sleep on silence); Trance Gate: the selected pattern's steps and ties, resolution, swing, attack / decay / sustain / release, depth, song-locked; Phaser: order, cutoff, depth, rate, spread, mix (block-rate triangle LFO, SVF all-passes); Distortion: drive, bias, spread, type (six shapes, ADAA), dynamics, DC filter, mix (Chebyshev II oversampler); Bitcrush: rate, bits, ADC / DAC quality, dither (its seeded generator), quantize, mix; Frequency Shifter: shift (LYNX's own 90° pair); Ensemble: voices, detune, spread, motion, mix (LYNX's own voice motion) [STATIC + MEASURED] (REA_rodada190nh) |
+| kHs Nonlinear Filter | Effector with a hidden Kilohearts law (round 190oc; Filter before, a slot saved with it keeps it) | names | type (low / band / high pass, notch, all-pass), mode (the nine: clean … digital), cutoff, Q, drive, mix: a saturating Chamberlin state-variable filter at 8× (2× through LYNX's own half-band, 4× Catmull-Rom, Chebyshev II down) [STATIC + MEASURED] (REA_rodada190oc) |
 | Soundtoys Decapitator, FabFilter Saturn | Ember Saturator (drive +1.4 dB, auto gain; round 113) | VST2 ID `StDc`, names | Saturn 2: multiband mode — bands, crossovers, style family, drive, mix, level (round 108) [EXEC layout]; Decapitator: her states (round 135, read black-box in the official trial: payload hash → voicing, drive, punish, tone, wide cuts, thump / steep, mix, trim) |
 | Soundtoys PanMan | Auto-pan, panner sources (round 135: a 3.56 Hz soft LFO, 150° wide, analog — her usual setting) | VST2 ID [DATA], name | her states (round 135, read black-box in the official trial: source, rate, steps, width, smoothing, gains, analog) |
 

+ 104 - 0
docs/analise/REA_rodada190oc.md

@@ -0,0 +1,104 @@
+# REA round 190oc — the Kilohearts Nonlinear Filter (0.1.31)
+
+Lab, captures and logs: `/mnt/e/lynx-work/helix4_khs3_190oc/` (HANDOFF.md). Branch `helix4_khs3_190oc` off
+origin/wip/rollup031. Evidence classes as in rounds 190nb / 190nh: [STATIC] read in Kilohearts' HeartCore 2.4.6
+(`HeartCore.core_64`, Kilohearts' own build of 2026-11-19; Ghidra headless, no execution), [MEASURED] black-box against
+round 190nb's 56 lossless kHs Nonlinear Filter references, [DATA] the snapin's own saved state. Clean-room: LYNX's code
+restates the law as formulas; the plug-in's half-band coefficients are a fixed table that LYNX does not use — LYNX designs
+its own half-band (§3). No Kilohearts code, table or preset is copied.
+
+## 1. Hosting
+
+A hidden law of FL's Effector, as rounds 190nb / 190nh's (core/KiloheartsDsp.h): [12] = 49 / 64 (the code round 190nh kept
+for it; `Law::nonlinearFilter`), [13] type / 4, [14] mode / 8, [15] cutoff on a log scale 20 … 20 480 Hz, [16] Q on a log
+scale 0.5 … 24, [17] drive 0 … 1; the mix is Effector's Wet. The translator opens the snapin on Effector (Type: Filter);
+a slot saved with the earlier Filter stand-in keeps it. Every project saved before has no law 49: unchanged (gold, §5).
+[DATA] The state keeps `filter_type` (low_pass, band_pass, high_pass, notch, all_pass), `dirt_type` (clean, saturated,
+tubular, clipped, warm, biased, fuzzy, metallic, digital: the order of the plug-in's own name table, which is the order
+of its mode switch), `cutoff` (Hz), `q`, `drive`; the defaults (no key saved) are low pass, saturated, 440 Hz, 0.707, 0.25.
+
+## 2. DirtyFilterDsp [STATIC]
+
+Vtable 0x18158e128: prepare (slot 7, 0x1802fd690), process (slot 14, 0x1802fd750), reset (slot 15, 0x1802fd5d0), the
+designer 0x1802feba0 (slot 13 only feeds the scope: (L + R) / 2 into a ring).
+
+- **Prepare:** the snapins' Chebyshev II designer (0x180bacef0, round 190nh's) for 3 sections (6th order) at 8 fs, stop band
+  from 1.5 fs, 85 dB; the cookbook biquad designer (0x180bac490, type 2: high pass) at 17 Hz, Q 1/√2, at fs.
+- **Process, per block:** up 2× through a polyphase IIR half-band (two branches of first-order all-passes, run on the
+  zero-stuffed input, ×2 in / ×½ out: H (z) = ½ (A0 (z²) + z^-1 A1 (z²))) — its seven coefficients are a fixed table;
+  then, per 2× sample, four samples at 8 fs by Catmull-Rom between the second and third of the last four 2× samples
+  (t = ¼, ½, ¾, 1; the weights are the Catmull-Rom polynomials' values); per 8× sample the filter (below, in double),
+  the output through the three Chebyshev II sections (double, each section's output rounded to float), every 4th kept
+  (the one at t = 1); down 2× through the same half-band; the 17 Hz high pass. The designer's seven values ramp linearly
+  across the block (step (new − now) / 8n at each 8× sample) and jump when the mode changes (a reset sets mode 9, so the
+  first block jumps).
+- **The filter:** a Chamberlin state-variable filter: hp = x − lp + k · bp (k = (1 − e^(g / Q)) / g), bp += g · hp,
+  lp += g · bp, where g solves g + g³ / 24 = ω (the plug-in writes the cubic's root by Cardano: two cube roots and a
+  square root; ω = 2π · scale · cutoff / 8 fs; g ≈ 2 sin (ω / 2)). Output y = cIn · x + cLp · lp[n−1] + cBp · bp[n−1] +
+  cHp · hp[n] (summed in float). Types: low pass (cLp 1), band pass (cBp 1), high pass (cHp 1), notch (lp + hp; in the
+  fuzzy and digital modes x − bp / Q), all-pass (lp + hp − bp / Q; digital: − 2 bp / Q).
+- **The modes** (drive d = 10^(dB / 20), dB = lo + Drive · (hi − lo); the designer's constants are exp2 of multiples of
+  log2 10, i.e. dB laws):
+
+| mode | the nonlinearity | lo … hi dB | the designer's extras |
+|---|---|---|---|
+| 0 clean | none | 0 … 0 | — |
+| 1 saturated | the low pass fed back as f (d · lp) / d, f (a) = a + a³/3 + a⁵/5 (|a| ≤ 1; beyond, 3a ∓ 22/15) | −12 … +24 | cutoff × 0.66^(D²), low pass × 10^(0.35 D²) |
+| 2 tubular | (lp, bp) scaled back onto d · |(lp, bp)| ≤ 1 after each step | −12 … +16 | — |
+| 3 clipped | bp and lp clipped to ±d | +3 … −16 | — |
+| 4 warm | x − lp through (v − 0.9 tanh v) / d, v = d (x − lp) (tanh: its [7/6] Padé fraction, |v| ≤ 4.373) | +24 … 0 | cutoff × 1.5^(D²), band pass × 10^(D/2), high pass × 10^(0.75 D + 0.1) |
+| 5 biased | the low pass fed back as (1 − h (−d · lp)) / d, h = exp on |a| ≤ 1, e · a above, (a + 2) / e below | −16 … +24 | — |
+| 6 fuzzy | bp clipped to ±1 / d | 0 … +36 | band pass × 10^(D²) |
+| 7 metallic | x − lp through (0.75 sin v + 0.25 v) / d | −12 … +24 | cutoff × 1.2^(D²), band pass × 10^(D²/4), high pass × 10^(0.35 D⁴) |
+| 8 digital | x − lp through ⌊v⌋ + ½ averaged over v ± 0.05 (a box-filtered staircase: its antiderivative's difference × 10) | +24 … 0 | — |
+
+The math library calls were identified by their use: exp2 (the log2 10 multiples), cbrt (Cardano), exp, sin, floor.
+
+## 3. LYNX's own half-band
+
+The plug-in's seven all-pass coefficients equal, to 1e-7, the elliptic (Valenzuela–Constantinides) half-band design with
+seven coefficients at a transition band of 0.05 of the 2× rate [STATIC + lab/halfband.py]. LYNX does not use that
+table: it designs its own at first use (`Engine::nlfHalfBand`, the textbook formulas — selectivity from the transition
+band, the nome, its theta series) with LYNX's own specification, **eight coefficients at a transition band of 0.054**
+(17th order, 109 dB stop band from 0.277 of the 2× rate, flat to 0.223) — a different filter with different
+coefficients. The specification was chosen black-box on the references (lab/nlfscore.py, lab/hbfit.py): the plug-in's
+chain, measured against LYNX's on the high-pass render, is 0.92 samples later at low frequencies and 1.11 at 20 kHz;
+eight coefficients at 0.054 with the decimator keeping H's odd outputs puts LYNX's low-frequency delay within a
+hundredth of a sample of the plug-in's (low-pass renders null at −73 … −108 dB), while the phase near 20 kHz still
+differs (the high-pass / notch / all-pass renders at −16 … −23 dB: §4). The candidates tried: 6 or 8 coefficients at
+0.03 … 0.08, both branch orders, both decimator phases (7 coefficients avoided: their best spec would be the
+plug-in's own table).
+
+## 4. Scores (fxparity time window, round 190nb's references and song positions, the same harness)
+
+Before = the Filter stand-in (round 190ln's map, origin/wip/rollup031), after = the law through fxrender; bypass = round
+190nh's column.
+
+| plug-in | files | bypass | before | after | up / same / down |
+|---|---|---|---|---|---|
+| kHs Nonlinear Filter | 56 | 2.18 | 4.62 | 9.43 | 55 / 1 / 0 |
+
+Per file (runs/after2_nlf.txt): 41 files at 10 (ESR −71 … −108 dB: every low-pass render, every mode the references
+hold — clean, saturated, tubular, warm, fuzzy — Q 0.5 … 24, drive 0 … 1, cutoff 20 … 640 Hz, and the default on the
+stimulus, drums, vocal, mix), 1 at 9 (warm, −55 dB), 11 at 8 (band pass −42 / −45 dB, digital −46 / −54, cutoff 3.6 kHz
+−45 / −47, 20.5 kHz −23 / −26, the high-pass / notch / all-pass level sweeps −21 … −23), 3 at 7 (the high-pass, notch
+and all-pass sine sweeps, −16 … −18 dB: the half-band's phase near Nyquist, §3). The one file the same: the high-pass
+sine sweep stays 7 (the stand-in's spectrum matched there already).
+
+## 5. Gates
+
+- Gold (gold/khsgold.sh, fxr_base vs the round's fxrender): 192 renders, 0 differ — round 190nh's 168 (Facet via Pro-Q,
+  22 stand-in defaults, Effector's 12 types × 2 settings, round 190nb's five laws) plus round 190nh's eight laws through
+  their translator, at 44.1 / 48 / 96 kHz.
+- CPU (cpu/khsbench.log, cpu/khsbench_cg.log): 1.41 s for 35 s stereo at 48 kHz on one pinned core (the Filter stand-in
+  0.22 s; the 190nh Distortion law 1.40 s in the same run) — about 4 % of a core per instance, the plug-in's own 8×
+  design; exact instructions per stereo sample by mode 3 160 (clean) … 4 660 (biased).
+
+## 6. Not done
+
+- The plug-in's sleep on silence (HeartCore's) is not modelled: the filter runs on through silence (its tail decays to
+  zero; no reference shows a difference).
+- The high-pass / notch / all-pass renders keep the half-band's phase difference near Nyquist (−16 … −23 dB): a closer
+  match would mean fitting the half-band to the plug-in's phase, i.e. rebuilding its table — not done (clean-room).
+- No reference exercises the clipped, biased and metallic modes, the mix, or automation (the ramps): those follow the
+  static read only.

+ 341 - 0
src/core/KiloheartsDsp.h

@@ -93,6 +93,10 @@ constexpr double driveLo = 0.25, driveHi = 16.0;
 constexpr double crushLo = 100.0, crushHi = 50000.0;
 // Frequency Shifter: [13] shift (v − ½) · 10 kHz (±5 kHz)
 // Ensemble: [13] voices / 16, [14] detune, [15] spread, [16] motion / 2 (random, symmetric, sine); the mix is Wet
+// round 190oc — Nonlinear Filter: [13] type / 4 (low, band, high pass, notch, all-pass), [14] mode / 8 (clean, saturated,
+// tubular, clipped, warm, biased, fuzzy, metallic, digital: the plug-in's order), [15] cutoff logv 20 … 20 480 Hz,
+// [16] Q logv 0.5 … 24, [17] drive; the mix is Wet
+constexpr double nlfCutLo = 20.0, nlfCutHi = 20480.0, nlfQLo = 0.5, nlfQHi = 24.0;
 inline double gateStepsPerBeat (float v) noexcept
 {
     static constexpr double steps[7] { 2.0, 3.0, 4.0, 6.0, 8.0, 12.0, 16.0 };
@@ -200,8 +204,12 @@ public:
         ensPos = 0.0;
         for (auto& v : ensAp)
             v = {};
+        nlfReset();
     }
     void setSongBeats (double b) noexcept { songBeats = b; songKnown = true; }
+    // round 190oc: LYNX's own half-band (the Nonlinear Filter's 2× resampler): its all-pass coefficients, A0's at the even
+    // places, A1's at the odd ones (tests, docs)
+    static std::vector<double> nonlinearHalfBand() { const auto& a = nlfHalfBand().a; return { a.begin(), a.end() }; }
     // round 190nh: the Trance Gate follows a song position only when it moves (a stopped transport: free running)
 
     void process (Law law, float* l, float* r, int n, const float* p, float mix, double bpm) noexcept
@@ -221,6 +229,7 @@ public:
             case Law::bitcrush: bitcrush (l, r, n, p, mix); break;
             case Law::freqShift: freqShift (l, r, n, p, mix); break;
             case Law::ensemble: ensemble (l, r, n, p, mix); break;
+            case Law::nonlinearFilter: nonlinearFilter (l, r, n, p, mix); break;
             default: break;
         }
     }
@@ -1355,5 +1364,337 @@ private:
             r[i] = (float) ((1.0 - mix) * line[1].back (b) + sr);
         }
     }
+    // ---- Nonlinear Filter (round 190oc) ------------------------------------------------------------------------
+    // DirtyFilterDsp read in HeartCore 2.4 (REA_rodada190oc): a state-variable filter of the Chamberlin form at eight
+    // times the rate, hp = x − lp + k · bp, bp += g · hp, lp += g · bp (k = (1 − e^(g / Q)) / g; g solves g + g³ / 24 = ω,
+    // ω = 2π · cutoff · scale / 8 fs: the first two terms of 2 asin (g / 2)); the mode bends it with drive d = 10^(dB / 20),
+    // dB = lo + Drive · (hi − lo) per mode:
+    //   0 clean: linear (0 dB);
+    //   1 saturated: the low pass fed back through f (d · lp) / d, f (a) = a + a³ / 3 + a⁵ / 5 (|a| ≤ 1, then 3a ∓ 22/15),
+    //     −12 … +24 dB, cutoff × 0.66^(D²), the low-pass output × 10^(0.35 D²);
+    //   2 tubular: both states scaled back onto the circle d · |(lp, bp)| ≤ 1, −12 … +16 dB;
+    //   3 clipped: both states clipped to ±d, +3 … −16 dB;
+    //   4 warm: x − lp through e (v) / d, e (v) = v − 0.9 tanh v (tanh as its [7/6] Padé fraction, |v| ≤ 4.373), v = d (x − lp),
+    //     +24 … 0 dB, cutoff × 1.5^(D²), band pass × 10^(D / 2), high pass × 10^(0.75 D + 0.1);
+    //   5 biased: the low pass fed back as (1 − h (−d · lp)) / d, h = exp on |a| ≤ 1, e · a above, (a + 2) / e below, −16 … +24 dB;
+    //   6 fuzzy: the band pass clipped to ±1 / d, 0 … +36 dB, band pass × 10^(D²);
+    //   7 metallic: x − lp through (0.75 sin v + 0.25 v) / d, −12 … +24 dB, cutoff × 1.2^(D²), band pass × 10^(D² / 4),
+    //     high pass × 10^(0.35 D⁴);
+    //   8 digital: x − lp through ⌊v⌋ + ½ averaged over v ± 0.05 (a box-filtered staircase), +24 … 0 dB.
+    // Out = cIn · x + cLp · lp[n−1] + cBp · bp[n−1] + cHp · hp[n] by type (low / band / high pass, notch = low + high or, in
+    // the fuzzy and digital modes, x − bp / Q, all-pass = low + high − bp / Q (digital: − 2 bp / Q)); the coefficients ramp
+    // across a block and jump when the mode changes. Around it: up 2× through a half-band, up 4× by Catmull-Rom between
+    // the 2× samples, down through a 6th-order Chebyshev II low pass (85 dB from 1.5 fs, the snapins' textbook design, as
+    // round 190nh's oversampler) keeping every 4th sample, down 2× through the half-band, then a cookbook 17 Hz high pass
+    // (Q 1/√2). The plug-in's half-band is a fixed coefficient table: LYNX designs its own (nlfHalfBand below).
+    //
+    // LYNX's own half-band: a two-branch polyphase IIR half-band, H (z) = ½ (A0 (z²) + z^-1 A1 (z²)), each branch a cascade
+    // of first-order all-passes (a + z^-1) / (1 + a z^-1); its coefficients come from the elliptic design of Valenzuela and
+    // Constantinides (IEE Proc. G 130, 1983: selectivity from the transition band, the nome's theta series), worked out
+    // here at first use with LYNX's own specification: nlfHalfBandCoefs coefficients (alternately to A0 and A1) and a
+    // transition band of nlfHalfBandTbw of the 2× rate (chosen on the references: lab/halfband.py, REA_rodada190oc §3).
+    static constexpr int nlfHalfBandCoefs = 8;        // (17th order: 109 dB stop band)
+    static constexpr double nlfHalfBandTbw = 0.054;   // (of the 2× rate: pass band to 0.223 × 2 fs, stop band from 0.277)
+    struct NlfHalfBand
+    {
+        std::array<double, nlfHalfBandCoefs> a {};
+        NlfHalfBand() noexcept
+        {
+            const int n = nlfHalfBandCoefs, order = 2 * n + 1;
+            const double k = std::pow (std::tan ((1.0 - 2.0 * nlfHalfBandTbw) * pi / 4.0), 2.0); // the selectivity
+            const double kp = std::pow (1.0 - k * k, 0.25);
+            const double e = 0.5 * (1.0 - kp) / (1.0 + kp);
+            const double q = e + 2.0 * std::pow (e, 5.0) + 15.0 * std::pow (e, 9.0) + 150.0 * std::pow (e, 13.0); // the nome
+            for (int i = 1; i <= n; ++i)
+            {
+                double num = 0.0, den = 0.0;
+                for (int m = 0; m < 12; ++m)
+                    num += (m % 2 == 0 ? 1.0 : -1.0) * std::pow (q, (double) (m * (m + 1))) * std::sin ((2 * m + 1) * i * pi / order);
+                for (int m = 1; m < 12; ++m)
+                    den += (m % 2 == 0 ? 1.0 : -1.0) * std::pow (q, (double) (m * m)) * std::cos (2.0 * m * i * pi / order);
+                const double w = 2.0 * std::pow (q, 0.25) * num / (1.0 + 2.0 * den), w2 = w * w;
+                const double x = std::sqrt ((1.0 - w2 * k) * (1.0 - w2 / k)) / (1.0 + w2);
+                a[(std::size_t) (i - 1)] = (1.0 - x) / (1.0 + x);
+            }
+        }
+    };
+    static const NlfHalfBand& nlfHalfBand() noexcept
+    {
+        static const NlfHalfBand h;
+        return h;
+    }
+    // one branch's all-pass chain (state x[n−1], y[n−1] per section), at the low rate
+    struct NlfBranch
+    {
+        std::array<double, nlfHalfBandCoefs> x1 {}, y1 {};
+        double run (const double* a, int first, double v) noexcept
+        {
+            for (int s = first, j = 0; s < nlfHalfBandCoefs; s += 2, ++j)
+            {
+                const double y = a[s] * (v - y1[(std::size_t) j]) + x1[(std::size_t) j];
+                x1[(std::size_t) j] = v;
+                y1[(std::size_t) j] = y;
+                v = y;
+            }
+            return v;
+        }
+    };
+    struct NlfChannel
+    {
+        NlfBranch up0, up1, dn0, dn1;
+        std::array<float, 4> hist {};        // the last four 2× samples (oldest first)
+        double lp = 0.0, bp = 0.0;           // the filter's states
+        double c1[3] {}, c2[3] {}, d1[3] {}, d2[3] {}; // the Chebyshev II sections (x and y history)
+        double dc[4] {};                     // the 17 Hz high pass (x1, x2, y1, y2)
+    };
+    std::array<NlfChannel, 2> nlfCh {};
+    struct NlfCoefs
+    {
+        double g = 0.0, k = 0.0, drive = 1.0, cLp = 0.0, cBp = 0.0, cHp = 0.0, cIn = 0.0;
+    };
+    NlfCoefs nlfNow {};
+    int nlfMode = -1;                        // (−1: nothing played yet — the first block takes its values at once)
+    double nlfForRate = 0.0;
+    double nlfB0[3] {}, nlfB1[3] {}, nlfA1[3] {}, nlfA2[3] {}; // (b2 = b0)
+    double nlfDc[5] {};
+    static NlfCoefs nlfDesign (int type, int mode, double cutoff, double q, double drive, double rate8) noexcept
+    {
+        NlfCoefs c;
+        double bp = 1.0;          // the band pass's coefficient the modes scale
+        bool lpOn = false, hpOn = false;
+        switch (type)
+        {
+            case 1: c.cBp = 1.0; break;
+            case 2: c.cHp = 1.0, hpOn = true, bp = 0.0; break;
+            case 3:
+                if (mode == 6 || mode == 8)
+                    c.cBp = bp = -1.0 / q, c.cIn = 1.0;
+                else
+                    c.cLp = c.cHp = 1.0, lpOn = hpOn = true, bp = 0.0;
+                break;
+            case 4:
+                c.cLp = c.cHp = 1.0, lpOn = hpOn = true;
+                c.cBp = bp = (mode == 8 ? -2.0 : -1.0) / q;
+                break;
+            default: c.cLp = 1.0, lpOn = true, bp = 0.0; break;
+        }
+        const double D = std::clamp (drive, 0.0, 1.0), D2 = D * D;
+        const auto db = [] (double v) { return std::pow (10.0, v / 20.0); };
+        double scale = 1.0, lo = 0.0, hi = 0.0;
+        switch (mode)
+        {
+            case 1: scale = std::pow (0.66, D2), lo = -12.0, hi = 24.0; if (lpOn) c.cLp = db (7.0 * D2); break;
+            case 2: lo = -12.0, hi = 16.0; break;
+            case 3: lo = 3.0, hi = -16.0; break;
+            case 4:
+                scale = std::pow (1.5, D2), lo = 24.0, hi = 0.0;
+                if (type != 2 && bp != 0.0) c.cBp = bp * db (10.0 * D);
+                if (hpOn) c.cHp = db (15.0 * D + 2.0);
+                break;
+            case 5: lo = -16.0, hi = 24.0; break;
+            case 6: lo = 0.0, hi = 36.0; if (bp != 0.0) c.cBp = bp * db (20.0 * D2); break;
+            case 7:
+                scale = std::pow (1.2, D2), lo = -12.0, hi = 24.0;
+                if (bp != 0.0) c.cBp = bp * db (5.0 * D2);
+                if (hpOn) c.cHp = db (7.0 * D2 * D2);
+                break;
+            case 8: lo = 24.0, hi = 0.0; break;
+            default: break;
+        }
+        c.drive = db (lo + D * (hi - lo));
+        const double w = scale * twoPi * cutoff / rate8;
+        // g + g³ / 24 = ω (Cardano: the one real root)
+        const double s = std::sqrt (144.0 * w * w + 512.0);
+        c.g = std::cbrt (12.0 * w + s) + std::cbrt (12.0 * w - s);
+        c.k = (1.0 - std::exp (c.g / q)) / c.g;
+        return c;
+    }
+    // the Catmull-Rom weights of the four 2× samples at t = ¼, ½, ¾, 1 between the second and the third: ½ (−t + 2t² − t³),
+    // ½ (2 − 5t² + 3t³), ½ (t + 4t² − 3t³), ½ (t³ − t²) (exact in float: multiples of 1/128)
+    static constexpr std::array<std::array<float, 4>, 4> nlfCatmull = [] {
+        std::array<std::array<float, 4>, 4> w {};
+        for (int j = 0; j < 4; ++j)
+        {
+            const double t = 0.25 * (j + 1), t2 = t * t, t3 = t2 * t;
+            w[(std::size_t) j] = { (float) (0.5 * (-t + 2.0 * t2 - t3)), (float) (0.5 * (2.0 - 5.0 * t2 + 3.0 * t3)), (float) (0.5 * (t + 4.0 * t2 - 3.0 * t3)),
+                                   (float) (0.5 * (t3 - t2)) };
+        }
+        return w;
+    }();
+    static double nlfTanh (double v) noexcept // the [7/6] Padé fraction of tanh (Lambert's continued fraction), |v| ≤ 4.373
+    {
+        v = std::clamp (v, -4.373000144958496, 4.373000144958496);
+        const double v2 = v * v;
+        return v * ((21.0 * v2 + 1260.0) * v2 + 10395.0) / (((v2 + 210.0) * v2 + 4725.0) * v2 + 10395.0);
+    }
+    static double nlfFloorInt (double u) noexcept // ∫₀ᵘ ⌊s⌋ ds
+    {
+        const double f = std::floor (u);
+        return 0.5 * f * (2.0 * u - f - 1.0);
+    }
+    // one step of the filter at 8 fs: x in, the output by type
+    static float nlfStep (NlfChannel& ch, double x, int mode, const NlfCoefs& c) noexcept
+    {
+        const double lp = ch.lp, bp = ch.bp, g = c.g, d = c.drive;
+        double hp;
+        switch (mode)
+        {
+            case 1:
+            {
+                const double a = d * lp;
+                const double f = a < -1.0 ? 3.0 * a + 22.0 / 15.0 : a > 1.0 ? 3.0 * a - 22.0 / 15.0 : a + a * a * a * (a * a / 5.0 + 1.0 / 3.0);
+                hp = c.k * bp + (x - f / d);
+                break;
+            }
+            case 4: { const double v = d * (x - lp); hp = c.k * bp + (v - 0.9 * nlfTanh (v)) / d; break; }
+            case 5:
+            {
+                const double a = -d * lp;
+                const double h = a < -1.0 ? (a + 2.0) / 2.718281828459045 : a > 1.0 ? 2.718281828459045 * a : std::exp (a);
+                hp = c.k * bp + x + (h - 1.0) / d;
+                break;
+            }
+            case 7: { const double v = d * (x - lp); hp = c.k * bp + (0.75 * std::sin (v) + 0.25 * v) / d; break; }
+            case 8:
+            {
+                const double v = d * (x - lp);
+                hp = c.k * bp + (10.0 * (nlfFloorInt (v + 0.05) - nlfFloorInt (v - 0.05)) + 0.5) / d;
+                break;
+            }
+            default: hp = c.k * bp + (x - lp); break;
+        }
+        double nbp = bp + g * hp, nlp;
+        switch (mode)
+        {
+            case 2:
+            {
+                nlp = lp + g * nbp;
+                const double r = d * std::sqrt (nlp * nlp + nbp * nbp);
+                const double s = r < 1.0 ? 1.0 : 1.0 / r;
+                nbp *= s, nlp *= s;
+                break;
+            }
+            case 3:
+                nbp = std::clamp (nbp, -d, d);
+                nlp = std::clamp (lp + g * nbp, -d, d);
+                break;
+            case 6:
+                nbp = std::clamp (d * nbp, -1.0, 1.0) / d;
+                nlp = lp + g * nbp;
+                break;
+            default: nlp = lp + g * nbp; break;
+        }
+        ch.lp = nlp;
+        ch.bp = nbp;
+        return (float) c.cIn * (float) x + (float) (c.cLp * lp) + (float) (c.cBp * bp) + (float) c.cHp * (float) hp;
+    }
+    void nonlinearFilter (float* l, float* r, int n, const float* p, float mix) noexcept
+    {
+        if (n <= 0)
+            return;
+        const int type = std::clamp ((int) std::lround (4.0 * p[valueParam]), 0, 4);
+        const int mode = std::clamp ((int) std::lround (8.0 * p[valueParam + 1]), 0, 8);
+        const double rate8 = 8.0 * fs;
+        const auto target = nlfDesign (type, mode, enc::logv (p[valueParam + 2], enc::nlfCutLo, enc::nlfCutHi),
+                                       enc::logv (p[valueParam + 3], enc::nlfQLo, enc::nlfQHi), p[valueParam + 4], rate8);
+        if (nlfForRate != fs)
+        {
+            nlfForRate = fs;
+            // the decimator: a 6th-order Chebyshev II low pass at 8 fs, 85 dB from 1.5 fs (textbook, unity at DC)
+            constexpr int order = 6;
+            const double eps = 1.0 / std::sqrt (std::pow (10.0, 85.0 / 10.0) - 1.0);
+            const double mu = std::asinh (1.0 / eps) / order;
+            const double kk = 1.0 / std::tan (pi * 1.5 * fs / rate8);
+            for (int s = 0; s < 3; ++s)
+            {
+                const double th = pi * (2.0 * s + 1.0) / (2.0 * order);
+                const double sr = -std::sinh (mu) * std::sin (th), si = std::cosh (mu) * std::cos (th);
+                const double den = sr * sr + si * si;
+                const double pr = sr / den, pim = -si / den;
+                const double Z = 1.0 / (std::cos (th) * std::cos (th)), B = -2.0 * pr, C = pr * pr + pim * pim;
+                const double gg = C / Z, a0 = kk * kk + B * kk + C;
+                nlfB0[s] = gg * (kk * kk + Z) / a0;
+                nlfB1[s] = gg * 2.0 * (Z - kk * kk) / a0;
+                nlfA1[s] = 2.0 * (C - kk * kk) / a0;
+                nlfA2[s] = (kk * kk - B * kk + C) / a0;
+            }
+            // the output's DC filter: a cookbook high pass, 17 Hz, Q 1/√2
+            const double w0 = twoPi * std::min (17.0, 0.49 * fs) / fs, cs = std::cos (w0), al = std::sin (w0) / (2.0 * 0.7071067811865476);
+            const double a0 = 1.0 + al;
+            nlfDc[0] = (1.0 + cs) / 2.0 / a0, nlfDc[1] = -(1.0 + cs) / a0, nlfDc[2] = nlfDc[0];
+            nlfDc[3] = -2.0 * cs / a0, nlfDc[4] = (1.0 - al) / a0;
+        }
+        NlfCoefs step {};
+        if (mode != nlfMode)
+            nlfNow = target, nlfMode = mode;
+        else
+        {
+            const double inv = 1.0 / (8.0 * n);
+            step = { (target.g - nlfNow.g) * inv, (target.k - nlfNow.k) * inv, (target.drive - nlfNow.drive) * inv, (target.cLp - nlfNow.cLp) * inv,
+                     (target.cBp - nlfNow.cBp) * inv, (target.cHp - nlfNow.cHp) * inv, (target.cIn - nlfNow.cIn) * inv };
+        }
+        const bool ramp = mode == nlfMode && (step.g != 0.0 || step.k != 0.0 || step.drive != 0.0 || step.cLp != 0.0 || step.cBp != 0.0
+                                              || step.cHp != 0.0 || step.cIn != 0.0);
+        const double* a = nlfHalfBand().a.data();
+        float* io[2] { l, r };
+        for (int i = 0; i < n; ++i)
+        {
+            // the coefficients this sample's eight steps use (the same for both channels; held: all eight the same)
+            NlfCoefs ramped[8];
+            const NlfCoefs* cs = ramped;
+            if (ramp)
+                for (int j = 0; j < 8; ++j)
+                {
+                    nlfNow.g += step.g, nlfNow.k += step.k, nlfNow.drive += step.drive, nlfNow.cLp += step.cLp;
+                    nlfNow.cBp += step.cBp, nlfNow.cHp += step.cHp, nlfNow.cIn += step.cIn;
+                    ramped[j] = nlfNow;
+                }
+            const int stride = ramp ? 1 : 0;
+            if (! ramp)
+                cs = &nlfNow;
+            for (int c = 0; c < 2; ++c)
+            {
+                auto& ch = nlfCh[(std::size_t) c];
+                const float x = io[c][i];
+                // up 2×: the two branches give the even and the odd 2× sample
+                const double u[2] { ch.up0.run (a, 0, x), ch.up1.run (a, 1, x) };
+                double half[2];
+                for (int h = 0; h < 2; ++h)
+                {
+                    auto& hs = ch.hist;
+                    hs[0] = hs[1], hs[1] = hs[2], hs[2] = hs[3], hs[3] = (float) u[h];
+                    // up 4× (Catmull-Rom between hs[1] and hs[2] at ¼, ½, ¾, 1), the filter, the decimator's low pass
+                    double y = 0.0;
+                    for (int j = 0; j < 4; ++j)
+                    {
+                        const auto& wj = nlfCatmull[(std::size_t) j];
+                        const float xi = wj[0] * hs[0] + wj[1] * hs[1] + wj[2] * hs[2] + wj[3] * hs[3];
+                        double v = nlfStep (ch, xi, mode, cs[(4 * h + j) * stride]);
+                        for (int s = 0; s < 3; ++s)
+                        {
+                            const double out = nlfB0[s] * v + nlfB1[s] * ch.c1[s] + nlfB0[s] * ch.c2[s] - nlfA1[s] * ch.d1[s] - nlfA2[s] * ch.d2[s];
+                            ch.c2[s] = ch.c1[s], ch.c1[s] = v;
+                            ch.d2[s] = ch.d1[s], ch.d1[s] = out;
+                            v = (double) (float) out;
+                        }
+                        y = v;
+                    }
+                    half[h] = y;
+                }
+                // down 2×: the odd 2× sample through A0, the even one through A1 (H's odd outputs kept)
+                const double down = 0.5 * (ch.dn0.run (a, 0, half[1]) + ch.dn1.run (a, 1, half[0]));
+                auto& z = ch.dc;
+                const double o = nlfDc[0] * down + nlfDc[1] * z[0] + nlfDc[2] * z[1] - nlfDc[3] * z[2] - nlfDc[4] * z[3];
+                z[1] = z[0], z[0] = down, z[3] = z[2], z[2] = o;
+                io[c][i] = (float) (x + mix * ((float) o - x));
+            }
+        }
+    }
+    void nlfReset() noexcept
+    {
+        for (auto& ch : nlfCh)
+            ch = {};
+        nlfMode = -1;
+    }
 };
 } // namespace lynx::khsdsp

+ 22 - 1
src/core/KiloheartsStates.inc

@@ -844,7 +844,8 @@ int translateKilohearts (const std::vector<std::uint8_t>& state, EffectSlot& slo
     // names the nearest Effector algorithm, Wet is the snapin's mix, the law and its values sit in the hidden [12 …]
     if (kind == EffectKind::effector
         && (type == "ring_mod" || type == "reverser" || type == "resonator" || type == "phase_distortion" || type == "shaper"
-            || type == "comb_filter" || type == "chorus" || type == "trance_gate" || type == "phaser" || type == "distortion" || type == "bitcrush" || type == "frequency_shifter" || type == "unison"))
+            || type == "comb_filter" || type == "chorus" || type == "trance_gate" || type == "phaser" || type == "distortion" || type == "bitcrush" || type == "frequency_shifter" || type == "unison"
+            || type == "dirty_filter"))
     {
         namespace k = khsdsp;
         auto hidden = [&] (int index, double v) { slot.params[(std::size_t) index] = (float) std::clamp (v, 0.0, 1.0); ++n; };
@@ -961,6 +962,26 @@ int translateKilohearts (const std::vector<std::uint8_t>& state, EffectSlot& slo
             hidden (k::valueParam + 4, m.num ("dynamics", 0.0));
             hidden (k::valueParam + 5, m.flag ("dc_filter", true) ? 1.0 : 0.0);
         }
+        else if (type == "dirty_filter")
+        {
+            // round 190oc: DirtyFilterDsp read in HeartCore (REA_rodada190oc); the type and mode by their saved names
+            typeIs (4); // Filter
+            hidden (k::lawParam, k::lawValue (k::Law::nonlinearFilter));
+            static constexpr const char* types[5] { "low_pass", "band_pass", "high_pass", "notch", "all_pass" };
+            static constexpr const char* modes[9] { "clean", "saturated", "tubular", "clipped", "warm", "biased", "fuzzy", "metallic", "digital" };
+            int t = 0, d = 1;
+            for (int i = 0; i < 5; ++i)
+                if (m.str ("filter_type") == types[i])
+                    t = i;
+            for (int i = 0; i < 9; ++i)
+                if (m.str ("dirt_type") == modes[i])
+                    d = i;
+            hidden (k::valueParam, t / 4.0);
+            hidden (k::valueParam + 1, d / 8.0);
+            hidden (k::valueParam + 2, k::enc::logValue (m.num ("cutoff", 440.0), k::enc::nlfCutLo, k::enc::nlfCutHi));
+            hidden (k::valueParam + 3, k::enc::logValue (m.num ("q", 0.707), k::enc::nlfQLo, k::enc::nlfQHi));
+            hidden (k::valueParam + 4, m.num ("drive", 0.25));
+        }
         else if (type == "phaser")
         {
             typeIs (3); // Phaser

+ 1 - 1
src/core/PluginSubstitutes.cpp

@@ -1111,7 +1111,7 @@ translate = kilohearts
 [khs-nonlinear-filter]
 product = kHs Nonlinear Filter
 vendor = Kilohearts
-lynx = Filter
+lynx = Effector
 names = kHs Nonlinear Filter
 translate = kilohearts
 

+ 133 - 0
tests/Parity190ocKhsTests.inc

@@ -0,0 +1,133 @@
+// Round 190oc: the Kilohearts Nonlinear Filter as a hidden law of Effector (core/KiloheartsDsp.h, code 49 / 64):
+// DirtyFilterDsp read in HeartCore (docs/analise/REA_rodada190oc.md), LYNX's own half-band around it, translated from the
+// snapin's state (core/KiloheartsStates.inc). Uses parity190lnkhs::state / load / named, parity190nbkhs::run and
+// parity190nhkhs::tone / energy / finite.
+
+namespace parity190ockhs
+{
+inline std::string body (const char* type, const char* mode, double cutoff, double q, double drive)
+{
+    return std::string ("\"cutoff\": \"") + std::to_string (cutoff) + "\", \"filter_type\": \"" + type + "\", \"dirt_type\": \"" + mode
+           + "\", \"q\": \"" + std::to_string (q) + "\", \"drive\": \"" + std::to_string (drive) + "\", \"$type\": \"dirty_filter\"";
+}
+inline lynx::EffectSlot filter (const char* type, const char* mode = "clean", double cutoff = 1000.0, double q = 0.707, double drive = 0.25)
+{
+    int n = 0;
+    return parity190lnkhs::load ("kHs Nonlinear Filter", parity190lnkhs::state (body (type, mode, cutoff, q, drive)), n);
+}
+// the steady gain (dB) of a tone through the slot: the last half second's energy against the input's
+inline double gainDb (const lynx::EffectSlot& s, double hz, float amp = 0.25f)
+{
+    const auto x = parity190nhkhs::tone (48000, hz, amp);
+    const auto y = parity190nbkhs::run (s, x);
+    double ex = 0.0, ey = 0.0;
+    for (int i = 24000; i < 48000; ++i)
+        ex += (double) x[(std::size_t) i] * x[(std::size_t) i], ey += (double) y[(std::size_t) i] * y[(std::size_t) i];
+    return 10.0 * std::log10 (std::max (ey, 1e-30) / ex);
+}
+// the level (dB re the input's amplitude) of the partial at hz in the last half second (one-bin DFT, Hann)
+inline double partialDb (const std::vector<float>& y, double hz, float amp)
+{
+    std::complex<double> acc {};
+    double wsum = 0.0;
+    for (int i = 24000; i < 48000; ++i)
+    {
+        const auto wv = 0.5 - 0.5 * std::cos (2.0 * 3.14159265358979 * (i - 24000) / 24000.0);
+        acc += wv * (double) y[(std::size_t) i] * std::polar (1.0, -2.0 * 3.14159265358979 * hz * i / 48000.0);
+        wsum += wv;
+    }
+    return 20.0 * std::log10 (std::max (2.0 * std::abs (acc) / wsum / amp, 1e-12));
+}
+} // namespace parity190ockhs
+
+TEST (parity190ockhs_law_code_and_translation)
+{
+    using namespace lynx;
+    using namespace parity190ockhs;
+    namespace k = khsdsp;
+    // code 49 (kept for it by round 190nh); round 190nb's and 190nh's codes unchanged
+    CHECK (k::lawCode (k::Law::nonlinearFilter) == 49 && k::lawValue (k::Law::nonlinearFilter) == 49.0f / 64.0f);
+    CHECK (k::lawOf (49.0f / 64.0f) == k::Law::nonlinearFilter && k::lawOf (48.0f / 64.0f) == k::Law::ensemble && k::lawOf (50.0f / 64.0f) == k::Law::none);
+    const auto s = filter ("notch", "fuzzy", 3620.386, 9.11803, 0.75);
+    CHECK (s.kind == EffectKind::effector && k::lawOf (s.params[(std::size_t) k::lawParam]) == k::Law::nonlinearFilter);
+    CHECK (std::lround (4.0f * s.params[(std::size_t) k::valueParam]) == 3 && std::lround (8.0f * s.params[(std::size_t) k::valueParam + 1]) == 6);
+    CHECK (std::abs (k::enc::logv (s.params[(std::size_t) k::valueParam + 2], k::enc::nlfCutLo, k::enc::nlfCutHi) - 3620.386) < 0.01);
+    CHECK (std::abs (k::enc::logv (s.params[(std::size_t) k::valueParam + 3], k::enc::nlfQLo, k::enc::nlfQHi) - 9.11803) < 1e-4);
+    CHECK (std::abs (s.params[(std::size_t) k::valueParam + 4] - 0.75f) < 1e-6f);
+    CHECK (std::lround (11.0f * s.params[(std::size_t) parity190lnkhs::named (s, "Type")]) == 4); // Effector's Filter
+    // the plug-in's defaults (no keys): low pass, saturated, 440 Hz, Q 0.707, drive 0.25; no latency reported
+    int n = 0;
+    const auto d = parity190lnkhs::load ("kHs Nonlinear Filter", parity190lnkhs::state ("\"$type\": \"dirty_filter\""), n);
+    CHECK (std::lround (4.0f * d.params[(std::size_t) k::valueParam]) == 0 && std::lround (8.0f * d.params[(std::size_t) k::valueParam + 1]) == 1);
+    CHECK (std::abs (k::enc::logv (d.params[(std::size_t) k::valueParam + 2], k::enc::nlfCutLo, k::enc::nlfCutHi) - 440.0) < 0.01);
+    CHECK (makeEffect (d)->latencySamples() == 0);
+}
+
+TEST (parity190ockhs_half_band_is_lynx_own_design)
+{
+    // LYNX's own elliptic half-band: eight coefficients rising in (0, 1); 109 dB down from 0.277 of the 2× rate, flat to
+    // 0.223 (H (z) = ½ (A0 (z²) + z^-1 A1 (z²)), evaluated here)
+    const auto a = lynx::khsdsp::Engine::nonlinearHalfBand();
+    CHECK (a.size() == 8 && std::is_sorted (a.begin(), a.end()) && a.front() > 0.0 && a.back() < 1.0);
+    const auto H = [&a] (double f) {
+        const auto z = std::polar (1.0, 2.0 * 3.14159265358979 * f), z2 = z * z;
+        std::complex<double> b0 (1.0), b1 (1.0);
+        for (std::size_t i = 0; i < a.size(); ++i)
+            (i % 2 == 0 ? b0 : b1) *= (a[i] + 1.0 / z2) / (1.0 + a[i] / z2);
+        return std::abs (0.5 * (b0 + b1 / z));
+    };
+    double stop = 0.0, pass = 1.0;
+    for (int i = 0; i <= 2000; ++i)
+    {
+        stop = std::max (stop, H (0.277 + (0.5 - 0.277) * i / 2000.0));
+        pass = std::min (pass, H (0.223 * i / 2000.0));
+    }
+    CHECK (20.0 * std::log10 (stop) < -100.0 && 20.0 * std::log10 (pass) > -1e-6);
+}
+
+TEST (parity190ockhs_filter_types_shape_the_spectrum)
+{
+    using namespace parity190ockhs;
+    // clean (linear): the low pass passes 100 Hz and cuts 10 kHz (12 dB an octave above 1 kHz), the high pass the other way
+    const auto lp = filter ("low_pass"), hp = filter ("high_pass"), bp = filter ("band_pass"), notch = filter ("notch"), ap = filter ("all_pass");
+    CHECK (std::abs (gainDb (lp, 100.0)) < 0.3 && gainDb (lp, 10000.0) < -35.0);
+    CHECK (std::abs (gainDb (hp, 10000.0)) < 0.5 && gainDb (hp, 100.0) < -35.0);
+    CHECK (gainDb (bp, 1000.0) > gainDb (bp, 100.0) + 15.0 && gainDb (bp, 1000.0) > gainDb (bp, 10000.0) + 15.0);
+    CHECK (gainDb (notch, 1000.0) < -30.0 && std::abs (gainDb (notch, 100.0)) < 0.5);
+    for (double hz : { 100.0, 1000.0, 5000.0 })
+        CHECK (std::abs (gainDb (ap, hz)) < 0.5);
+    // linear: twice the input, twice the output
+    const auto x = parity190nhkhs::tone (24000, 300.0, 0.2f);
+    auto x2 = x;
+    for (auto& v : x2)
+        v *= 2.0f;
+    const auto y = parity190nbkhs::run (lp, x), y2 = parity190nbkhs::run (lp, x2);
+    double err = 0.0;
+    for (std::size_t i = 0; i < y.size(); ++i)
+        err = std::max (err, (double) std::fabs (y2[i] - 2.0f * y[i]));
+    CHECK (err < 1e-5);
+}
+
+TEST (parity190ockhs_modes_saturate_and_stay_bounded)
+{
+    using namespace parity190ockhs;
+    static const char* modes[9] { "clean", "saturated", "tubular", "clipped", "warm", "biased", "fuzzy", "metallic", "digital" };
+    static const char* types[5] { "low_pass", "band_pass", "high_pass", "notch", "all_pass" };
+    const auto x = parity190nhkhs::tone (48000, 200.0, 0.5f);
+    for (int m = 0; m < 9; ++m)
+        for (int t = 0; t < 5; ++t)
+            for (double drive : { 0.0, 1.0 })
+            {
+                const auto s = filter (types[t], modes[m], 800.0, 4.0, drive);
+                std::vector<float> r;
+                const auto y = parity190nbkhs::run (s, x, &r);
+                CHECK (parity190nhkhs::finite (y) && parity190nhkhs::finite (r));
+                CHECK (std::all_of (y.begin(), y.end(), [] (float v) { return std::fabs (v) < 8.0f; }));
+                CHECK (parity190nhkhs::energy (y) > 1e-3 * parity190nhkhs::energy (x) || t == 3);
+                CHECK (y == parity190nbkhs::run (s, x)); // (deterministic)
+            }
+    // the saturated mode at full drive bends a loud tone (its 3rd harmonic up), clean does not
+    const auto sat = parity190nbkhs::run (filter ("low_pass", "saturated", 4000.0, 0.707, 1.0), x);
+    const auto clean = parity190nbkhs::run (filter ("low_pass", "clean", 4000.0, 0.707, 1.0), x);
+    CHECK (partialDb (sat, 600.0, 0.5f) > -50.0 && partialDb (clean, 600.0, 0.5f) < -90.0);
+}

+ 1 - 0
tests/tests.cpp

@@ -17869,6 +17869,7 @@ TEST (fl_low_lifter_matches_fl_engine)
 #include "Parity190lnKhsTests.inc" // round 190ln: Kilohearts states (kHs snapins, Faturator, Disperser) on LYNX stand-ins
 #include "Parity190nbKhsTests.inc" // round 190nb: Kilohearts laws on Effector (Ring Mod, Reverser, Resonator, Phase Distortion, Shaper) + measured maps
 #include "Parity190nhKhsTests.inc" // round 190nh: Kilohearts part 2 (Comb Filter, Chorus, Trance Gate, Phaser, Distortion, Bitcrush, Frequency Shifter, Ensemble)
+#include "Parity190ocKhsTests.inc" // round 190oc: Kilohearts Nonlinear Filter
 #include "Parity190kwR2Tests.inc" // round 190kw: Pro-R 2 → LuxeVerb Space, the Space engine's revision 1 (recovered laws)
 #include "Parity190lpR2Tests.inc" // round 190lp: Pro-R 2 → LuxeVerb Space revision 1, the reference's fixed early taps (after Parity190kwR2: its helpers)
 #include "Parity190mgC4Tests.inc" // round 190mg: Prism's hidden C4 law (REA of the Waves C4), C4 on it