v2.1.1 release: delay-click fix + internal consolidation
Mirror of Lyrebird dev HEAD (9f791c7c) minus maintainer-only paths. Patch release: fixes the allpass fractional-delay click (DelayLine/CombFilter/AllpassFilter/ DelayLineFeedback under a modulated delay) and lands the internal code-quality consolidation pass (~160 deduped sites + shared base classes/helpers, bit-identical output). No public API removed or changed. See RELEASES.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -101,7 +101,7 @@ public func floatValue(graph: SynthGraph) -> Double { previousOutputValue }
|
||||
|
||||
### Control.init — must call _setupSubBlockBuffer()
|
||||
|
||||
Every `ControlGenerator.Control.init` must call `_setupSubBlockBuffer()` after `super.init()`. Multi-channel generators use `_setupSubBlockBuffer(channels: N)`.
|
||||
Every SUB-BLOCKING `ControlGenerator.Control.init` must call `_setupSubBlockBuffer()` after `super.init()`. Multi-channel generators use `_setupSubBlockBuffer(channels: N)`. Exception: `BlockRateControlGenerator` conformers never sub-block and omit it (see Rule 2).
|
||||
|
||||
```swift
|
||||
public final class Control: _Base, ControlGenerator {
|
||||
@@ -111,7 +111,7 @@ public final class Control: _Base, ControlGenerator {
|
||||
public override init(...) {
|
||||
// init stored properties first
|
||||
super.init(...)
|
||||
_setupSubBlockBuffer() // ← required; never call on RT thread
|
||||
_setupSubBlockBuffer() // ← required for sub-blocking Controls; omit when conforming to BlockRateControlGenerator; never call on RT thread
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -202,40 +202,31 @@ freq = freqInput.calculatedSamples(graph: graph, count: graph.engine.blockSize).
|
||||
freq = freqInput.calculatedSamples(graph: graph, count: count).first?.first ?? 0
|
||||
```
|
||||
|
||||
### Rule 2 — Add calculatedSamples bypass for per-audio-block state
|
||||
### Rule 2 — Conform to BlockRateControlGenerator for per-audio-block state
|
||||
|
||||
If the generator's state must advance exactly **once per audio block** (not once per sub-block), add a `calculatedSamples` bypass override. Without it, the sub-block loop calls `_computeSamples` N times per block.
|
||||
If the generator's state must advance exactly **once per audio block** (not once per sub-block), conform the `Control` class to `BlockRateControlGenerator` instead of `ControlGenerator`. Without it, the sub-block loop calls `_computeSamples` N times per block.
|
||||
|
||||
**Generators requiring a bypass:** anything where `_computeSamples` writes to a bus, advances a buffer position, detects trigger edges, smooths a gain value, or draws a random sample that should update at audio-block rate.
|
||||
**Generators requiring the marker:** anything where `_computeSamples` writes to a bus, advances a buffer position, detects trigger edges, smooths a gain value, draws a random sample, or runs an IIR step on an audio-rate input that should update at audio-block rate.
|
||||
|
||||
**Bypass pattern** (identical in every generator — copy verbatim):
|
||||
**Pattern** — just conform; the marker supplies the block-rate `calculatedSamples` as a protocol default, and the generator skips `_setupSubBlockBuffer()` (it never touches `_subBlockBuffer`):
|
||||
```swift
|
||||
// Bypass sub-block loop: <one-line reason why _computeSamples must run once per audio block>.
|
||||
public func calculatedSamples(graph: SynthGraph, count: Int) -> [[Double]] {
|
||||
let currentSerial = graph.engine.segmentSerial
|
||||
if _segmentSerial == currentSerial,
|
||||
let cachedChannel = _cachedResult.first, cachedChannel.count >= count {
|
||||
return _cachedResult
|
||||
}
|
||||
_segmentSerial = currentSerial
|
||||
_cachedResult = []
|
||||
let result = _computeSamples(graph: graph, count: count)
|
||||
_cachedResult = result
|
||||
return result
|
||||
public final class Control: _Base, BlockRateControlGenerator {
|
||||
// no calculatedSamples override, no _setupSubBlockBuffer() call
|
||||
public func _computeSamples(graph: SynthGraph, count: Int) -> [[Double]] { … }
|
||||
}
|
||||
```
|
||||
|
||||
**Decision rule:** if phase advancement is `phase += rate * Double(count) / sampleRate`, sub-blocking is correct and no bypass needed. If state advances once regardless of `count` (e.g. draw one random number, write one bus value, advance one buffer frame, run one IIR step on an audio-rate input), bypass is required.
|
||||
**Decision rule:** if phase advancement is `phase += rate * Double(count) / sampleRate`, sub-blocking is correct and the marker is NOT needed (stay a plain `ControlGenerator`, call `_setupSubBlockBuffer()`). If state advances once regardless of `count` (e.g. draw one random number, write one bus value, advance one buffer frame, run one IIR step on an audio-rate input), conform to `BlockRateControlGenerator`.
|
||||
|
||||
**Find prior art** instead of relying on a hand-list:
|
||||
```
|
||||
# Generators that have a bypass override (look here for shape to copy)
|
||||
grep -rn "public func calculatedSamples" Sources/Lyrebird/Generators/
|
||||
# Control generators that bypass sub-blocking (look here for shape to copy)
|
||||
grep -rln "BlockRateControlGenerator" Sources/Lyrebird/Generators/
|
||||
|
||||
# Generators that do NOT (oscillators, LFOs, envelopes — sub-block-correct by construction)
|
||||
ls Sources/Lyrebird/Generators/Oscillators/ Sources/Lyrebird/Generators/Envelope*.swift
|
||||
```
|
||||
The list is too long and changes too often to maintain inline. Apply the decision rule, then check 1–2 nearby generators of similar shape for the exact bypass body.
|
||||
The list is too long and changes too often to maintain inline. Apply the decision rule, then check 1–2 nearby generators of similar shape.
|
||||
|
||||
## Shared Helper Functions — ALWAYS Use
|
||||
|
||||
@@ -283,7 +274,7 @@ public enum MyGen {
|
||||
private var _rampTarget: Double = 0.0 // if using fillRampedResult
|
||||
public override init(...) {
|
||||
super.init(...)
|
||||
_setupSubBlockBuffer() // ← required in every Control.init
|
||||
_setupSubBlockBuffer() // ← required in every sub-blocking Control.init (omit for BlockRateControlGenerator conformers)
|
||||
}
|
||||
public func floatValue(...) -> Double { previousOutputValue }
|
||||
public func _computeSamples(...) -> [[Double]] { ... }
|
||||
@@ -338,7 +329,7 @@ Every new generator needs Swift Testing tests (`@Suite`, `@Test`, `#expect`) in
|
||||
|
||||
For `ControlGenerator` add:
|
||||
8. **Ramp** — last sample of first block equals target (use `samples[0][count-1]`, not `samples[0].last` — the pre-allocated buffer is 512 elements)
|
||||
9. **Sub-block bypass** — if the generator has a `calculatedSamples` bypass override, verify `_computeSamples` is called exactly once even when `controlBlockSize < blockSize`
|
||||
9. **Sub-block bypass** — if the generator conforms to `BlockRateControlGenerator`, verify `_computeSamples` is called exactly once even when `controlBlockSize < blockSize`
|
||||
|
||||
Test helpers: `makeTestEngine`, `makeSynthGraph`, `advanceBlock` in `Tests/LyrebirdTests/TestHelpers.swift`.
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@ Group your review by these categories. Every item below is a blocking finding.
|
||||
|
||||
### Generator protocol violations
|
||||
- Redeclaring `_segmentSerial` / `_cachedResult` / `_subBlockBuffer` instead of inheriting from `GeneratorBase`.
|
||||
- `ControlGenerator.Control.init` missing `_setupSubBlockBuffer()` (or `_setupSubBlockBuffer(channels: N)`) after `super.init()`.
|
||||
- A sub-blocking `ControlGenerator.Control.init` missing `_setupSubBlockBuffer()` (or `_setupSubBlockBuffer(channels: N)`) after `super.init()`. `BlockRateControlGenerator` conformers are exempt — they never sub-block and must NOT call it.
|
||||
- `Control._computeSamples` using `graph.engine.blockSize` for phase/state advancement (must use `count`); same for any `calculatedSamples(graph:count:)` call on inputs.
|
||||
- Generators that must advance once per audio block (bus writers, buffer-position advancers, gain smoothers, trigger detectors, random drawers, IIR filters with audio-rate input) without a `calculatedSamples` bypass override (canonical pattern: `Out.Control`). To verify a `Control` variant in the diff has a bypass when it should: `grep -n "public func calculatedSamples" Sources/Lyrebird/Generators/<Path>/<Type>.swift`.
|
||||
- Control generators that must advance once per audio block (bus writers, buffer-position advancers, gain smoothers, trigger detectors, random drawers, IIR filters with audio-rate input, analysers) that fail to conform to `BlockRateControlGenerator` — the marker protocol whose `calculatedSamples` default supplies the block-rate gateway (it replaced the old per-generator `calculatedSamples { _calculatedSamplesBlockRate(...) }` forwarder). To verify a `Control` variant in the diff bypasses sub-blocking when it should: `grep -n "BlockRateControlGenerator" Sources/Lyrebird/Generators/<Path>/<Type>.swift`. A conforming class needs no `calculatedSamples` override and must NOT call `_setupSubBlockBuffer()`; conversely, a true sub-blocker must not conform.
|
||||
- Multi-row generators (`_result.count > 1`) without an `outputChannelCount` override returning the fixed init-time channel count. Missing override silently mono-izes under `+ - * /` operators.
|
||||
- Channel count derived from a runtime-mutable source rather than a `let` constant or `_result.count` set at init.
|
||||
- Static or global mutable state shared between generator instances.
|
||||
|
||||
@@ -33,6 +33,8 @@ EXCLUSIONS=(
|
||||
"DOC_UPDATE_PLAN.md"
|
||||
"docs/00-working-order.md"
|
||||
"docs/01-completed-working-order.md"
|
||||
"docs/plans"
|
||||
"spikes"
|
||||
".claude"
|
||||
".githooks"
|
||||
".swiftpm"
|
||||
|
||||
Reference in New Issue
Block a user