Skip to content

armgit / nota

Public Imported from GitHub
0

Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.

(fix) Prism, EQ-8 and Auto Filter use as little CPU as before the engine rebuild (#287)

Egor Khindikaynen5c297bf6679c
diff --git a/.specify/bugs/dsp-perf-regressions/assessment.md b/.specify/bugs/dsp-perf-regressions/assessment.md
new file mode 100644
index 00000000..7de6ac43
--- /dev/null
+++ b/.specify/bugs/dsp-perf-regressions/assessment.md
@@ -0,0 +1,116 @@
+# Bug Assessment: Prism, EQ-8 and Auto Filter render up to 2× slower since the engine rebuild
+
+- **Slug**: dsp-perf-regressions
+- **Created**: 2026-10-23
+- **Source**: pasted text + the Performance run on nota-daw/nota#285 (https://github.com/nota-daw/nota/actions/runs/39852475318, host github.com, allowlisted; read through `gh`)
+- **Verdict**: valid
+- **Severity**: medium
+
+## Report (verbatim or summarized)
+
+The Performance gate (`.github/workflows/perf.yml`, `scripts/perf-gate.sh`) fails on the
+release PR develop → main (#285): 19 scenarios do more than 1 % more CPU instructions,
+or take more than 15 % more wall time, than `main` (0.56.1). Every regressed device was
+last touched by `64250a5f` "(feat) Engine rebuild: DSP overhaul, CPM deps, hygiene (#212)",
+which landed before the gate existed (#227), so it was never gated. Biggest CI rows:
+
+| scenario | work main → develop | wall main → develop |
+|---|---|---|
+| `effect-07` Auto Filter x8 | 9.91 M → 13.25 M (+34 %) | 10.81 → 15.64 ms |
+| `effect-21` Prism x8 | 58.21 M → 77.20 M (+33 %) | 47.90 → 75.65 ms |
+| `effect-00` EQ-8 x8 | 18.23 M → 11.79 M (−35 %) | 11.63 → 16.62 ms (+43 %) |
+
+Local wall time on Apple Silicon (`nota_perf run <id> 1`, best of 5, ms per 1 s of audio):
+
+| scenario | main | develop |
+|---|---|---|
+| Prism x8 | 13.8 | 24.3 (+76 %) |
+| EQ-8 x8 | 4.8 | 10.2 (+110 %) |
+| Auto Filter x8 | 4.2 | 6.0 (+43 %) |
+
+## Symptom
+
+Nota Prism, Nota EQ-8 and Nota Auto Filter use 40–110 % more CPU per block than in
+0.56.1 with the same settings and the same output; on a busy project that is the
+difference between headroom and dropouts. Expected: no slower than 0.56.1.
+
+## Reproduction
+
+1. Build the engine at `origin/main` and at `origin/develop` (Release), plus `tests/perf`
+ against each.
+2. `nota_perf run effect-21 1`, `effect-00`, `effect-07` with both builds, interleaved.
+3. develop is 1.4–2.1× slower on all three; `scripts/perf-gate.sh origin/main` on Linux
+ reports the same rows as FAIL.
+
+## Suspected Code Paths
+
+- `src/native/nota.engine/src/dsp/primitives/SvfFilter.cpp:SvfFilter::processAll()` /
+ `process()` / `processBlock()` — per-sample hot path, defined out of line; the engine
+ builds without LTO, so every sample in Prism (7 sections per channel), Auto Filter and
+ Compressor pays a call and the optimizer cannot keep state in registers. The body also
+ computes `v1/v2/v3` in `float` from `double` state and coefficients (a convert on every
+ operation, and less precision than the pre-#212 all-`double` TPT code in `AutoFilter.h`).
+- `src/native/nota.engine/src/devices/effects/Eq.cpp:Eq::process()` — "bands in series,
+ each in 64-sample blocks": each band runs `BiquadCascade::processBlock` over the whole
+ buffer, so every pass is bound by one biquad's recurrence latency. The pre-#212 `Eq.h`
+ ran all bands per frame, letting the core overlap band k of frame i+1 with band k+1 of
+ frame i. Fewer instructions, twice the time.
+- `src/native/nota.engine/src/dsp/primitives/BiquadCascade.cpp:processSampleL/R()` —
+ per-sample entry points, also out of line.
+
+## Root Cause Hypothesis
+
+High confidence. #212 moved shared DSP primitives from header-only into `.cpp` files
+(no LTO, so no cross-TU inlining) and restructured EQ-8 from sample-major to band-major.
+Confirmed experimentally: making `SvfFilter`'s hot methods inline with all-`double`
+math brings Prism back to 14.2 ms (main 13.8) and Auto Filter to 5.0 ms; a sample-major
+EQ-8 loop brings it to 5.8 ms (main 4.8). Enabling LTO alone helps Auto Filter and Prism
+but not EQ-8.
+
+## Proposed Remediation
+
+**Preferred**: (1) Define `SvfFilter::processAll`, `process` and `processBlock` inline in
+`SvfFilter.h`, computing in `double` throughout (as the pre-#212 code did) and rounding
+only the returned taps to `float`. (2) Add an inline `BiquadCascade::processFrame(double& l,
+double& r, BiquadChannel)` (and make `processSampleL/R` inline), and rewrite `Eq::process`'s
+band loop as `kCtrl`-frame chunks: rebuild the coefficients of gliding bands once per
+chunk, then run every frame through all active bands in series in `double`. This also
+removes the `float` rounding between bands.
+
+**Alternatives**:
+- Turn on `CMAKE_INTERPROCEDURAL_OPTIMIZATION` for `nota_engine` — fixes inlining
+ everywhere, but does nothing for EQ-8, lengthens link times on three platforms and
+ changes the build of every device; a bigger change than this bug needs.
+- Accept the regression with `perf-regression-accepted` — leaves users with the slower
+ devices.
+
+**Files likely to change**:
+- `src/native/nota.engine/src/dsp/primitives/SvfFilter.h`, `SvfFilter.cpp`
+- `src/native/nota.engine/src/dsp/primitives/BiquadCascade.h`, `BiquadCascade.cpp`
+- `src/native/nota.engine/src/devices/effects/Eq.cpp`
+
+**Tests to add or update**:
+- The Performance gate itself (`tests/perf` scenarios `effect-00`, `effect-07`,
+ `effect-21`, `effect-01`) locks the speed in.
+- Sound check: render the affected devices before and after the fix through the same
+ deterministic input and compare (null test); the difference must be at float-rounding
+ level (the double-precision change moves results only in the last bits).
+- `scripts/build.sh` smoke test (every Prism / Auto Filter / EQ preset applies and renders).
+
+## Risks & Considerations
+
+- `SvfFilter` math moving from float intermediates to double changes output in the last
+ bits for Prism, Auto Filter and Compressor; Prism's band-sum flatness must still hold.
+- EQ-8: glide coefficients now update for all gliding bands per chunk at the same frame
+ offsets as before (`kCtrl`), so the glide curve is unchanged; Mid/Side routing moves into
+ `processFrame` and is computed in double.
+- `BiquadCascade::processBlock` stays for DynamicEq / Eq3 / AutoGain, unchanged.
+- The other 16 FAIL rows (Delay, Flanger, Phaser, Chorus, Utility, Crush, Strata, Reverb,
+ Keys, Synth …, +2–27 % instructions, no wall-time change on ARM) come mostly from the
+ per-sample peak tracking that drives the new idle sleep — out of scope here, so the
+ release PR will still need `perf-regression-accepted` for those.
+
+## Open Questions
+
+- Auto Filter remains ~15 % and EQ-8 ~20 % above 0.56.1 on Apple Silicon after the fix;
+ x86 / Valgrind numbers come from the CI gate once the PR is open.
diff --git a/.specify/bugs/dsp-perf-regressions/fix.md b/.specify/bugs/dsp-perf-regressions/fix.md
new file mode 100644
index 00000000..258065db
--- /dev/null
+++ b/.specify/bugs/dsp-perf-regressions/fix.md
@@ -0,0 +1,90 @@
+# Bug Fix: Prism, EQ-8 and Auto Filter render up to 2× slower since the engine rebuild
+
+- **Slug**: dsp-perf-regressions
+- **Fixed**: 2026-10-23
+- **Assessment**: ./assessment.md
+- **Status**: applied
+
+## Summary
+
+`dsp::SvfFilter`'s per-sample methods are inline again and compute in `double`, and
+Nota EQ-8 runs every frame through all its bands (sample-major) instead of one band
+over the whole buffer at a time. Prism and EQ-8 are back within ~5–15 % of 0.56.1,
+Auto Filter within ~15 %, with the output unchanged to below −99 dB.
+
+## Changes
+
+| File | Change | Notes |
+|------|--------|-------|
+| `src/native/nota.engine/src/dsp/primitives/SvfFilter.h` | modified | `processAll` / `process` / `processBlock` defined inline; `processAll` math in `double` |
+| `src/native/nota.engine/src/dsp/primitives/SvfFilter.cpp` | modified | the three out-of-line definitions removed |
+| `src/native/nota.engine/src/dsp/primitives/BiquadCascade.h` | modified | `processSampleL/R` inline; new inline `processFrame(double& l, double& r, BiquadChannel)` (Stereo/Left/Right/Mid/Side) |
+| `src/native/nota.engine/src/dsp/primitives/BiquadCascade.cpp` | modified | out-of-line `processSampleL/R` removed |
+| `src/native/nota.engine/src/devices/effects/Eq.cpp` | modified | band loop: `kCtrl`-frame chunks, gliding bands rebuilt per chunk, then all active bands per frame in `double` |
+| `CHANGELOG.md` | modified | `[Unreleased]` → Fixed entry |
+
+## Diff Highlights (optional)
+
+```cpp
+// Eq::process — sample-major series chain
+for (int32_t i = 0; i < m; ++i) {
+ double l = p[i * 2], r = p[i * 2 + 1];
+ for (int a = 0; a < nAct; ++a) bands_[act[a]].processFrame(l, r, rt[act[a]]);
+ p[i * 2] = static_cast<float>(l);
+ p[i * 2 + 1] = static_cast<float>(r);
+}
+```
+
+## Tests Added or Updated
+
+- No new test files: the Performance gate scenarios `effect-00` (EQ-8), `effect-07`
+ (Auto Filter), `effect-21` (Prism) and `effect-01` (Compressor) already pin the speed,
+ and the smoke test's "every Prism / Auto Filter / EQ preset applies and renders" rows pin
+ that the devices still render.
+
+## Local Verification
+
+- Commands run:
+ - `nota_perf run <id> 1`, best of 5 interleaved rounds, Apple Silicon, ms per 1 s of audio
+ (main / develop / fix): EQ-8 4.78 / 10.21 / 5.48 · Prism 13.93 / 24.92 / 14.59 ·
+ Auto Filter 4.36 / 6.26 / 5.05 · Compressor 5.45 / 5.03 / 5.12 · Dynamic EQ-8
+ 12.31 / 11.36 / 9.97 · EQ-3 8.01 / 8.10 / 8.11 · Synth alone 1.23 / 1.22 / 1.22.
+ - Null test (C ABI harness: Synth track + the device, 3 s, defaults and 5 seeded random
+ parameter sets each with a mid-render change so glides run), develop vs fix, 24 renders:
+ EQ-8 and Compressor at defaults bit-identical; worst case anywhere: diff peak −106.9 dBFS,
+ diff RMS −99.0 dB below the signal (Auto Filter, random set 1); no non-finite samples.
+ Same-build renders are bit-identical, so the diffs are the double-precision change only.
+ - `scripts/build.sh` → engine, scanner self-test and managed build pass; smoke test
+ 3914 PASS / 1 FAIL: `RenderPoolTests` "overloaded: at most 7 late blocks within 50 ms
+ (<= 4)". Re-ran `dotnet run --project tests/Nota.SmokeTest -c Release` twice: FAIL
+ (9) then PASS (4). That scenario renders Synth + Reverb + Delay only — none touch
+ `SvfFilter`, `BiquadCascade` or EQ-8 — so it is the wall-clock burst check being flaky
+ on this machine, not this change.
+- Manual checks: none in the app UI (no UI change).
+
+## Deviations from Assessment
+
+None.
+
+## Follow-ups
+
+- The remaining instruction-count rows on the release PR (Delay, Flanger, Phaser, Chorus,
+ Utility, Crush, Strata, Reverb, Keys, Synth …) come from the idle-sleep peak tracking;
+ they still need `perf-regression-accepted` on the develop → main PR, or a separate change
+ that computes those peaks with the SIMD block helpers after the loop.
+- Auto Filter (~15 %) and EQ-8 (~15 %) are still a little above 0.56.1 on Apple Silicon;
+ x86 numbers come from the Performance gate on this PR.
+
+## Addendum — EQ-8 instruction count (PR #287 gate)
+
+The first push failed the Performance gate on `effect-00` (+22.6 % instructions vs develop,
+−30 % wall time) and, through the EQ-8 on every track, `silent-32` / `sparse-32` (+1.5 %):
+the per-frame band loop paid a routing switch, an index lookup and a `stages_` reload per
+band. When every active band is Stereo and none is gliding (the common case), `Eq::process`
+now copies all bands' sections into one contiguous chain on the stack, runs each frame
+through it and stores the state back; the general per-band path stays for Left / Right /
+Mid / Side and glides. `BiquadCascade` gains `bank(int)` for that. Output is unchanged
+(the null test gives the same figures as before, bit-identical at defaults). Apple Silicon:
+EQ-8 x8 4.40 ms (develop 9.86, 0.56.1 4.79); instructions retired per second of audio
+(`/usr/bin/time -l`, whole process) 111 M vs develop 133 M; silent-32 653 vs 656 M,
+sparse-32 1688 vs 1716 M.
diff --git a/.specify/bugs/dsp-perf-regressions/test.md b/.specify/bugs/dsp-perf-regressions/test.md
new file mode 100644
index 00000000..6825756c
--- /dev/null
+++ b/.specify/bugs/dsp-perf-regressions/test.md
@@ -0,0 +1,62 @@
+# Bug Verification: Prism, EQ-8 and Auto Filter render up to 2× slower since the engine rebuild
+
+- **Slug**: dsp-perf-regressions
+- **Tested**: 2026-10-23
+- **Assessment**: ./assessment.md
+- **Fix**: ./fix.md
+- **Result**: partial
+
+## Summary
+
+The wall-time slowdown no longer reproduces on Apple Silicon: Prism and EQ-8 drop from
+1.8× / 2.1× of 0.56.1 to 1.05× / 1.2×, Auto Filter from 1.4× to 1.15×. The output matches
+develop to below −99 dB, and bit for bit for every device that only shares the touched
+headers. No regressions were found. Partial only because reproduction step 3 — the Linux /
+Valgrind instruction-count gate — could not run locally and is left to the Performance
+workflow on the PR.
+
+## Checks Performed
+
+| Check | Command / Action | Result | Notes |
+|-------|------------------|--------|-------|
+| Fix binary matches the tree | `cmake --build /tmp/nperf/engine-fix --target nota_engine` | pass | "no work to do" — built from the current working tree |
+| Reproduction (post-fix), wall time | `nota_perf run <id> 1`, best of 5, main / develop / fix interleaved, all 16 scenarios that failed the gate | pass | the three real regressions fixed; the other 13 within noise of develop |
+| Reproduction, instruction-count gate | `scripts/perf-gate.sh origin/develop` (Linux + Valgrind) | not-run | no Valgrind on macOS, Docker daemon not running; the Performance workflow runs it on the PR |
+| Sound unchanged (null test) | C ABI harness: Synth + device, 3 s, defaults + 5 seeded random sets with a mid-render change, develop vs fix; EQ-8, Compressor, Auto Filter, Prism, Dynamic EQ-8, EQ-3 (36 renders) | pass | worst diff peak −106.9 dBFS, RMS −99.0 dB below signal (Auto Filter); Dynamic EQ-8 and EQ-3 bit-identical; no non-finite samples |
+| Regression suite | `scripts/build.sh` (engine, scanner self-test, managed build, smoke test) | pass (1 flaky timing budget) | 3914 PASS / 1 FAIL `RenderPoolTests` burst budget; see below |
+| Smoke re-run | `dotnet run --project tests/Nota.SmokeTest -c Release` ×2 | fail, then pass | the same budget: 9 then 4 (limit 4) |
+| Lint / format | `clang-format` | skipped | not installed; CI does not check formatting |
+
+## Output Excerpts
+
+```
+id main develop fix
+effect-00 EQ-8 4.82 10.19 5.85
+effect-21 Prism 13.70 24.37 14.36
+effect-07 AutoFlt 4.25 5.93 4.87
+effect-01 Comp 5.27 5.14 5.06
+effect-02 Reverb 33.15 32.74 32.60
+```
+
+```
+[FAIL] overloaded: at most 7 late blocks within 50 ms (<= 4: no bursts when the pool re-checks the load)
+```
+
+That check is a `TimingBudget` (not enforced under `CI`). On develop's own CI runs before
+this change the same number was 5, 6, 9, 24, 26, 27, 28 and 35, so it exceeds 4 without the
+fix too; its scenario renders Synth + Reverb + Delay, none of which touch the changed code.
+
+## Residual Risks
+
+- x86 / Valgrind instruction counts not measured locally; the gate on the PR decides
+ `effect-00`, `effect-07`, `effect-21`, `effect-01`.
+- Auto Filter (~15 %) and EQ-8 (~20 %) remain a little above 0.56.1 on Apple Silicon.
+- The other 16 rows of the release-PR gate (idle-sleep peak tracking) are out of scope and
+ still need `perf-regression-accepted` on develop → main.
+- Windows / Linux builds not run locally (`build-win.ps1`, `build-linux.sh`); CI covers them.
+
+## Recommendation
+
+Hold for the CI Performance gate on the PR: if `effect-00`, `effect-07` and `effect-21`
+pass there (or show only the residual Auto Filter / EQ-8 overhead), close the bug. The
+burst-budget smoke failure is pre-existing noise and does not block this change.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cf8378ce..27782ab3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,12 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
## [Unreleased]
+### Fixed
+- **Nota Prism, Nota EQ-8 and Nota Auto Filter use as little CPU as before the engine
+ rebuild**: Prism and EQ-8 had become up to twice as heavy, Auto Filter about 40 %
+ heavier, with the same sound. The shared filter core runs inline again and EQ-8 runs all
+ its bands per sample; the output is unchanged to well below the last bit of 16-bit audio.
+
## [0.57.1] — 2026-10-22
### Added
diff --git a/src/native/nota.engine/src/devices/effects/Eq.cpp b/src/native/nota.engine/src/devices/effects/Eq.cpp
index 9d09a369..bebda3ec 100644
--- a/src/native/nota.engine/src/devices/effects/Eq.cpp
+++ b/src/native/nota.engine/src/devices/effects/Eq.cpp
@@ -2,7 +2,7 @@
// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
//
// Nota EQ-8 implementation . Audio path: shared
-// dsp::BiquadCascade sections in 64-sample blocks (routing branch hoisted),
+// dsp::BiquadCascade sections run sample-major (all bands per frame, in double),
// FastMath pitch/dB mapping, auto-sleep on silent stretches. Everything else
// (params, analyzer, blob-irrelevant text) is verbatim.
@@ -247,15 +247,54 @@ void Eq::process(float* buf, int32_t frames) {
++w;
}
- // Bands in series, each in 64-sample blocks; gliding bands rebuild every kCtrl.
- for (int b = 0; b < kBands; ++b) {
- if (!on[b]) continue;
- if (!glMoving_[b]) {
- bands_[b].processBlock(buf, frames, routing(ch[b]));
- continue;
+ // Bands in series, sample-major: every frame runs through all active bands before
+ // the next, so the out-of-order core overlaps the bands' recurrences across frames
+ // (band-major passes are each bound by one biquad's latency). Gliding bands rebuild
+ // their coefficients every kCtrl frames.
+ int act[kBands], nAct = 0;
+ dsp::BiquadChannel rt[kBands];
+ for (int b = 0; b < kBands; ++b)
+ if (on[b]) {
+ rt[b] = routing(ch[b]);
+ act[nAct++] = b;
+ }
+ bool flat = !moving;
+ for (int a = 0; a < nAct && flat; ++a) flat = rt[act[a]] == dsp::BiquadChannel::Stereo;
+ if (flat) {
+ // Common case — every active band Stereo and none gliding: the bands in series are
+ // one chain of sections. Run it from a contiguous copy, then store the state back.
+ dsp::BiquadSection chL[kBands * kMaxSec], chR[kBands * kMaxSec];
+ int n = 0;
+ for (int a = 0; a < nAct; ++a) {
+ dsp::BiquadCascade& bc = bands_[act[a]];
+ for (int k = 0; k < bc.stages(); ++k, ++n) {
+ chL[n] = bc.bank(0)[k];
+ chR[n] = bc.bank(1)[k];
+ }
+ }
+ for (int32_t i = 0; i < frames; ++i) {
+ double l = buf[i * 2], r = buf[i * 2 + 1];
+ for (int k = 0; k < n; ++k) {
+ l = chL[k].run(l);
+ r = chR[k].run(r);
+ }
+ buf[i * 2] = static_cast<float>(l);
+ buf[i * 2 + 1] = static_cast<float>(r);
+ }
+ n = 0;
+ for (int a = 0; a < nAct; ++a) {
+ dsp::BiquadCascade& bc = bands_[act[a]];
+ for (int k = 0; k < bc.stages(); ++k, ++n) {
+ bc.bank(0)[k] = chL[n];
+ bc.bank(1)[k] = chR[n];
+ }
}
- for (int32_t off = 0; off < frames; off += kCtrl) {
- const int32_t m = off + kCtrl <= frames ? kCtrl : frames - off;
+ }
+ for (int32_t off = 0; off < frames && !flat; off += kCtrl) {
+ const int32_t m = off + kCtrl <= frames ? kCtrl : frames - off;
+ for (int a = 0; a < nAct; ++a) {
+ const int b = act[a];
+ if (!glMoving_[b]) continue;
glF_[b] = settle(glF_[b] + (tF[b] - glF_[b]) * glideC, tF[b], 1e-5);
glG_[b] = settle(glG_[b] + (tG[b] - glG_[b]) * glideC, tG[b], 1e-4);
glQ_[b] = settle(glQ_[b] + (tQ[b] - glQ_[b]) * glideC, tQ[b], 1e-5);
@@ -264,10 +303,16 @@ void Eq::process(float* buf, int32_t frames) {
cb, ty[b], sl[b], sr, fast_math::exp2f((float)glF_[b]), glG_[b], fast_math::exp2f((float)glQ_[b]));
bands_[b].setStages(n);
for (int k = 0; k < n; ++k) bands_[b].setSection(k, cb[k]);
- bands_[b].processBlock(buf + off * 2, m, routing(ch[b]));
+ glMoving_[b] = glF_[b] != tF[b] || glG_[b] != tG[b] || glQ_[b] != tQ[b];
+ moving = moving || glMoving_[b];
+ }
+ float* p = buf + off * 2;
+ for (int32_t i = 0; i < m; ++i) {
+ double l = p[i * 2], r = p[i * 2 + 1];
+ for (int a = 0; a < nAct; ++a) bands_[act[a]].processFrame(l, r, rt[act[a]]);
+ p[i * 2] = static_cast<float>(l);
+ p[i * 2 + 1] = static_cast<float>(r);
}
- glMoving_[b] = glF_[b] != tF[b] || glG_[b] != tG[b] || glQ_[b] != tQ[b];
- moving = moving || glMoving_[b];
}
(void)moving;
diff --git a/src/native/nota.engine/src/dsp/primitives/BiquadCascade.cpp b/src/native/nota.engine/src/dsp/primitives/BiquadCascade.cpp
index f11d3908..b1f866f8 100644
--- a/src/native/nota.engine/src/dsp/primitives/BiquadCascade.cpp
+++ b/src/native/nota.engine/src/dsp/primitives/BiquadCascade.cpp
@@ -34,14 +34,6 @@ void BiquadCascade::reset() noexcept {
for (auto& s : bank) s.reset();
}
-double BiquadCascade::processSampleL(double x) NOTA_RT_SAFE {
- return runBank(0, x);
-}
-
-double BiquadCascade::processSampleR(double x) NOTA_RT_SAFE {
- return runBank(1, x);
-}
-
void BiquadCascade::processBlock(float* buf, int32_t frames, BiquadChannel ch) NOTA_RT_SAFE {
if (buf == nullptr || frames <= 0 || stages_ <= 0) return;
if (ch == BiquadChannel::Stereo) {
diff --git a/src/native/nota.engine/src/dsp/primitives/BiquadCascade.h b/src/native/nota.engine/src/dsp/primitives/BiquadCascade.h
index 45c00ce1..429b1198 100644
--- a/src/native/nota.engine/src/dsp/primitives/BiquadCascade.h
+++ b/src/native/nota.engine/src/dsp/primitives/BiquadCascade.h
@@ -56,11 +56,37 @@ class BiquadCascade {
void setStages(int n) noexcept;
int stages() const noexcept { return stages_; }
+ // Direct access to a bank's sections (bank 0 = L/Mid/Side, 1 = R), for hosts that
+ // flatten several cascades into one chain.
+ BiquadSection* bank(int b) noexcept { return st_[b]; }
void setSection(int i, const BiquadCoeffs& c) noexcept;
void reset() noexcept;
- double processSampleL(double x) NOTA_RT_SAFE;
- double processSampleR(double x) NOTA_RT_SAFE;
+ double processSampleL(double x) NOTA_RT_SAFE { return runBank(0, x); }
+ double processSampleR(double x) NOTA_RT_SAFE { return runBank(1, x); }
+ // One stereo frame with channel routing, in double (for sample-major series chains).
+ void processFrame(double& l, double& r, BiquadChannel ch) NOTA_RT_SAFE {
+ switch (ch) {
+ case BiquadChannel::Stereo:
+ l = runBank(0, l);
+ r = runBank(1, r);
+ break;
+ case BiquadChannel::Left: l = runBank(0, l); break;
+ case BiquadChannel::Right: r = runBank(1, r); break;
+ case BiquadChannel::Mid: {
+ const double side = (l - r) * 0.5, f = runBank(0, (l + r) * 0.5);
+ l = f + side;
+ r = f - side;
+ break;
+ }
+ case BiquadChannel::Side: {
+ const double mid = (l + r) * 0.5, f = runBank(0, (l - r) * 0.5);
+ l = mid + f;
+ r = mid - f;
+ break;
+ }
+ }
+ }
// Interleaved stereo block with channel routing (branch hoisted outside
// the 64-sample chunks). Left/Mid/Side run on bank 0, Right on bank 1.
void processBlock(float* buf, int32_t frames, BiquadChannel ch) NOTA_RT_SAFE;
diff --git a/src/native/nota.engine/src/dsp/primitives/SvfFilter.cpp b/src/native/nota.engine/src/dsp/primitives/SvfFilter.cpp
index 9aa544c3..aaec6cb2 100644
--- a/src/native/nota.engine/src/dsp/primitives/SvfFilter.cpp
+++ b/src/native/nota.engine/src/dsp/primitives/SvfFilter.cpp
@@ -41,25 +41,6 @@ void SvfFilter::update() NOTA_RT_SAFE {
linGain_ = fast_math::dbToLin(gainDb_);
}
-float SvfFilter::process(float x) NOTA_RT_SAFE {
- float lp, bp, hp, notch;
- processAll(x, lp, bp, hp, notch);
- switch (mode_) {
- case Mode::LowPass: return lp;
- case Mode::BandPass: return bp;
- case Mode::HighPass: return hp;
- case Mode::Notch: return notch;
- case Mode::Peak: return lp - hp;
- case Mode::Allpass: return x - 2.0f * (float)k_ * bp;
- case Mode::Bell: {
- const float peak = lp - hp;
- return x + (linGain_ - 1.0f) * peak; // proportional-Q bell (boost & cut)
- }
- case Mode::LowShelf: return x + (linGain_ - 1.0f) * lp;
- case Mode::HighShelf: return x + (linGain_ - 1.0f) * hp;
- }
- return lp;
-}
void SvfFilter::setCoeffs(double a1, double a2, double a3, double k) NOTA_RT_SAFE {
a1_ = a1;
@@ -68,22 +49,7 @@ void SvfFilter::setCoeffs(double a1, double a2, double a3, double k) NOTA_RT_SAF
k_ = k;
}
-void SvfFilter::processBlock(float* buf, int32_t n) NOTA_RT_SAFE {
- if (buf == nullptr || n <= 0) return;
- for (int32_t i = 0; i < n; ++i) buf[i] = process(buf[i]);
-}
-void SvfFilter::processAll(float x, float& lp, float& bp, float& hp, float& notch) NOTA_RT_SAFE {
- const float v3 = x - ic2_;
- const float v1 = a1_ * ic1_ + a2_ * v3;
- const float v2 = ic2_ + a2_ * ic1_ + a3_ * v3;
- ic1_ = 2.0f * v1 - ic1_;
- ic2_ = 2.0f * v2 - ic2_;
- bp = v1;
- lp = v2;
- hp = x - k_ * v1 - v2;
- notch = lp + hp;
-}
void Lr4Splitter::setSampleRate(double sr) noexcept {
lp1_.setSampleRate(sr);
diff --git a/src/native/nota.engine/src/dsp/primitives/SvfFilter.h b/src/native/nota.engine/src/dsp/primitives/SvfFilter.h
index fae9c79c..936acb06 100644
--- a/src/native/nota.engine/src/dsp/primitives/SvfFilter.h
+++ b/src/native/nota.engine/src/dsp/primitives/SvfFilter.h
@@ -82,5 +82,46 @@ class Lr4Splitter {
SvfFilter lp1_, lp2_, hp1_, hp2_;
};
+// Per-sample hot path, inline: the engine builds without LTO, so an out-of-line call
+// here costs every sample of every caller. Math runs in double like the state.
+inline void SvfFilter::processAll(float x, float& lp, float& bp, float& hp, float& notch) NOTA_RT_SAFE {
+ const double xd = x;
+ const double v3 = xd - ic2_;
+ const double v1 = a1_ * ic1_ + a2_ * v3;
+ const double v2 = ic2_ + a2_ * ic1_ + a3_ * v3;
+ ic1_ = 2.0 * v1 - ic1_;
+ ic2_ = 2.0 * v2 - ic2_;
+ const double hpd = xd - k_ * v1 - v2;
+ bp = (float)v1;
+ lp = (float)v2;
+ hp = (float)hpd;
+ notch = (float)(v2 + hpd);
+}
+
+inline float SvfFilter::process(float x) NOTA_RT_SAFE {
+ float lp, bp, hp, notch;
+ processAll(x, lp, bp, hp, notch);
+ switch (mode_) {
+ case Mode::LowPass: return lp;
+ case Mode::BandPass: return bp;
+ case Mode::HighPass: return hp;
+ case Mode::Notch: return notch;
+ case Mode::Peak: return lp - hp;
+ case Mode::Allpass: return x - 2.0f * (float)k_ * bp;
+ case Mode::Bell: {
+ const float peak = lp - hp;
+ return x + (linGain_ - 1.0f) * peak; // proportional-Q bell (boost & cut)
+ }
+ case Mode::LowShelf: return x + (linGain_ - 1.0f) * lp;
+ case Mode::HighShelf: return x + (linGain_ - 1.0f) * hp;
+ }
+ return lp;
+}
+
+inline void SvfFilter::processBlock(float* buf, int32_t n) NOTA_RT_SAFE {
+ if (buf == nullptr || n <= 0) return;
+ for (int32_t i = 0; i < n; ++i) buf[i] = process(buf[i]);
+}
+
} // namespace dsp
} // namespace nota