Browse Source

Pocket EQ, Graphic EQ and Filter: FL Studio Mobile's Equalizer, Graphic EQ and Filter as exact engines

FL Studio Mobile's modules 3, 7 and 9 rebuilt from FLM's laws (core/PocketFxE.cpp), with FLM's own 0..1 values:
- Pocket EQ: four cookbook-form bands at twice the rate on FLM's doubled amplitude law, held 2x path and FLM's
  four-lane band pipeline (1 sample late when flat), per-side coefficient sets for the Channel modes
- Pocket Graphic EQ: eight one-octave bands run as FLM's four pairs (8 samples late)
- Pocket Filter: 1/2/4 pairs of FLM's LP/BP/HP biquads, one sample per pair, the LP level 0.8^pairs
- FLM's silence gate (tail 10 s / 6 s, state cleared after it)

Against FL Studio Mobile inside FL, 17 settings: every set at the 16-bit floor (ESR -61...-85 dB, lag 0,
transfer-function error <= 0.05 dB). Tests in tests/PocketEq190dwTests.inc check each engine against an
independent double-precision model of the design and pipelines.
Ka1-S 3 weeks ago
parent
commit
ce77003cfd
2 changed files with 879 additions and 0 deletions
  1. 551 0
      src/core/PocketFxE.cpp
  2. 328 0
      tests/PocketEq190dwTests.inc

+ 551 - 0
src/core/PocketFxE.cpp

