v1.3.0 release: graceful-release fix, quickstart template + demo, documentation accuracy pass
- Fixed: SynthesizerBase subclasses' release/free now dispatch correctly (gated synths were hard-freed instead of released). - New: quickstart project template + LyrebirdQuickstartDemo. - Docs: every example typechecked or provably illustrative (426->542); ~20 wrong-API examples fixed; root docs brought under the compile guard. - Fixed: NRT/Score demo Package.swift build from terminal again. See RELEASES.md for details.
This commit is contained in:
+28
-26
@@ -39,7 +39,7 @@ condition is never violated in engine-driven usage. No heap allocation occurs in
|
||||
Input literalness is classified once at `init` time (`lhsIsLiteral`/`rhsIsLiteral`) — no
|
||||
runtime type checks on the RT thread.
|
||||
- **`Out.Control`**: `_result` pre-allocated in `init`; fills in-place and returns the pre-allocated
|
||||
buffer rather than constructing `[[LyrebirdFloat](repeating:count:)]` on every block.
|
||||
buffer rather than constructing `[[Double](repeating:count:)]` on every block.
|
||||
- **`Out.Audio`**: returns the source's own `calculatedSamples` result directly — no additional
|
||||
wrapper allocation.
|
||||
|
||||
@@ -47,15 +47,15 @@ condition is never violated in engine-driven usage. No heap allocation occurs in
|
||||
|
||||
## `ParameterNode` — Live Parameter Node
|
||||
|
||||
`ParameterNode` is an `AudioGenerator` that carries a single `LyrebirdFloat` value from
|
||||
`ParameterNode` is an `AudioGenerator` that carries a single `Double` value from
|
||||
the main thread to the RT audio thread through a lock-free `Atomic<UInt64>`. It is
|
||||
typically created implicitly via the `@LiveParam` property wrapper.
|
||||
|
||||
```swift
|
||||
// Example — your synthesizer, defined by subclassing SynthesizerBase
|
||||
final class SineTone: SynthesizerBase {
|
||||
@LiveParam var freq: LyrebirdFloat = 440.0 // $freq is a ParameterNode
|
||||
@LiveParam var amp: LyrebirdFloat = 0.2
|
||||
@LiveParam var freq: Double = 440.0 // $freq is a ParameterNode
|
||||
@LiveParam var amp: Double = 0.2
|
||||
|
||||
override func build() {
|
||||
output(bus: 0, source: OscSin.Audio(freq: $freq) * $amp)
|
||||
@@ -104,7 +104,7 @@ OscSin.Audio(freq: 440.0, interpolation: .cubic) // Catmull-Ro
|
||||
OscSin.Audio(freq: 440.0, table: engine.sharedTables.sineTable) // use engine's shared copy
|
||||
```
|
||||
|
||||
- `freq` accepts any `ValidGeneratorInput`. **Scalar inputs** (literal, String) call `floatValue` once per block. **Generator inputs** are read at audio rate — one frequency value per sample — enabling true FM synthesis with no block-rate aliasing.
|
||||
- `freq` accepts any `ValidGeneratorInput`. **Scalar inputs** (a `Double`/`Int` literal) call `floatValue` once per block. **Generator inputs** are read at audio rate — one frequency value per sample — enabling true FM synthesis with no block-rate aliasing.
|
||||
- `phase` parameter is a fraction of a full cycle [0, 1).
|
||||
- `interpolation` — `TableInterpolation` enum: `.none` (nearest), `.linear` (default), `.cubic`
|
||||
(Catmull-Rom, ~4× arithmetic cost; only audibly better than `.linear` at table sizes < 256 or
|
||||
@@ -116,7 +116,7 @@ OscSin.Audio(freq: 440.0, table: engine.sharedTables.sineTable) // use engine
|
||||
- **Power-of-two required**: `OscSin.init` enforces this with a `precondition`. Use `OscTable`
|
||||
for non-power-of-two sizes.
|
||||
- The table reference is stored as a non-Optional `let` ivar — zero ARC traffic on the RT thread.
|
||||
- State: `LyrebirdFloat` phase accumulator, advanced per sample.
|
||||
- State: `Double` phase accumulator, advanced per sample.
|
||||
|
||||
#### OscTable
|
||||
Table-lookup oscillator reading from a user-supplied `LyrebirdBuffer`. Accepts any table content
|
||||
@@ -125,7 +125,7 @@ and any size (power-of-two or not), with selectable interpolation.
|
||||
```swift
|
||||
// Custom waveform (linear interpolation, default)
|
||||
let table = LyrebirdBuffer(count: lyrebirdDefaultTableSize)
|
||||
table.fill { i, n in LyrebirdFloat(i) / LyrebirdFloat(n) * 2.0 - 1.0 } // sawtooth
|
||||
table.fill { i, n in Double(i) / Double(n) * 2.0 - 1.0 } // sawtooth
|
||||
let osc = OscTable.Audio(table: table, freq: 440.0)
|
||||
|
||||
// Cubic interpolation for a small custom table
|
||||
@@ -146,7 +146,7 @@ let osc = OscTable.Audio(table: engine.sharedTables.sineTable, freq: 440.0, phas
|
||||
fast path for power-of-two tables.
|
||||
- Checks `table.isValid` (acquiring load) each block; outputs silence if the table has been
|
||||
invalidated. The freq input generator is always evaluated — its state advances even when silent.
|
||||
- State: `LyrebirdFloat` phase accumulator, advanced per sample.
|
||||
- State: `Double` phase accumulator, advanced per sample.
|
||||
|
||||
#### VectorOscillator
|
||||
Vector-synthesis (XY) wavetable oscillator. Audio + Control variants; `GeneratorEnum` conformance. Crossfades between four mono `LyrebirdBuffer` waveforms on a 2D plane: `x` blends A↔B and C↔D, `y` blends the resulting AB↔CD pair. Linear blend on both axes; per-buffer reads use `TableInterpolation` (`.none` / `.linear` / `.cubic`).
|
||||
@@ -161,8 +161,8 @@ let d = LyrebirdBuffer(count: size); d.fillHanning()
|
||||
VectorOscillator.Audio(
|
||||
bufferA: a, bufferB: b, bufferC: c, bufferD: d,
|
||||
freq: 220.0,
|
||||
x: LFNoise2.Audio(freq: 0.4) * 0.5 + 0.5, // animated X
|
||||
y: LFNoise2.Audio(freq: 0.3) * 0.5 + 0.5 // animated Y
|
||||
x: LFCurveNoise.Audio(freq: 0.4) * 0.5 + 0.5, // animated X
|
||||
y: LFCurveNoise.Audio(freq: 0.3) * 0.5 + 0.5 // animated Y
|
||||
)
|
||||
```
|
||||
|
||||
@@ -182,7 +182,7 @@ Impulse.Audio(freq: 1.0, initPhase: 0.5) // first fire at half-period offset
|
||||
|
||||
- `freq` accepts any `ValidGeneratorInput`. **Scalar inputs** compute a constant phase increment once per block. **Generator inputs** are read at audio rate — one frequency value per sample — so the impulse spacing can be modulated at full audio precision.
|
||||
- `initPhase` is a fraction [0, 1) — `0.0` fires at sample 0 of the first block.
|
||||
- State: `LyrebirdFloat` phase accumulator.
|
||||
- State: `Double` phase accumulator.
|
||||
|
||||
#### Phasor
|
||||
Linear phase accumulator (ramp generator). Equivalent to SuperCollider `Phasor`. Accumulates `rate` units per sample within the half-open range `[start, end)`. On a ≤0 → >0 rising edge of `trig`, phase resets to `resetPos`.
|
||||
@@ -339,7 +339,7 @@ State: `x1`, `x2`, `y1`, `y2` persist across block boundaries.
|
||||
#### RBJ Filter Overview
|
||||
|
||||
All RBJ filters share the same modulation model:
|
||||
- All parameter inputs accept any `ValidGeneratorInput` (literals, Strings, Generators).
|
||||
- All parameter inputs accept any `ValidGeneratorInput` (literals, Generators, closures).
|
||||
- **Scalar inputs**: coefficients recomputed only when a parameter or `sampleRate` changes between blocks.
|
||||
- **Generator inputs**: coefficients computed at block boundaries (first and last sample) and linearly interpolated across the block — at most 6 trig/pow calls per block regardless of block size.
|
||||
- Frequencies above 0.999 × Nyquist return `BiquadCoeffs.zero` (silence).
|
||||
@@ -465,7 +465,7 @@ Envelope(levels: [0, 1, 0], duration: 1.0, curves: [0, 0])
|
||||
- `levels`: N+1 values. `durations` and `curves`: N values each (one per segment).
|
||||
- Both `durations` and `curves` are padded/trimmed to `segmentCount` in `init` — a mismatched
|
||||
array never reaches the RT thread.
|
||||
- `totalDuration: LyrebirdFloat` is pre-computed in `init` (not a `reduce` computed property).
|
||||
- `totalDuration: Double` is pre-computed in `init` (not a `reduce` computed property).
|
||||
|
||||
**Curve values** (formula per segment: `(1 − exp(curve·t/N)) / (1 − exp(curve))`):
|
||||
|
||||
@@ -824,7 +824,7 @@ Read from one or more consecutive buses. Do not modify bus memory. Channel count
|
||||
In.Audio(bus: 2) // AudioGenerator — reads audioBuses[2]
|
||||
In.Control(bus: 10) // ControlGenerator — reads controlBuses[10], interpolated ramp
|
||||
|
||||
// Multi-channel — N consecutive buses, N-channel [[LyrebirdFloat]] output
|
||||
// Multi-channel — N consecutive buses, N-channel [[Double]] output
|
||||
In.Audio(bus: 4, channels: 3) // reads audioBuses[4], [5], [6]
|
||||
In.Control(bus: 10, channels: 2) // reads controlBuses[10] and [11]; independent ramps
|
||||
|
||||
@@ -1442,10 +1442,11 @@ Single Chamberlin SVF stage with four simultaneous outputs available through the
|
||||
|
||||
```swift
|
||||
SVF.Audio(input: sig, freq: 800.0, q: 0.707) // Butterworth Q
|
||||
SVF.Audio(input: sig, freq: env, q: 4.0, mode: .bandpass)
|
||||
SVF.Audio(input: sig, freq: env, q: 4.0).bandpass // select the bandpass output
|
||||
```
|
||||
|
||||
- Modes: `.lowpass` (default), `.highpass`, `.bandpass`, `.notch`. Init-only.
|
||||
- Outputs: `.lowpass`, `.highpass`, `.bandpass`, `.notch` accessors (all four are
|
||||
computed simultaneously; pick one, or read several from the same instance).
|
||||
- `q` defaults to `svfButterworthQ` (= 0.707).
|
||||
- Audio-rate `freq` modulation supported; Chamberlin clamping ensures stability at the Nyquist limit.
|
||||
|
||||
@@ -1686,7 +1687,7 @@ Continuous random walker with low-pass smoothing. Internal xorshift64 PRNG (seed
|
||||
|
||||
```swift
|
||||
Jitter.Control(center: 1.0, speed: 5.0, amount: 0.3) // 5 Hz wobble, ±30% around 1.0
|
||||
Jitter.Audio(center: 220.0, speed: 8.0, amount: 50.0, // 50 Hz random detune
|
||||
Jitter.Control(center: 220.0, speed: 8.0, amount: 50.0, // 50 Hz random detune
|
||||
seed: 12345)
|
||||
```
|
||||
|
||||
@@ -1711,7 +1712,7 @@ Buffer-driven, oscillator-driven, FM, and input-grain synthesis. All use the sha
|
||||
Reads grains from a `LyrebirdBuffer` at sample-accurate positions.
|
||||
|
||||
```swift
|
||||
BufferGrain.Audio(
|
||||
BufferGrain(
|
||||
buffer: bufferRef,
|
||||
position: 0.5, positionSpread: 0.1,
|
||||
duration: 0.08,
|
||||
@@ -1728,14 +1729,14 @@ BufferGrain.Audio(
|
||||
Sine-window grain cloud. `freq` is the grain pitch.
|
||||
|
||||
```swift
|
||||
SineGrain.Audio(freq: 440.0, amp: 0.4, duration: 0.05, density: 100.0)
|
||||
SineGrain(freq: 440.0, amp: 0.4, duration: 0.05, density: 100.0)
|
||||
```
|
||||
|
||||
### FMGrain
|
||||
Per-grain FM synthesis. `carrierFreq` × `modFreq` × `modIndex` defines the grain's spectrum.
|
||||
|
||||
```swift
|
||||
FMGrain.Audio(carrierFreq: 880.0, modFreq: 440.0, modIndex: 2.0,
|
||||
FMGrain(carrierFreq: 880.0, modFreq: 440.0, modIndex: 2.0,
|
||||
amp: 0.3, duration: 0.1)
|
||||
```
|
||||
|
||||
@@ -1743,7 +1744,7 @@ FMGrain.Audio(carrierFreq: 880.0, modFreq: 440.0, modIndex: 2.0,
|
||||
Records live audio into a circular capture buffer, then triggers grains from arbitrary read positions. Use for "freeze" effects, stutter, micro-looping live input.
|
||||
|
||||
```swift
|
||||
InputGrain.Audio(input: micIn, position: 0.1, positionSpread: 0.4,
|
||||
InputGrain(input: micIn, position: 0.1, positionSpread: 0.4,
|
||||
duration: 0.15, density: 30.0)
|
||||
```
|
||||
|
||||
@@ -1965,7 +1966,8 @@ ScannedSynthesizer.Audio(
|
||||
centeringForce: 1.0,
|
||||
excitationIndex: 0,
|
||||
initialDisplacement: .gaussian,
|
||||
sampleRate: engine.sampleRate
|
||||
sampleRate: engine.sampleRate,
|
||||
blockSize: engine.blockSize
|
||||
)
|
||||
```
|
||||
|
||||
@@ -2030,7 +2032,7 @@ let player = try DiskIn.Audio(
|
||||
sampleRate: engine.sampleRate,
|
||||
rate: 1.0, // 1.0 = native pitch, audio-rate Generator OK
|
||||
loop: true,
|
||||
doneAction: .freeSynth, // node-tree action when EOF hit (loop=false)
|
||||
doneAction: .freeNode, // node-tree action when EOF hit (loop=false)
|
||||
bufferFrames: 8192
|
||||
)
|
||||
output(bus: 0, source: player)
|
||||
@@ -2038,7 +2040,7 @@ output(bus: 0, source: player)
|
||||
|
||||
- Reads in a background thread; RT pulls from a lock-free SPSC queue. `bufferFrames` sizes the pre-read buffer.
|
||||
- `rate` accepts Generator inputs for varispeed playback.
|
||||
- `doneAction` mirrors SC node-tree actions: `.nothing` / `.freeSynth` / `.pause` / `.releaseNode(n)`. See `Sources/Lyrebird/Generators/BufferIO/DiskInError.swift` for error cases.
|
||||
- `doneAction` sets the node-tree action on EOF: `.nothing` / `.freeNode` / `.loop`. See `Sources/Lyrebird/Generators/BufferIO/DiskInError.swift` for error cases.
|
||||
|
||||
### DiskOut.Audio
|
||||
Streams `source` audio to a file URL. Throwing init.
|
||||
@@ -2345,7 +2347,7 @@ The minimal `AmbiEncoder1` / `AmbiDecoder1` panning generators above remain in c
|
||||
Plays a `SpectralFrameBuffer` as sinusoidal partials directly (additive resynthesis, no IFFT). Reads `position` ∈ `[0, frameCount)` and interpolates between consecutive frames.
|
||||
|
||||
```swift
|
||||
let frameBuffer = SpectralFrameBuffer(fftSize: 2048, frameCount: 1024)
|
||||
let frameBuffer = SpectralFrameBuffer(fftSize: 2048, hopSize: 512, frameCount: 1024, sampleRate: 44100.0)
|
||||
// ... fill from analysis or file ...
|
||||
AdditiveSynthesizer(
|
||||
frameBuffer: frameBuffer,
|
||||
@@ -2442,7 +2444,7 @@ freeze.unfreeze() // resume live analysis
|
||||
Record a chain into a `SpectralFrameBuffer` for offline playback, or play back from one. `SpectralPlayBuffer` and `SpectralBufferRead` conform to `SpectralBufferGenerator` and drive `SpectralChain.Audio`'s synthOnly mode directly.
|
||||
|
||||
```swift
|
||||
let frames = SpectralFrameBuffer(fftSize: 2048, frameCount: 256)
|
||||
let frames = SpectralFrameBuffer(fftSize: 2048, hopSize: 512, frameCount: 256, sampleRate: 44100.0)
|
||||
|
||||
// Record into frames
|
||||
let rec = SpectralRecordBuffer(frameBuffer: frames, loop: false)
|
||||
|
||||
Reference in New Issue
Block a user