Music XML updates and optimizations
This commit is contained in:
@@ -301,6 +301,138 @@ complete.**
|
||||
New work beyond this group is scoped from the **Deferred / Future** and **Not
|
||||
planned** lists below as demand appears.
|
||||
|
||||
### Generator Consolidation + RT Performance group (GP-1 … GP-9)
|
||||
|
||||
Goal: collapse remaining duplicated per-sample / per-init Generator code into
|
||||
shared helpers, and land a set of benchmark-gated real-time performance wins on
|
||||
the audio render path (`_computeSamples` / `calculatedSamples`). Sourced from an
|
||||
architecture sweep of `Sources/Lyrebird/Generators/` + `GeneratorCore/`.
|
||||
|
||||
Splits into two work-streams: **dedup** (no behaviour change, gated on tests
|
||||
only) and **perf** (gated on before/after benchmark + tests + review). Each
|
||||
phase is its own branch off `main` per the standing phase-branch policy.
|
||||
|
||||
**Locked decisions (with Josh):**
|
||||
|
||||
- **vDSP/vForce strategy = split-path, keep scalar fallback.** Each vectorised
|
||||
generator branches on `n == count` (upstream block full-length — the normal
|
||||
case at *any* block size, including small control blocks like 64). Only the
|
||||
rare short-upstream-block case (`n < count`) falls to the existing scalar
|
||||
loop. The vDSP/vForce call fires for 64-sample control blocks too — the gate
|
||||
is upstream-fullness, not absolute block size. If benchmarks show vDSP call
|
||||
overhead losing at *tiny* counts (1/2/4), add a `count >= minVectorCount`
|
||||
threshold (strictly better than "vDSP everywhere"). Revisit a
|
||||
"vDSP-everywhere + zero-pad" variant only if the split-path data warrants it.
|
||||
- **Benchmark harness = existing `Sources/LyrebirdBenchmark/main.swift`.** Add
|
||||
one timed case per perf phase (`ContinuousClock`, warmup + N timed iters,
|
||||
reports ns/block + ns/sample; `OfflineDriver` for in-context `processBlock`).
|
||||
Run release only: `swift run -c release LyrebirdBenchmark`. The control-block
|
||||
sweep (512 → 1) already in the harness shows the win-curve across block sizes.
|
||||
- **Per-phase gate.** Dedup phases: `swift test --no-parallel` green +
|
||||
`/lyrebird_review` clean. Perf phases: same, *plus* a committed before/after
|
||||
benchmark delta; keep the change only if it shows a real win with no test
|
||||
regression. Capture baseline numbers in the phase branch's first commit.
|
||||
|
||||
#### Phase GP-0 — Benchmark baseline capture
|
||||
|
||||
Add timed cases to `LyrebirdBenchmark` for every perf target *before* touching
|
||||
code: `BinaryOpGenerator` (scalar-mul, vector-add), unary math (`Sin`/`Exp`/
|
||||
`Sqrt`/`Abs`), `LinLin.Audio`, SVF generator-driven `freq`, `Chorus.Audio`.
|
||||
Run the control-block sweep on each. Commit the baseline numbers as the
|
||||
reference all GP perf phases diff against. No production code change.
|
||||
|
||||
#### Phase GP-1 — Trivial / low-risk dedup (no perf risk) ✓ *(complete — merged to main)*
|
||||
|
||||
Pure consolidation, semantically identical, gated on tests + review only:
|
||||
|
||||
- **D1** — Merge byte-identical `normalizeLFPhase` / `normalizeBLPhase` into one
|
||||
`normalizeOscPhase(_:)` helper. 8 oscillator `.Control` callers
|
||||
(LF/Osc Sawtooth/Square/Triangle/DutyCycle).
|
||||
- **D7** — Add `lyrebirdTwoPi` to `Math/LyrebirdConstants.swift`; replace 5
|
||||
inline `let twoPi = 2.0 * .pi` locals (Chorus/Flanger/Phaser/Jitter/
|
||||
ScannedSynthesizer). Removes magic-number-rule smell on the hot path.
|
||||
- **D4** — Adopt existing `resolveGeneratorOrScalar(...)` in `Chorus`/`Flanger`/
|
||||
`Phaser._computeSamples` — replaces ~17 hand-rolled 8-line input-resolution
|
||||
blocks. Helper already proven in Flute/Clarinet/Pan*/PlateReverb.
|
||||
- **D2** — Extract `computeButterworthQs(order:) -> [Double]` (new
|
||||
`Filters/ButterworthHelpers.swift`); 4 Butterworth filters call it at init.
|
||||
|
||||
#### Phase GP-2 — SVF helper extraction + coefficient interpolation (D6 + P4) ✓ *(complete — merged to main; −5.9% on gen-driven-freq bench)*
|
||||
|
||||
Bundles a dedup and a perf win that touch the same code:
|
||||
|
||||
- **D6** — Extract `runSVFBlock(...)` (Chamberlin recurrence + denormal flush +
|
||||
zero-fill); `SVF.Audio` and `SVF.Control._computeSamples` collapse to setup +
|
||||
one call + `mulAdd`. Name `svfMinQDamping` / `svfFCoeffMax` constants.
|
||||
- **P4** — In the generator-driven-`freq` path, replace per-sample
|
||||
`Darwin.sin(piOverSr·freq)` with block-boundary `fFirst`/`fLast` + linear
|
||||
interpolation (same technique as `runRBJBiquadBlock`). Eliminates ~510 of 512
|
||||
`sin` calls/block on that path. Benchmark the gen-driven-freq case.
|
||||
|
||||
Gate: tests + review + benchmark (perf component).
|
||||
|
||||
#### Phase GP-3 — Butterworth LP/HP cascade engine extraction (D3) ✓ *(complete — merged to main; ~250 dup lines removed, behavior-identical)*
|
||||
|
||||
- **D3** — Extract shared background-thread vDSP cascade machinery
|
||||
(`runScalar`/`runVDSP`/`runAudioRate`/deinit drain + the `_vdsp*Queue` set)
|
||||
into a `ButterworthCascadeEngine` in `ButterworthHelpers.swift`. LP and HP
|
||||
inject two coefficient closures and become thin wrappers. Removes ~250 lines
|
||||
of duplicated thread lifecycle. Medium risk — match the thread teardown
|
||||
exactly. Gate: tests + review. Sets up GP-9.
|
||||
|
||||
#### Phase GP-4 — Unary math vForce/vDSP fast path (P3) ✓ *(complete — merged to main; −66.9% / ~3× on the 4-op unary chain)*
|
||||
|
||||
- **P3** — Split-path vectorisation for `Sin`/`Cos`/`Exp`/`Log`/`Sqrt`/`Floor`/
|
||||
`Ceil` (`vvsin`/`vvcos`/`vvexp`/`vvlog`/`vvsqrt`/`vvfloor`/`vvceil`) and
|
||||
`Abs` (`vDSP_vabsD`). `n == count` → vectorised; `n < count` → existing scalar
|
||||
loop. No allocation (write into pre-zeroed `_result`). Highest single-generator
|
||||
throughput win (~4–10×). Benchmark each across the control-block sweep; apply
|
||||
`minVectorCount` threshold if tiny blocks regress.
|
||||
|
||||
#### Phase GP-5 — `BinaryOpGenerator` enum dispatch + vDSP (P2) ✓ *(complete — merged to main; gen×gen −56%, gen×scalar −72%)*
|
||||
|
||||
- **P2** — Replace the stored `op: (Double,Double)->Double` closure with an
|
||||
operator enum (`.add`/`.subtract`/`.multiply`/`.divide`) classified at init;
|
||||
dispatch aligned gen-vs-gen / gen-vs-scalar paths to `vDSP_vaddD`/`vsubD`/
|
||||
`vmulD`/`vdivD`/`vsaddD`/`vsmulD`. Keep the per-sample closure fallback for
|
||||
non-arithmetic / unaligned-count cases. Highest *graph-wide* win — every
|
||||
`osc * 0.5 + env` chain. Preserve IEEE-754 divide-by-zero behaviour. Medium
|
||||
risk — enumerate all variants, keep closure escape hatch. Benchmark scalar-mul
|
||||
+ vector-add cases.
|
||||
|
||||
#### Phase GP-6 — `LinLin` vDSP fast path (P7) ✓ *(complete — merged to main; −26.9%. LinExp/ExpLin deferred)*
|
||||
|
||||
- **P7** — `LinLin.Audio` → single `vDSP_vsmsaD` (`a·x + b`, coefficients
|
||||
hoisted out of loop; range params are always block-scalar so unconditional).
|
||||
Short-block fallback keeps the exact per-sample formula.
|
||||
- *Deferred:* `LinExp`/`ExpLin` (build the linear stage via vDSP then `vvexp` —
|
||||
needs a pre-allocated scratch buffer at init; modest incremental win, revisit
|
||||
if a profile flags them).
|
||||
|
||||
#### Phase GP-7 — Power-of-two delay-line wrapping (P5) ✓ *(complete — merged to main; Chorus −3.3%)*
|
||||
|
||||
- **P5** — `Chorus`/`Flanger` circular delay lines: size up to next power of two
|
||||
at init, replace per-sample `% delayLineCount` (3–4 per sample) with
|
||||
`& (delayLineCount - 1)`. ~2× delay-buffer memory (≈64 KB at max delay) for
|
||||
~6–9 cycles/sample saved. Add init-time `roundUpToPowerOfTwo(_:)`. Benchmark
|
||||
`Chorus.Audio`.
|
||||
|
||||
#### Phase GP-8 — Butterworth band-pass / band-reject vDSP cascade (P6) ✓ *(complete — merged to main; shared ButterworthSectionEngine, BP/BR gain vDSP + dedup)*
|
||||
|
||||
- **P6** — Extend the GP-3 `ButterworthCascadeEngine` vDSP path to
|
||||
`ButterworthBandPass` (sequenced HP→LP) and `ButterworthBandReject` (parallel
|
||||
LP+HP summed via `vDSP_vaddD`). Matches the LP/HP acceleration. Depends on
|
||||
GP-3. Band-reject needs two vDSP setups + dual kill-queue drain. Benchmark a
|
||||
4th-order bandpass.
|
||||
|
||||
**Sequencing:** GP-0 (baseline) → GP-1 (safe dedup) → GP-2/GP-3 (helper
|
||||
extractions, GP-3 before GP-8) → GP-4/GP-5 (highest-value perf) → GP-6/GP-7 →
|
||||
GP-8. Each lands on `main` via `--no-ff` before the next starts, per policy.
|
||||
|
||||
**Not pursued:** D5 (`OscSin.Audio` inlined switch) — intentional audio-rate
|
||||
choice (three branchless loops vs per-sample function call); leave as-is, revisit
|
||||
only if `OscillatorTableReadHelpers` gains a bitmask-wrap variant.
|
||||
|
||||
### Longer-term — Not planned
|
||||
|
||||
#### Phase 96b — Ableton Link *(not planned)*
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
# GP Performance Baseline
|
||||
|
||||
Reference numbers for the Generator Consolidation + RT Performance group
|
||||
(GP-0 … GP-8, see `docs/00-working-order.md`). Each perf phase diffs its
|
||||
before/after against this table.
|
||||
|
||||
**Harness:** `Sources/LyrebirdBenchmark/main.swift`, GP section.
|
||||
**Command:** `swift run -c release LyrebirdBenchmark` (release build mandatory).
|
||||
**Graph:** 8 voices per target, each `target → Pan2 → Out`, driven via
|
||||
`OfflineDriver`; engine advances segment serial per block (no fan-out cache
|
||||
artifact). Swept at `cbs=512` (1 control tick/callback) and `cbs=64`
|
||||
(8 sub-blocks/callback).
|
||||
|
||||
> Absolute ns vary by machine/thermal state. What matters is the **delta** on
|
||||
> the same machine before vs after a change. Re-run the baseline on the working
|
||||
> machine if comparing across hardware.
|
||||
|
||||
## Baseline (captured on `gp-0-benchmark-baseline`)
|
||||
|
||||
| Target | Phase | cbs=512 ns/block | cbs=512 ns/sample | cbs=64 ns/block |
|
||||
|---|---|---|---|---|
|
||||
| BinaryOp gen×gen / gen+gen | GP-5 | 141716.7 | 276.79 | 141195.9 |
|
||||
| BinaryOp gen×scalar / +scalar | GP-5 | 79927.6 | 156.11 | 79395.5 |
|
||||
| Unary math Exp(Sqrt(Abs(Sin))) | GP-4 | 93944.7 | 183.49 | 94131.2 |
|
||||
| LinLin.Audio | GP-6 | 27768.1 | 54.23 | 27561.8 |
|
||||
| SVF.Audio gen-driven freq | GP-2 | 80005.9 | 156.26 | 78595.2 |
|
||||
| Chorus.Audio | GP-7 | 93432.5 | 182.49 | 93420.9 |
|
||||
|
||||
`blockSize=512 voices=8 warmup=500 iterations=10000`
|
||||
|
||||
Note: control block size has negligible effect on these targets — all are
|
||||
`.Audio`-rate generators whose inner loop runs at audio rate regardless of the
|
||||
control sub-block split. The cbs=64 column is retained as a regression guard
|
||||
(a change must not introduce sub-block sensitivity).
|
||||
|
||||
## How each phase reports
|
||||
|
||||
Each GP perf phase appends an "After" row (or a side-by-side block) under its
|
||||
section here with the same command, same machine, and states the delta as a
|
||||
percentage. Keep the change only if the delta is a real win with no
|
||||
`swift test --no-parallel` regression.
|
||||
|
||||
## Results
|
||||
|
||||
### GP-2 — SVF helper extraction + block-boundary cutoff interpolation
|
||||
|
||||
| Target | Before ns/sample | After ns/sample | Delta |
|
||||
|---|---|---|---|
|
||||
| SVF.Audio gen-driven freq (cbs=512) | 156.26 | 147.10 | −5.9% |
|
||||
|
||||
Graph-level number; the SVF inner-loop saving is larger but diluted by the
|
||||
constant OscSin-input / OscSin-LFO / Pan2 / Out overhead in the bench voice.
|
||||
Faithful: per-sample `freq > 0 → silence` guard preserved exactly; slow cutoff
|
||||
motion is numerically ≈ identical to per-sample `sin()`. Full suite 4882/4882.
|
||||
|
||||
### GP-4 — unary math vForce/vDSP fast path
|
||||
|
||||
| Target | Before ns/sample | After ns/sample | Delta |
|
||||
|---|---|---|---|
|
||||
| Unary math Exp(Sqrt(Abs(Sin))) (cbs=512) | 183.49 | 60.78 | −66.9% |
|
||||
|
||||
Split-path vectorisation of Sin/Cos/Exp/Log/Sqrt/Floor/Ceil (`vvsin`/`vvcos`/
|
||||
`vvexp`/`vvlog`/`vvsqrt`/`vvfloor`/`vvceil`) and Abs (`vDSP_vabsD`) via the shared
|
||||
`unaryVector*` helpers (`Generators/Math/UnaryMathVectorHelpers.swift`). The
|
||||
bench chains 4 of these ops, so the ~3× speedup reflects the stacked saving.
|
||||
vForce transcendentals are within tolerance of `Foundation.*` (suite asserts
|
||||
`< 1e-10`); floor/ceil/abs are exact. Full suite 4883/4883.
|
||||
|
||||
### GP-5 — BinaryOpGenerator kind dispatch + vDSP
|
||||
|
||||
| Target | Before ns/sample | After ns/sample | Delta |
|
||||
|---|---|---|---|
|
||||
| BinaryOp gen×gen / gen+gen (cbs=512) | 276.79 | 120.97 | −56.3% |
|
||||
| BinaryOp gen×scalar / +scalar (cbs=512) | 156.11 | 44.16 | −71.7% |
|
||||
|
||||
`op` closure replaced by a `BinaryOpKind` enum classified at init (operator
|
||||
overloads pass `.add/.subtract/.multiply/.divide`; the closure init still exists
|
||||
for arbitrary ops → `kind=nil` → closure fallback). Aligned generator rows
|
||||
dispatch to vDSP (`vDSP_vaddD/vmulD/vsubD/vdivD`, `vsaddD/vsmulD/vsdivD`,
|
||||
`vsmsaD/svdivD`). Subtract via `+(-s)` / `vsmsaD`, divide via true-division
|
||||
routines (never reciprocal-multiply) → **bit-identical** to the scalar loop, so
|
||||
no tolerance concern; only arg-order risk, covered by the full suite + new
|
||||
order-sensitive tests. Highest graph-wide win (BinaryOp is ubiquitous). Full
|
||||
suite 4883→4887/4887 (4 new tests).
|
||||
|
||||
### GP-6 — LinLin.Audio vDSP_vsmsaD
|
||||
|
||||
| Target | Before ns/sample | After ns/sample | Delta |
|
||||
|---|---|---|---|
|
||||
| LinLin.Audio (cbs=512) | 54.23 | 39.66 | −26.9% |
|
||||
|
||||
The range params are always block-scalar (`floatValue`), so the affine map
|
||||
`f(x) = a·x + b` (`a = outRange/inRange`, `b = outLo − inLo·a`) applies
|
||||
unconditionally — full block in one `vDSP_vsmsaD`. Short upstream blocks keep
|
||||
the original exact per-sample formula (byte-identical fallback). The affine
|
||||
reorder is within the suite's `< 1e-8` tolerance. LinLin is a cheap op so the
|
||||
graph-level win is moderate (Osc/Pan2/Out dominate the bench voice). Full suite
|
||||
4887/4887.
|
||||
|
||||
### GP-7 — power-of-two delay-line wrap (Chorus / Flanger)
|
||||
|
||||
| Target | Before ns/sample | After ns/sample | Delta |
|
||||
|---|---|---|---|
|
||||
| Chorus.Audio (cbs=512) | 182.49 | 176.45 | −3.3% |
|
||||
|
||||
Delay buffers rounded up to a power of two (shared `lyrebirdNextPowerOfTwo`);
|
||||
the 5 (Chorus) / 3 (Flanger) per-sample `% delayLineCount` index wraps become
|
||||
`& delayMask`. The semantic max delay (`_maxDelayFrac`) is kept separate from
|
||||
the over-allocated buffer length, so the audible delay range and the delayed
|
||||
content are unchanged (larger ring, identical relative reads → bit-identical
|
||||
output; Chorus/Flanger tests pass). Modest win — the two per-sample LFO `sin()`
|
||||
calls dominate, not the modulo. Aligns Chorus/Flanger with the pow2-delay
|
||||
convention already used by CombFilter / AllpassFilter / DelayLine. Full suite
|
||||
4887/4887.
|
||||
|
||||
### GP-3 / GP-8 — Butterworth cascade engine extraction (dedup + capability)
|
||||
|
||||
No isolated benchmark — these are structural. GP-3 extracted the shared LP/HP
|
||||
cascade machinery into `_ButterworthCascadeBase`; GP-8 extracted a reusable
|
||||
non-Generator `ButterworthSectionEngine` so BandPass (HP→LP series) and
|
||||
BandReject (LP+HP parallel sum, now `vDSP_vaddD`) compose it — gaining the same
|
||||
background-thread `vDSP_biquad_SetupD` path LP/HP already had, and removing their
|
||||
duplicated scalar-cascade code. The vDSP biquad acceleration was already
|
||||
characterised on LP/HP; for BP/BR it only materially helps at high order
|
||||
(default order 2 = 1 biquad/section, where scalar ≈ vDSP). Net effect is large
|
||||
dedup (GP-3 −278 LOC; GP-8 removes BP/BR cascade duplication) + vDSP capability
|
||||
for high-order band filters. Behavior-identical (full Butterworth suite + 4887
|
||||
total pass).
|
||||
@@ -997,7 +997,7 @@ Add these to the forbidden list in §6 alongside heap allocation and locking.
|
||||
|
||||
## 13. Shared RT-Safe Helper Functions
|
||||
|
||||
Three module-level free functions and one method exist to eliminate repeated boilerplate. **Always use them** — do not re-inline the patterns they replace.
|
||||
A family of module-level free functions, base classes, and methods exist to eliminate repeated boilerplate. **Always use them** — do not re-inline the patterns they replace.
|
||||
|
||||
> **Out-of-tree extension packages:** these helpers are exposed as `@_spi(LyrebirdExtensions) public`. Add `@_spi(LyrebirdExtensions) import LyrebirdSynth` to any generator implementation file outside the core module. Full surface and stability policy: [extension-sdk.md](extension-sdk.md).
|
||||
|
||||
@@ -1167,6 +1167,18 @@ _zeroFallback = [Double](repeating: 0, count: lyrebirdDefaultResultBufferSize)
|
||||
_zeroFallback = makeSampleBuffer()
|
||||
```
|
||||
|
||||
### Accelerate-backed vectorisation helpers (Math / Filters / Delays)
|
||||
|
||||
These wrap the common pattern *"vectorise the full-block case, fall back to a scalar loop for short upstream blocks"* — the split-path strategy: branch on `n == count` (upstream block full-length, the normal case at any block size), run one Accelerate call, and keep a scalar fallback for `n < count`. All are RT-safe (no allocation; closures passed in capture only global functions).
|
||||
|
||||
- **`unaryVector{Sin,Cos,Exp,Log,Sqrt,Floor,Ceil,Abs}(_:into:count:)`** — `Generators/Math/UnaryMathVectorHelpers.swift`. One per unary `Math.Audio` waveshaper. Replaces the per-sample `Foundation.<fn>(i < n ? block[i] : pad)` loop with a single vForce (`vvsin`/`vvcos`/`vvexp`/`vvlog`/`vvsqrt`/`vvfloor`/`vvceil`) or `vDSP_vabsD` call. `Log` pads `1.0` (→ `log(1)=0`); the rest pad `0.0`. Built on the private `applyUnaryVectorTransform(_:pad:into:count:_:)` driver — add a new wrapper there if you add a unary op with a vForce/vDSP equivalent. `.Control` variants stay scalar.
|
||||
- **`BinaryOpKind` + `binaryOpVectorScalarRHS` / `binaryOpScalarLHSVector` / `binaryOpVectorVector`** — `Generators/Math/BinaryOpVectorHelpers.swift`. The vDSP dispatch path for `BinaryOpGenerator`'s four arithmetic kinds. `+ − × ÷` map to correctly-rounded vDSP routines, so results are **bit-identical** to the scalar `lhs op rhs` loop. Divide uses true-division (`vDSP_vsdivD` / `vDSP_svdivD` / `vDSP_vdivD`), never reciprocal-multiply. Note `vDSP_vsubD` / `vDSP_vdivD` take the subtrahend / divisor pointer **first** (`C = A − B` / `A / B`). `BinaryOpGenerator` stores `kind: BinaryOpKind?` — `nil` means an arbitrary closure was supplied and the per-sample `op` fallback runs.
|
||||
- **`runSVFBlock(...)`** — `Generators/Filters/SVFHelpers.swift`. The shared Chamberlin SVF per-block body for `SVF.Audio` and `SVF.Control` (four outputs: low / high / band / notch). When `freq` is generator-driven, the cutoff coefficient `f = 2·sin(π·freq/sr)` is evaluated with `sin()` only at the block's first/last sample and linearly interpolated between (same coefficient-ramp technique as `runRBJBiquadBlock`); the per-sample `freq > 0 → silence` guard is preserved exactly. `low` / `band` state mutated `inout`. (`LinLin.Audio` uses the same interpolation-free idea inline via `vDSP_vsmsaD` for its affine map — no helper, single call site.)
|
||||
- **`_ButterworthCascadeBase` / `ButterworthSectionEngine`** — `Generators/Filters/ButterworthCascadeBase.swift`, `ButterworthSectionEngine.swift`. `ButterworthSectionEngine` is a reusable (non-Generator) order-1…8 biquad-cascade engine: per-stage Butterworth Q, scalar + audio-rate-interpolated paths, and a background-thread `vDSP_biquad_SetupD` builder (Option B, RT-safe). Coefficient formulas are injected as init closures + a thread name. `_ButterworthCascadeBase` is the thin Generator shell owning one engine (LP/HP subclass it); `ButterworthBandPass` chains two engines (HP→LP series) and `ButterworthBandReject` sums two parallel (LP+HP via `vDSP_vaddD`). Build a new Butterworth-family filter by composing engines — never re-inline the cascade/thread machinery.
|
||||
- **`computeButterworthQs(order:)`** — `Generators/Filters/ButterworthHelpers.swift`. Init-time per-stage Butterworth pole-Q array. Call from any Butterworth-family `init`; do not inline the `−1/(2·cos(...))` loop.
|
||||
- **`lyrebirdNextPowerOfTwo(_:)`** — `Math/PowerOfTwo.swift`. Smallest power of two `≥ n` (1 for `n ≤ 1`). Use at init to size any circular buffer whose index wrap should be a single `& (count − 1)` instead of `% count` (CombFilter / AllpassFilter / DelayLine / DelayLineFeedback / Chorus / Flanger). Keep the *semantic* length separate from the rounded buffer length so the audible range is unchanged.
|
||||
- **`lyrebirdTwoPi`** — `Math/LyrebirdConstants.swift`. Canonical `2π` constant; use instead of an inline `let twoPi = 2.0 * .pi` local in any `_computeSamples`.
|
||||
|
||||
### Summary table
|
||||
|
||||
| Helper | Location | Use when |
|
||||
@@ -1197,6 +1209,13 @@ _zeroFallback = makeSampleBuffer()
|
||||
| `lyrebirdSeedXorshift64(from:mixConstant:)` | `LyrebirdConstants.swift` | Init-time PRNG seeding for Audio/Control pairs that must decorrelate via a per-variant `mixConstant` |
|
||||
| `lyrebirdSeedXorshift64(from:)` | `LyrebirdConstants.swift` | Init-time PRNG seeding for stand-alone single-state owners (e.g. `DemandTemporalTendency`, `DemandTemporalBrownian`) — convenience for the two-arg form with `mixConstant: 0` |
|
||||
| `_registerAutoFreeIfNeeded(_:)` | `Envelopes/DoneActionWatchable.swift` (extension) | Last line of every `DoneActionWatchable` generator's designated `init` (after `super.init`). If `doneAction == .freeNode`, self-registers with the currently-building `SynthesizerBase` so the synth auto-frees on completion. No-op outside `Synthesizer.build()`. |
|
||||
| `unaryVector{Sin,Cos,Exp,Log,Sqrt,Floor,Ceil,Abs}(_:into:count:)` | `Generators/Math/UnaryMathVectorHelpers.swift` | Unary `Math.Audio` waveshaper inner loop — vForce / `vDSP_vabsD` full-block fast path with scalar fallback. Add a wrapper via `applyUnaryVectorTransform` for a new vectorisable unary op. `.Control` stays scalar. |
|
||||
| `BinaryOpKind` + `binaryOpVectorScalarRHS` / `binaryOpScalarLHSVector` / `binaryOpVectorVector` | `Generators/Math/BinaryOpVectorHelpers.swift` | `BinaryOpGenerator` arithmetic dispatch. `+ − × ÷` → correctly-rounded vDSP (bit-identical to scalar). Divide is true-division; `vsubD`/`vdivD` take subtrahend/divisor first. `kind == nil` → closure fallback. |
|
||||
| `runSVFBlock(...)` | `Generators/Filters/SVFHelpers.swift` | Chamberlin SVF per-block body shared by `SVF.Audio` / `SVF.Control`. Generator-driven cutoff uses block-boundary `sin()` interpolation; per-sample `freq > 0` silence guard preserved. `low`/`band` `inout`. |
|
||||
| `ButterworthSectionEngine` / `_ButterworthCascadeBase` | `Generators/Filters/ButterworthSectionEngine.swift`, `ButterworthCascadeBase.swift` | Order-1…8 biquad cascade (scalar + audio-rate + background-thread vDSP setup). Compose for any Butterworth-family filter (LP/HP subclass the base; BandPass chains two engines, BandReject sums two). Never re-inline the cascade/thread machinery. |
|
||||
| `computeButterworthQs(order:)` | `Generators/Filters/ButterworthHelpers.swift` | Init-time per-stage Butterworth pole-Q array. Call from any Butterworth-family `init`. |
|
||||
| `lyrebirdNextPowerOfTwo(_:)` | `Math/PowerOfTwo.swift` | Init-time circular-buffer sizing so the index wrap is `& (count − 1)` not `% count`. Keep semantic length separate from the rounded buffer length. |
|
||||
| `lyrebirdTwoPi` | `Math/LyrebirdConstants.swift` | Canonical `2π`; use instead of an inline `2.0 * .pi` local in `_computeSamples`. |
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user