@@ -0,0 +1,551 @@
+#include "core/PocketFx.h"
+
+// Pocket EQ, Pocket Graphic EQ and Pocket Filter: FL Studio Mobile's Equalizer ("Param EQ", module 3), Graphic EQ
+// (module 7) and Filter (module 9), rebuilt in round 190dw from FLM's laws (the study notes are
+// /mnt/e/lynx-work/flm190dw/rea/spec-eqfilter.md; summary in docs/analise/FLM_FORMAT.md §7). Clean-room: the formulas
+// and the processing order restated in our own words, no Image-Line code or data.
+//
+// FLM runs these modules as small four-lane filter pipelines in single precision, and the pipelines are part of the
+// sound: a band hands its output to the next one a step later, so the Equalizer is 1.5 samples late, the Graphic EQ 8
+// and the Filter one sample per pair of biquads. FLM reports no latency for them and neither does LYNX (a .flm mix
+// was made with these delays in it). Every value below is computed in the precision FLM uses; contraction into FMAs
+// stays off so the results match the module's sample for sample.
+#if defined(__clang__)
+#pragma clang fp contract(off)
+#elif defined(__GNUC__)
+#pragma GCC optimize ("fp-contract=off")
+#endif
+
+#include <algorithm>
+#include <array>
+#include <cmath>
+#include <cstdio>
+
+namespace lynx::pocket
+{
+namespace
+{
+constexpr double tiny = 1.0e-30; // added to every input sample before the filters (keeps the feedback out of denormals)
+
+float flushSmall (float c) noexcept { return c < 1e-09f && c > -1e-09f ? 0.0f : c; }
+
+std::string format (const char* fmt, double v)
+{
+    char text[48];
+    std::snprintf (text, sizeof (text), fmt, v);
+    return text;
+}
+
+// FLM's module wrapper stops calling a module once its input has been silent for longer than the module's tail
+// (Equalizer and Graphic EQ 10 s, Filter 6 s), lets the buffer through untouched, and clears the module's state when
+// the input comes back. A freshly prepared module starts in the stopped state.
+struct SilenceGate
+{
+    long long count = 0, tail = 441000;
+    bool pendingReset = false;
+
+    void prepare (double fs, double seconds) noexcept
+    {
+        tail = (long long) (fs * seconds);
+        count = tail + 1;
+        pendingReset = false;
+    }
+    // true = run the module on this block; clear = the module's state must be cleared first
+    bool run (const float* l, const float* r, int n, bool& clear) noexcept
+    {
+        clear = pendingReset;
+        pendingReset = false;
+        bool active = false;
+        for (int i = 0; i < n && ! active; ++i)
+            active = l[i] != 0.0f || (r != nullptr && r[i] != 0.0f);
+        if (active)
+        {
+            count = 0;
+            return true;
+        }
+        if (count > tail)
+            return false;
+        count += n;
+        if (count <= tail)
+            return true;
+        pendingReset = true;
+        return false;
+    }
+};
+
+// ---------------------------------------------------------------------------------------------------------------
+// The band design FLM's Equalizer and Graphic EQ share: the cookbook's shelf / peak forms with the bandwidth in octaves,
+// but with the amplitude A = 10^(dB/20) where the cookbook has 10^(dB/40) (a band moves twice the dB its knob shows).
+// Coefficients are normalised by a0 and anything below 1e-9 in size becomes 0.
+struct Coefs
+{
+    float b0 = 1.0f, b1 = 0.0f, b2 = 0.0f, a1 = 0.0f, a2 = 0.0f;
+};
+
+Coefs designBand (int kind, float hz, float db, float octaves, float rate) noexcept
+{
+    const float A = std::pow (10.0f, db * 0.05f);
+    float w = (hz * 6.283185f) / rate;
+    if (w >= 3.0f)
+        w = 3.0f;
+    if (w <= 0.0f)
+        w = 0.0f;
+    const float s = std::sin (w);
+    const double sh = std::sinh (((double) octaves * (double) 0.3465736f * (double) w) / (double) s);
+    const float twoSh = (float) (sh + sh);
+    const float k = std::sqrt (A) * twoSh;
+    Coefs c;
+    float a0;
+    if (kind == 0) // low shelf
+    {
+        const float cs = std::cos (w);
+        const float twoRootAlpha = s * k;
+        const float am = A - 1.0f, ap = A + 1.0f;
+        const float m = ap - am * cs, p = am * cs + ap, apc = ap * cs;
+        a0 = twoRootAlpha + p;
+        c.b2 = (m - twoRootAlpha) * A;
+        c.b0 = (m + twoRootAlpha) * A;
+        c.a1 = am * -2.0f - (apc + apc);
+        c.b1 = (A + A) * (am - apc);
+        c.a2 = p - s * k;
+    }
+    else if (kind == 1) // peak
+    {
+        const float alpha = s * twoSh * 0.5f;
+        const float alphaA = alpha * A, alphaOverA = alpha / A;
+        a0 = alphaOverA + 1.0f;
+        c.b0 = alphaA + 1.0f;
+        const float cs = std::cos (w);
+        c.a1 = cs * -2.0f;
+        c.b1 = cs * -2.0f;
+        c.a2 = 1.0f - alphaOverA;
+        c.b2 = 1.0f - alphaA;
+    }
+    else // high shelf
+    {
+        const float cs = std::cos (w);
+        const float twoRootAlpha = s * k;
+        const float am = A - 1.0f, ap = A + 1.0f;
+        const float p = am * cs + ap, m = ap - am * cs;
+        a0 = m + twoRootAlpha;
+        c.b0 = (twoRootAlpha + p) * A;
+        const float q = am - ap * cs;
+        c.b2 = (p - twoRootAlpha) * A;
+        c.b1 = (ap * cs + am) * A * -2.0f;
+        c.a1 = q + q;
+        c.a2 = m - s * k;
+    }
+    const float inv = 1.0f / a0;
+    c.b0 = flushSmall (inv * c.b0);
+    c.b1 = flushSmall (inv * c.b1);
+    c.b2 = flushSmall (inv * c.b2);
+    c.a1 = flushSmall (inv * c.a1);
+    c.a2 = flushSmall (inv * c.a2);
+    return c;
+}
+
+// one Direct-Form-I step in FLM's order of operations
+inline float biquad (const Coefs& c, float x0, float x1, float x2, float y1, float y2) noexcept
+{
+    return ((x0 * c.b0 + x1 * c.b1 + c.b2 * x2) - c.a1 * y1) - c.a2 * y2;
+}
+
+// ---------------------------------------------------------------------------------------------------------------
+// Equalizer (FLM module 3). Four bands; band b: gain (v − ½)·24 dB as shown (twice that applied), frequency
+// 2^(9.25v + 5) Hz, bandwidth 7v + ¼ octaves (at least 0.0001), kind ⌊2v⌋ (low shelf, peak, high shelf), channel ⌊4v⌋
+// (both; left only; right only; left + / right −; left − / right +). The bands are designed at twice the running rate
+// and run 2× oversampled: each input sample is fed twice (held), every second output is kept. The four bands are one
+// pipeline: the input enters band 4, and each band takes the output its neighbour produced one half-sample earlier.
+class Equalizer final : public Effect
+{
+public:
+    void prepare (double sampleRate) noexcept override
+    {
+        fs = sampleRate > 0.0 ? sampleRate : 44100.0;
+        gate.prepare (fs, 10.0);
+        reset();
+    }
+    void reset() noexcept override
+    {
+        for (auto& ch : st)
+            ch = {};
+        dirty = true;
+    }
+    void process (float* left, float* right, int n, const EffectParams& p, double) noexcept override
+    {
+        for (int k = 0; k < eqParams; ++k)
+            if (p[(std::size_t) k] != last[(std::size_t) k])
+                dirty = true;
+        bool clear = false;
+        const bool on = gate.run (left, right, n, clear);
+        if (clear)
+            for (auto& ch : st)
+                ch = {};
+        if (! on)
+            return;
+        if (dirty)
+            design (p);
+        for (int i = 0; i < n; ++i)
+        {
+            const auto xl = (float) ((double) left[i] + tiny);
+            const auto xr = (float) ((double) (right != nullptr ? right[i] : left[i]) + tiny);
+            step (st[0], coef[0], xl);
+            step (st[1], coef[1], xr);
+            left[i] = step (st[0], coef[0], xl);
+            const auto yr = step (st[1], coef[1], xr);
+            if (right != nullptr)
+                right[i] = yr;
+        }
+    }
+
+    // lane k = band k; the pipeline runs from lane 3 (the input) down to lane 0 (the output)
+    struct Lanes
+    {
+        std::array<float, 4> x1 {}, x2 {}, y1 {}, y2 {};
+    };
+
+    static float step (Lanes& s, const std::array<Coefs, 4>& c, float x) noexcept
+    {
+        std::array<float, 4> in { s.y1[1], s.y1[2], s.y1[3], x }, y {};
+        for (int k = 0; k < 4; ++k)
+            y[(std::size_t) k] = biquad (c[(std::size_t) k], in[(std::size_t) k], s.x1[(std::size_t) k], s.x2[(std::size_t) k],
+                                         s.y1[(std::size_t) k], s.y2[(std::size_t) k]);
+        s.x2 = s.x1;
+        s.x1 = in;
+        s.y2 = s.y1;
+        s.y1 = y;
+        return y[0];
+    }
+
+    void design (const EffectParams& p) noexcept
+    {
+        dirty = false;
+        for (int k = 0; k < eqParams; ++k)
+            last[(std::size_t) k] = p[(std::size_t) k];
+        const auto rate = (float) (fs + fs);
+        for (int b = 0; b < 4; ++b)
+        {
+            const auto kind = std::clamp ((int) (p[(std::size_t) (4 * b + 3)] * 2.0f), 0, 2);
+            auto hz = (float) std::pow (2.0, (double) p[(std::size_t) (4 * b + 1)] * 9.25 + 5.0);
+            if (hz <= 0.0f)
+                hz = 0.0f;
+            auto oct = p[(std::size_t) (4 * b + 2)] * 7.0f + 0.25f;
+            if (oct <= 0.0001f)
+                oct = 0.0001f;
+            const auto db = (p[(std::size_t) (4 * b)] - 0.5f) * 24.0f;
+            const auto mode = (int) (p[(std::size_t) (16 + b)] * 4.0f);
+            float gl = 1.0f, gr = 1.0f;
+            switch (mode)
+            {
+                case 1: gr = 0.0f; break;
+                case 2: gl = 0.0f; break;
+                case 3: gr = -1.0f; break;
+                case 4: gl = -1.0f; break;
+                default: break;
+            }
+            coef[0][(std::size_t) b] = designBand (kind, hz, db * gl, oct, rate);
+            coef[1][(std::size_t) b] = designBand (kind, hz, db * gr, oct, rate);
+        }
+    }
+
+private:
+    double fs = 44100.0;
+    std::array<Lanes, 2> st {};
+    std::array<std::array<Coefs, 4>, 2> coef {};
+    std::array<float, eqParams> last {};
+    bool dirty = true;
+    SilenceGate gate;
+};
+
+// ---------------------------------------------------------------------------------------------------------------
+// Graphic EQ (FLM module 7): eight bands at 80, 160, 375, 750, 1500, 3000, 6000 and 12000 Hz — a low shelf, six peaks
+// and a high shelf, one octave wide, 24v − 12 dB as shown (twice that applied), designed at the running rate. FLM
+// runs them as four pairs; inside a pair the second band takes the first band's output from two samples earlier, the
+// pairs follow each other within the sample: 8 samples of delay in all.
+constexpr float graphicCentres[8] { 80.0f, 160.0f, 375.0f, 750.0f, 1500.0f, 3000.0f, 6000.0f, 12000.0f };
+
+class GraphicEq final : public Effect
+{
+public:
+    void prepare (double sampleRate) noexcept override
+    {
+        fs = sampleRate > 0.0 ? sampleRate : 44100.0;
+        gate.prepare (fs, 10.0);
+        reset();
+    }
+    void reset() noexcept override
+    {
+        for (auto& ch : st)
+            ch = {};
+        dirty = true;
+    }
+    void process (float* left, float* right, int n, const EffectParams& p, double) noexcept override
+    {
+        for (int k = 0; k < graphicEqParams; ++k)
+            if (p[(std::size_t) k] != last[(std::size_t) k])
+                dirty = true;
+        bool clear = false;
+        const bool on = gate.run (left, right, n, clear);
+        if (clear)
+            for (auto& ch : st)
+                ch = {};
+        if (! on)
+            return;
+        if (dirty)
+        {
+            dirty = false;
+            for (int b = 0; b < 8; ++b)
+            {
+                last[(std::size_t) b] = p[(std::size_t) b];
+                const auto kind = b == 0 ? 0 : b == 7 ? 2 : 1;
+                coef[(std::size_t) b] = designBand (kind, graphicCentres[b], p[(std::size_t) b] * 24.0f - 12.0f, 1.0f, (float) fs);
+            }
+        }
+        for (int i = 0; i < n; ++i)
+        {
+            const auto xl = (float) ((double) left[i] + tiny);
+            const auto xr = (float) ((double) (right != nullptr ? right[i] : left[i]) + tiny);
+            left[i] = run (st[0], xl);
+            const auto yr = run (st[1], xr);
+            if (right != nullptr)
+                right[i] = yr;
+        }
+    }
+
+    // per pair g: lane 0 = band 2g, lane 1 = band 2g + 1
+    struct Pair
+    {
+        std::array<float, 2> x1 {}, x2 {}, y1 {}, y2 {};
+    };
+
+    float run (std::array<Pair, 4>& s, float x) noexcept
+    {
+        for (int g = 0; g < 4; ++g)
+        {
+            auto& q = s[(std::size_t) g];
+            const auto in1 = q.y2[0]; // the first band's output two samples back
+            const auto y0 = biquad (coef[(std::size_t) (2 * g)], x, q.x1[0], q.x2[0], q.y1[0], q.y2[0]);
+            const auto y1 = biquad (coef[(std::size_t) (2 * g + 1)], in1, q.x1[1], q.x2[1], q.y1[1], q.y2[1]);
+            q.x2 = q.x1;
+            q.x1 = { x, in1 };
+            q.y2 = q.y1;
+            q.y1 = { y0, y1 };
+            x = y1;
+        }
+        return x;
+    }
+
+private:
+    double fs = 44100.0;
+    std::array<std::array<Pair, 4>, 2> st {};
+    std::array<Coefs, 8> coef {};
+    std::array<float, graphicEqParams> last {};
+    bool dirty = true;
+    SilenceGate gate;
+};
+
+// ---------------------------------------------------------------------------------------------------------------
+// Filter (FLM module 9): frequency 2^(10.3v + 4) Hz, Q = 2v² + 0.8, type ⌊2v⌋ (low-pass, band-pass, high-pass), slope
+// ⌊2v⌋ = 1, 2 or 4 pairs of identical biquads (24 / 48 / 96 dB per octave). Low / high-pass: feedback at α = sin ω/Q,
+// feed-forward (1 ∓ cos ω)/(2 + sin ω/Q) on the zeros 1, ±2, 1 (the cookbook's filter at Q/2 with its level offset
+// (1 + s/Q)/(1 + s/2Q)); the low-pass output is × 0.8^pairs. Band-pass: the cookbook's constant-skirt form in double
+// precision (peak level Q). Inside a pair the second biquad takes the first one's output of the sample before; the pairs
+// follow each other within the sample. The level 0.8^pairs is only recomputed with the coefficients (a Frequency, Q or
+// Type change), as FLM does.
+class Filter final : public Effect
+{
+public:
+    void prepare (double sampleRate) noexcept override
+    {
+        fs = sampleRate > 0.0 ? sampleRate : 44100.0;
+        gate.prepare (fs, 6.0);
+        reset();
+    }
+    void reset() noexcept override
+    {
+        for (auto& ch : st)
+            ch = {};
+        dirty = true;
+    }
+    void process (float* left, float* right, int n, const EffectParams& p, double) noexcept override
+    {
+        if (p[0] != last[0] || p[1] != last[1] || p[2] != last[2])
+            dirty = true;
+        const auto slope = (int) (p[3] + p[3]);
+        if (slope == 0)
+            pairs = 1;
+        else if (slope == 1)
+            pairs = 2;
+        else if (slope == 2)
+            pairs = 4;
+        bool clear = false;
+        const bool on = gate.run (left, right, n, clear);
+        if (clear)
+            for (auto& ch : st)
+                ch = {};
+        if (! on)
+            return;
+        if (dirty)
+            design (p);
+        for (int i = 0; i < n; ++i)
+        {
+            const auto xl = (float) ((double) left[i] + tiny);
+            const auto xr = (float) ((double) (right != nullptr ? right[i] : left[i]) + tiny);
+            left[i] = run (st[0], xl) * level;
+            const auto yr = run (st[1], xr) * level;
+            if (right != nullptr)
+                right[i] = yr;
+        }
+    }
+
+    struct Pair
+    {
+        std::array<float, 2> x1 {}, x2 {}, y1 {}, y2 {};
+    };
+
+    float run (std::array<Pair, 4>& s, float x) const noexcept
+    {
+        for (int g = 0; g < pairs; ++g)
+        {
+            auto& q = s[(std::size_t) g];
+            const std::array<float, 2> in { x, q.y1[0] };
+            std::array<float, 2> y {};
+            for (int k = 0; k < 2; ++k)
+            {
+                const auto j = (std::size_t) k;
+                if (type == 1)
+                    y[j] = ((in[j] - q.x2[j]) * c.b0 + c.a1 * q.y1[j]) - c.a2 * q.y2[j];
+                else
+                    y[j] = ((zero * q.x1[j] + in[j] + q.x2[j]) * c.b0 - c.a1 * q.y1[j]) - c.a2 * q.y2[j];
+            }
+            q.x2 = q.x1;
+            q.x1 = in;
+            q.y2 = q.y1;
+            q.y1 = y;
+            x = y[1];
+        }
+        return x;
+    }
+
+    void design (const EffectParams& p) noexcept
+    {
+        dirty = false;
+        for (int k = 0; k < 3; ++k)
+            last[(std::size_t) k] = p[(std::size_t) k];
+        const auto hz = (float) std::pow (2.0, (double) p[0] * 10.3 + 4.0);
+        const auto q = p[1] * p[1] + p[1] * p[1] + 0.8f;
+        type = (int) (p[2] + p[2]);
+        const auto rate = (float) fs;
+        if (type == 1)
+        {
+            const double w = ((double) hz * 6.283185307179586) / (double) rate;
+            const double s = std::sin (w), cs = std::cos (w);
+            const double inv = 1.0 / ((0.5 / (double) q) * s + 1.0);
+            c.b0 = flushSmall ((float) ((double) (float) (s * 0.5) * inv));
+            c.a1 = flushSmall ((float) ((double) (float) (cs + cs) * inv));
+            c.a2 = flushSmall ((float) ((double) (float) (1.0 - s / (double) (q + q)) * inv));
+            level = 1.0f;
+        }
+        else if (type == 0 || type == 2)
+        {
+            const float w = (hz * 6.2831855f) / rate;
+            const float s = std::sin (w), cs = std::cos (w);
+            const float inv = 1.0f / (s + q);
+            c.b0 = flushSmall ((type == 0 ? 1.0f - cs : cs + 1.0f) / (s / q + 2.0f));
+            c.a1 = flushSmall (cs * inv * q * -2.0f);
+            c.a2 = flushSmall ((q - s) * inv);
+            zero = type == 0 ? 2.0f : -2.0f;
+            level = type == 0 ? (float) std::pow ((double) 0.8f, (double) pairs) : 1.0f;
+        }
+    }
+
+private:
+    double fs = 44100.0;
+    std::array<std::array<Pair, 4>, 2> st {};
+    Coefs c;
+    float zero = 2.0f, level = 0.8f;
+    int type = 0, pairs = 2;
+    std::array<float, 3> last { -1.0f, -1.0f, -1.0f };
+    bool dirty = true;
+    SilenceGate gate;
+};
+} // namespace
+
+std::unique_ptr<Effect> makeEq() { return std::make_unique<Equalizer>(); }
+std::unique_ptr<Effect> makeGraphicEq() { return std::make_unique<GraphicEq>(); }
+std::unique_ptr<Effect> makeFilter() { return std::make_unique<Filter>(); }
+
+int eqKind (float v) noexcept { return std::clamp ((int) (v * 2.0f), 0, 2); }
+int eqChannelMode (float v) noexcept { return std::clamp ((int) (v * 4.0f), 0, 4); }
+double eqHz (float v) noexcept { return std::pow (2.0, (double) v * 9.25 + 5.0); }
+double eqOctaves (float v) noexcept { return std::max ((double) (v * 7.0f + 0.25f), 0.0001); }
+double filterHzOf (float v) noexcept { return std::pow (2.0, (double) v * 10.3 + 4.0); }
+double filterQOf (float v) noexcept { return (double) (v * v + v * v + 0.8f); }
+int filterType (float v) noexcept { return std::clamp ((int) (v + v), 0, 2); }
+int filterPairs (float v) noexcept
+{
+    const auto s = (int) (v + v);
+    return s <= 0 ? 1 : s == 1 ? 2 : 4;
+}
+
+std::array<double, 5> eqBandCoefficients (int kind, double hz, double shownDb, double octaves, double rate) noexcept
+{
+    const auto c = designBand (kind, (float) hz, (float) shownDb, (float) octaves, (float) rate);
+    return { c.b0, c.b1, c.b2, c.a1, c.a2 };
+}
+
+namespace
+{
+std::string hzText (double hz) { return hz < 1000.0 ? format ("%.1f Hz", hz) : format ("%.2f kHz", hz * 0.001); }
+} // namespace
+
+std::string eqParamText (int param, float v)
+{
+    if (param < 0 || param >= eqParams)
+        return {};
+    if (param >= 16)
+    {
+        static const char* const names[] { "Both", "Left", "Right", "Left + / right -", "Left - / right +" };
+        return names[eqChannelMode (v)];
+    }
+    switch (param % 4)
+    {
+        case 0: return format ("%.1f dB", (double) (v * 24.0f - 12.0f));
+        case 1: return hzText (eqHz (v));
+        case 2: return format ("%.2f oct", eqOctaves (v));
+        default:
+        {
+            static const char* const names[] { "Low shelf", "Peak", "High shelf" };
+            return names[eqKind (v)];
+        }
+    }
+}
+
+std::string graphicEqParamText (int param, float v)
+{
+    if (param < 0 || param >= graphicEqParams)
+        return {};
+    return format ("%.1f dB", (double) (v * 24.0f - 12.0f));
+}
+
+std::string filterParamText (int param, float v)
+{
+    switch (param)
+    {
+        case 0: return format ("%.1f Hz", filterHzOf (v));
+        case 1: return format ("%.2f", filterQOf (v));
+        case 2:
+        {
+            static const char* const names[] { "LP", "BP", "HP" };
+            return names[filterType (v)];
+        }
+        case 3:
+        {
+            static const char* const names[] { "24 dB/O", "48 dB/O", "96 dB/O" };
+            const auto p = filterPairs (v);
+            return names[p == 1 ? 0 : p == 2 ? 1 : 2];
+        }
+        default: return {};
+    }
+}
+} // namespace lynx::pocket

+ 328 - 0
tests/PocketEq190dwTests.inc

@@ -0,0 +1,328 @@
+// Round 190dw: FL Studio Mobile's Equalizer, Graphic EQ and Filter as exact Pocket engines (core/PocketFxE.cpp).
+// Each engine's impulse response is checked against an independent double-precision model written here from the laws
+// (design, 2× hold-and-keep path, the band pipelines' delays), plus the laws themselves, the channel modes, the silence
+// gate and extremes. The renders against FL Studio Mobile inside FL are in the round's notes
+// (/mnt/e/lynx-work/flm190dw/fx, 34 sets at the 16-bit floor).
+
+namespace eq190dw
+{
+using C5 = std::array<double, 5>; // b0, b1, b2, a1, a2 (a0 = 1)
+
+// FLM's band design in double: the cookbook forms with A = 10^(dB/20) and the bandwidth in octaves
+inline C5 band (int kind, double hz, double db, double oct, double rate)
+{
+    const double A = std::pow (10.0, db / 20.0);
+    const double w = std::clamp (2.0 * 3.141592653589793 * hz / rate, 0.0, 3.0);
+    const double s = std::sin (w), c = std::cos (w);
+    const double alpha = s * std::sinh (std::log (2.0) / 2.0 * oct * w / s);
+    double b0, b1, b2, a0, a1, a2;
+    if (kind == 1)
+        b0 = 1 + alpha * A, b1 = -2 * c, b2 = 1 - alpha * A, a0 = 1 + alpha / A, a1 = -2 * c, a2 = 1 - alpha / A;
+    else
+    {
+        const double r = 2 * std::sqrt (A) * alpha, sg = kind == 0 ? 1.0 : -1.0;
+        b0 = A * ((A + 1) - sg * (A - 1) * c + r);
+        b1 = sg * 2 * A * ((A - 1) - sg * (A + 1) * c);
+        b2 = A * ((A + 1) - sg * (A - 1) * c - r);
+        a0 = (A + 1) + sg * (A - 1) * c + r;
+        a1 = -sg * 2 * ((A - 1) + sg * (A + 1) * c);
+        a2 = (A + 1) + sg * (A - 1) * c - r;
+    }
+    return { b0 / a0, b1 / a0, b2 / a0, a1 / a0, a2 / a0 };
+}
+
+struct Bq
+{
+    C5 c {};
+    double x1 = 0, x2 = 0, y1 = 0, y2 = 0;
+    double operator() (double x)
+    {
+        const double y = c[0] * x + c[1] * x1 + c[2] * x2 - c[3] * y1 - c[4] * y2;
+        x2 = x1, x1 = x, y2 = y1, y1 = y;
+        return y;
+    }
+};
+
+inline std::vector<double> cascade (std::vector<Bq> f, const std::vector<double>& x)
+{
+    std::vector<double> y (x.size());
+    for (std::size_t i = 0; i < x.size(); ++i)
+    {
+        double v = x[i];
+        for (auto& b : f)
+            v = b (v);
+        y[i] = v;
+    }
+    return y;
+}
+
+// the left output of an engine for a unit impulse at sample 0 (both sides); `right` gets the right side
+inline std::vector<float> ir (lynx::EffectKind kind, const std::vector<float>& values, int n, double fs = 44100.0,
+                              std::vector<float>* right = nullptr)
+{
+    using namespace lynx;
+    auto fx = makeEffect (kind);
+    fx->prepare (fs);
+    auto p = makeEffectSlot (kind).params;
+    for (std::size_t k = 0; k < values.size(); ++k)
+        p[k] = values[k];
+    std::vector<float> l ((std::size_t) n, 0.0f), r ((std::size_t) n, 0.0f);
+    l[0] = r[0] = 1.0f;
+    for (int at = 0; at < n; at += 512)
+        fx->process (l.data() + at, r.data() + at, std::min (512, n - at), p, 120.0);
+    if (right != nullptr)
+        *right = r;
+    return l;
+}
+
+inline double maxDiff (const std::vector<float>& a, const std::vector<double>& b)
+{
+    double m = 0;
+    for (std::size_t i = 0; i < std::min (a.size(), b.size()); ++i)
+        m = std::max (m, std::abs ((double) a[i] - b[i]));
+    return m;
+}
+
+// the Equalizer's reference: hold each sample twice, run the four bands (band 4 first) at 2·fs, keep one output in
+// two; FLM's pipeline adds three half-sample steps, so output n is the 2× sequence's sample 2n − 2
+inline std::vector<double> eqReference (const std::vector<float>& v, int n, double fs, int channel)
+{
+    std::vector<Bq> f;
+    for (int b = 3; b >= 0; --b)
+    {
+        const int kind = std::clamp ((int) (v[(std::size_t) (4 * b + 3)] * 2.0f), 0, 2);
+        const double hz = std::pow (2.0, (double) v[(std::size_t) (4 * b + 1)] * 9.25 + 5.0);
+        const double oct = std::max ((double) v[(std::size_t) (4 * b + 2)] * 7.0 + 0.25, 0.0001);
+        double db = ((double) v[(std::size_t) (4 * b)] - 0.5) * 24.0;
+        const int mode = v.size() > (std::size_t) (16 + b) ? (int) (v[(std::size_t) (16 + b)] * 4.0f) : 0;
+        if ((mode == 1 && channel == 1) || (mode == 2 && channel == 0))
+            db = 0.0;
+        if ((mode == 3 && channel == 1) || (mode == 4 && channel == 0))
+            db = -db;
+        Bq q;
+        q.c = band (kind, hz, db, oct, 2.0 * fs);
+        f.push_back (q);
+    }
+    std::vector<double> up ((std::size_t) (2 * n), 0.0);
+    up[0] = up[1] = 1.0;
+    const auto y2 = cascade (f, up);
+    std::vector<double> y ((std::size_t) n, 0.0);
+    for (int i = 1; i < n; ++i)
+        y[(std::size_t) i] = y2[(std::size_t) (2 * i - 2)];
+    return y;
+}
+} // namespace eq190dw
+
+TEST (pocketeq190dw_laws)
+{
+    using namespace lynx;
+    CHECK (std::abs (pocket::eqHz (0.0f) - 32.0) < 1e-9);
+    CHECK (std::abs (pocket::eqHz (1.0f) - std::pow (2.0, 14.25)) < 1e-6);
+    CHECK (std::abs (pocket::eqHz (0.07f) - 50.0) < 1.0); // FLM's "Low Cut 50Hz" preset value
+    CHECK (std::abs (pocket::eqOctaves (0.5f) - 3.75) < 1e-6 && std::abs (pocket::eqOctaves (0.0f) - 0.25) < 1e-9);
+    CHECK (pocket::eqKind (0.0f) == 0 && pocket::eqKind (0.51f) == 1 && pocket::eqKind (1.0f) == 2);
+    CHECK (pocket::eqChannelMode (0.0f) == 0 && pocket::eqChannelMode (0.3f) == 1 && pocket::eqChannelMode (0.5f) == 2
+           && pocket::eqChannelMode (0.75f) == 3 && pocket::eqChannelMode (1.0f) == 4);
+    CHECK (std::abs (pocket::filterHzOf (0.0f) - 16.0) < 1e-9 && std::abs (pocket::filterHzOf (1.0f) - std::pow (2.0, 14.3)) < 1e-6);
+    CHECK (std::abs (pocket::filterQOf (0.0f) - 0.8) < 1e-6 && std::abs (pocket::filterQOf (1.0f) - 2.8) < 1e-6);
+    CHECK (pocket::filterType (0.0f) == 0 && pocket::filterType (0.5f) == 1 && pocket::filterType (1.0f) == 2);
+    CHECK (pocket::filterPairs (0.0f) == 1 && pocket::filterPairs (0.5f) == 2 && pocket::filterPairs (1.0f) == 4);
+    // the doubled amplitude law: a +6 dB (shown) peak lifts its centre by 12 dB
+    const auto c = pocket::eqBandCoefficients (1, 1000.0, 6.0, 1.0, 88200.0);
+    const double w = 2.0 * 3.141592653589793 * 1000.0 / 88200.0;
+    const std::complex<double> z1 = std::polar (1.0, -w), z2 = z1 * z1;
+    const double db = 20.0 * std::log10 (std::abs ((c[0] + c[1] * z1 + c[2] * z2) / (1.0 + c[3] * z1 + c[4] * z2)));
+    CHECK (std::abs (db - 12.0) < 0.001);
+    const auto r = eq190dw::band (1, 1000.0, 6.0, 1.0, 88200.0);
+    for (int k = 0; k < 5; ++k)
+        CHECK (std::abs (c[(std::size_t) k] - r[(std::size_t) k]) < 2e-6);
+    // the texts FLM shows
+    CHECK (pocket::eqParamText (0, 0.75f) == "6.0 dB" && pocket::eqParamText (1, 0.0f) == "32.0 Hz");
+    CHECK (pocket::eqParamText (3, 0.0f) == "Low shelf" && pocket::eqParamText (16, 0.3f) == "Left");
+    CHECK (pocket::graphicEqParamText (0, 1.0f) == "12.0 dB");
+    CHECK (pocket::filterParamText (2, 1.0f) == "HP" && pocket::filterParamText (3, 0.5f) == "48 dB/O");
+    // parameter lists: the module's values after its Enable, FLM's defaults
+    CHECK ((int) effectInfo (EffectKind::pocketEq).params.size() == pocket::eqParams);
+    CHECK ((int) effectInfo (EffectKind::pocketGraphicEq).params.size() == pocket::graphicEqParams);
+    CHECK ((int) effectInfo (EffectKind::pocketFilter).params.size() == pocket::filterParams);
+    CHECK (std::abs (effectInfo (EffectKind::pocketFilter).params[0].defaultValue - 0.7f) < 1e-6f);
+}
+
+TEST (pocketeq190dw_equalizer_matches_its_model)
+{
+    using namespace lynx;
+    const std::vector<std::vector<float>> sets {
+        { 0.5595f, 0.2065f, 0.1862f, 0.0f, 0.4403f, 0.3207f, 0.6021f, 0.51f, 0.5f, 1.0f, 0.5f, 0.51f, 0.6318f, 0.5696f, 0.208f, 1.0f, 0, 0, 0, 0 },
+        { 0.0f, 0.006f, 0.3691f, 0.0f, 0.5f, 0.4f, 0.5f, 0.51f, 0.5f, 0.6f, 0.5f, 0.51f, 0.5337f, 0.6317f, 0.5f, 1.0f, 0, 0, 0, 0 },
+        { 0.5f, 0.2f, 0.5f, 0.51f, 0.25f, 0.75f, 0.1f, 0.51f, 0.6875f, 0.95f, 0.05f, 0.51f, 0.75f, 0.84f, 0.3f, 1.0f, 0, 0, 0, 0 },
+        { 0.75f, 0.55f, 0.2f, 0.51f, 0.3f, 0.4f, 0.5f, 0.51f, 0.6f, 0.6f, 0.5f, 0.0f, 0.4f, 0.8f, 0.5f, 0.51f, 0.3f, 0.5f, 0.75f, 1.0f },
+    };
+    for (double fs : { 44100.0, 48000.0, 96000.0 })
+        for (const auto& v : sets)
+        {
+            std::vector<float> right;
+            const auto l = eq190dw::ir (EffectKind::pocketEq, v, 4096, fs, &right);
+            const double eL = eq190dw::maxDiff (l, eq190dw::eqReference (v, 4096, fs, 0));
+            const double eR = eq190dw::maxDiff (right, eq190dw::eqReference (v, 4096, fs, 1));
+            CHECK (eL < 2e-4 && eR < 2e-4);
+            if (! (eL < 2e-4 && eR < 2e-4))
+                std::printf ("  fs %.0f: |error| L %.2e R %.2e\n", fs, eL, eR);
+        }
+    // flat: the input comes out one sample late (the pipeline's three half-sample steps and the hold)
+    const auto flat = eq190dw::ir (EffectKind::pocketEq, {}, 64);
+    CHECK (std::abs (flat[0]) < 1e-6f && std::abs (flat[1] - 1.0f) < 1e-6f && std::abs (flat[2]) < 1e-6f);
+}
+
+TEST (pocketeq190dw_graphic_eq_matches_its_model)
+{
+    using namespace lynx;
+    static constexpr double centres[8] { 80, 160, 375, 750, 1500, 3000, 6000, 12000 };
+    const std::vector<std::vector<float>> sets { { 0.0f, 0.0691f, 0.1406f, 0.3586f, 0.2175f, 0.1276f, 0.0862f, 0.0f },
+                                                 { 0.249f, 0.3314f, 0.351f, 0.5f, 0.5f, 0.4255f, 0.6098f, 0.649f },
+                                                 { 1.0f, 0.5f, 1.0f, 0.5f, 1.0f, 0.5f, 1.0f, 1.0f } };
+    for (double fs : { 44100.0, 96000.0 })
+        for (const auto& v : sets)
+        {
+            std::vector<eq190dw::Bq> f;
+            for (int b = 0; b < 8; ++b)
+            {
+                eq190dw::Bq q;
+                q.c = eq190dw::band (b == 0 ? 0 : b == 7 ? 2 : 1, centres[b], (double) v[(std::size_t) b] * 24.0 - 12.0, 1.0, fs);
+                f.push_back (q);
+            }
+            std::vector<double> x (4096, 0.0);
+            x[0] = 1.0;
+            const auto y = eq190dw::cascade (f, x);
+            std::vector<double> late (4096, 0.0); // two samples inside each of the four pairs
+            for (int i = 8; i < 4096; ++i)
+                late[(std::size_t) i] = y[(std::size_t) (i - 8)];
+            const double e = eq190dw::maxDiff (eq190dw::ir (EffectKind::pocketGraphicEq, v, 4096, fs), late);
+            CHECK (e < 5e-4);
+            if (! (e < 5e-4))
+                std::printf ("  graphic fs %.0f: |error| %.2e\n", fs, e);
+        }
+}
+
+TEST (pocketeq190dw_filter_matches_its_model)
+{
+    using namespace lynx;
+    const std::vector<std::vector<float>> sets { { 1.0f, 0.0f, 0.0f, 0.5f }, { 0.7f, 0.0f, 0.0f, 0.5f }, { 0.5788f, 0.5037f, 1.0f, 0.0f },
+                                                 { 0.6075f, 1.0f, 0.0f, 0.5f }, { 0.5f, 0.5f, 0.5f, 0.5f }, { 0.6f, 0.3f, 0.0f, 1.0f },
+                                                 { 0.3f, 0.8f, 0.5f, 1.0f } };
+    for (double fs : { 44100.0, 48000.0, 96000.0 })
+        for (const auto& v : sets)
+        {
+            const double hz = pocket::filterHzOf (v[0]), q = pocket::filterQOf (v[1]);
+            const int type = pocket::filterType (v[2]), pairs = pocket::filterPairs (v[3]);
+            const double w = 2.0 * 3.141592653589793 * hz / fs, s = std::sin (w), c = std::cos (w);
+            eq190dw::Bq bq;
+            if (type == 1)
+            {
+                const double a0 = 1.0 + s / (2.0 * q);
+                bq.c = { s / 2.0 / a0, 0.0, -s / 2.0 / a0, -2.0 * c / a0, (1.0 - s / (2.0 * q)) / a0 };
+            }
+            else
+            {
+                const double a0 = 1.0 + s / q, g = (type == 0 ? 1.0 - c : 1.0 + c) / (2.0 + s / q), z = type == 0 ? 2.0 : -2.0;
+                bq.c = { g, z * g, g, -2.0 * c / a0, (1.0 - s / q) / a0 };
+            }
+            for (auto& k : bq.c)
+                k = (double) (float) k; // FLM's coefficients are single precision: compare the arithmetic, not the rounding
+            std::vector<eq190dw::Bq> f ((std::size_t) (2 * pairs), bq);
+            std::vector<double> x (4096, 0.0);
+            x[0] = 1.0;
+            const auto y = eq190dw::cascade (f, x);
+            const double level = type == 0 ? std::pow (0.8, pairs) : 1.0;
+            std::vector<double> late (4096, 0.0); // one sample inside each pair
+            for (int i = pairs; i < 4096; ++i)
+                late[(std::size_t) i] = level * y[(std::size_t) (i - pairs)];
+            double peak = 0;
+            for (double t : late)
+                peak = std::max (peak, std::abs (t));
+            const double e = eq190dw::maxDiff (eq190dw::ir (EffectKind::pocketFilter, v, 4096, fs), late);
+            CHECK (e < 2e-3 * std::max (1.0, peak)); // (8 stages of a narrow low band-pass: float rounding in the state)
+            if (! (e < 2e-3 * std::max (1.0, peak)))
+                std::printf ("  filter fs %.0f type %d pairs %d: |error| %.2e\n", fs, type, pairs, e);
+        }
+}
+
+TEST (pocketeq190dw_channel_modes_and_silence)
+{
+    using namespace lynx;
+    // band 1 boosted on the left only: the right side stays flat (one sample late)
+    std::vector<float> v (20, 0.5f);
+    for (int b = 0; b < 4; ++b)
+        v[(std::size_t) (4 * b + 3)] = 0.51f, v[(std::size_t) (4 * b + 1)] = 0.2f + 0.2f * (float) b;
+    for (int b = 0; b < 4; ++b)
+        v[(std::size_t) (16 + b)] = 0.0f;
+    v[0] = 0.8f;
+    v[16] = 0.3f;
+    std::vector<float> right;
+    const auto left = eq190dw::ir (EffectKind::pocketEq, v, 256, 44100.0, &right);
+    CHECK (std::abs (right[1] - 1.0f) < 1e-6f && std::abs (right[2]) < 1e-6f);
+    CHECK (std::abs (left[2]) > 1e-3f);
+    // opposite gains: left + / right − mirror each other's response (a boost and the same cut)
+    v[16] = 0.75f;
+    const auto l3 = eq190dw::ir (EffectKind::pocketEq, v, 256, 44100.0, &right);
+    CHECK (eq190dw::maxDiff (l3, eq190dw::eqReference (v, 256, 44100.0, 0)) < 2e-4);
+    CHECK (eq190dw::maxDiff (right, eq190dw::eqReference (v, 256, 44100.0, 1)) < 2e-4);
+
+    // silence in → silence out, exactly; after the tail the module stops and starts afresh on new input
+    for (auto kind : { EffectKind::pocketEq, EffectKind::pocketGraphicEq, EffectKind::pocketFilter })
+    {
+        auto fx = makeEffect (kind);
+        fx->prepare (44100.0);
+        const auto p = makeEffectSlot (kind).params;
+        std::vector<float> l (512, 0.0f), r (512, 0.0f);
+        bool silent = true;
+        for (int k = 0; k < 20; ++k)
+        {
+            fx->process (l.data(), r.data(), 512, p, 120.0);
+            for (int i = 0; i < 512; ++i)
+                silent = silent && l[(std::size_t) i] == 0.0f && r[(std::size_t) i] == 0.0f;
+        }
+        CHECK (silent);
+        // an impulse, then 11 s of silence (past every tail), then the same impulse: the same response
+        auto first = std::vector<float> (512, 0.0f), again = first;
+        first[0] = 1.0f;
+        auto rr = first;
+        fx->process (first.data(), rr.data(), 512, p, 120.0);
+        for (int k = 0; k < (int) (11.0 * 44100.0 / 512.0) + 2; ++k)
+        {
+            std::fill (l.begin(), l.end(), 0.0f), std::fill (r.begin(), r.end(), 0.0f);
+            fx->process (l.data(), r.data(), 512, p, 120.0);
+        }
+        again[0] = 1.0f;
+        rr = again;
+        fx->process (again.data(), rr.data(), 512, p, 120.0);
+        CHECK (first == again);
+    }
+}
+
+TEST (pocketeq190dw_extremes_stay_finite)
+{
+    using namespace lynx;
+    std::mt19937 rng (190);
+    std::uniform_real_distribution<float> u (-1.0f, 1.0f);
+    for (double fs : { 44100.0, 48000.0, 96000.0 })
+        for (auto kind : { EffectKind::pocketEq, EffectKind::pocketGraphicEq, EffectKind::pocketFilter })
+            for (float x : { 0.0f, 1.0f })
+            {
+                auto fx = makeEffect (kind);
+                fx->prepare (fs);
+                auto p = makeEffectSlot (kind).params;
+                for (std::size_t k = 0; k < effectInfo (kind).params.size(); ++k)
+                    p[k] = x;
+                std::vector<float> l (4096), r (4096);
+                for (auto& s : l)
+                    s = u (rng);
+                for (auto& s : r)
+                    s = u (rng);
+                for (int at = 0; at < 4096; at += 512)
+                    fx->process (l.data() + at, r.data() + at, 512, p, 120.0);
+                bool finite = true;
+                for (int i = 0; i < 4096; ++i)
+                    finite = finite && std::isfinite (l[(std::size_t) i]) && std::isfinite (r[(std::size_t) i]) && std::abs (l[(std::size_t) i]) < 1e7f;
+                CHECK (finite);
+            }
+}