Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 24ea32e47c | |||
| c14efe998a | |||
| 63b630b317 | |||
| 3668739d20 | |||
| 6e7f4c0076 |
@@ -1,6 +1,6 @@
|
|||||||
# Lyrebird
|
# Lyrebird
|
||||||
|
|
||||||
A native macOS/iOS audio synthesis framework written in Swift. Implement `Generator` and `Synthesizer` protocols; the Lyrebird engine handles Core Audio I/O and signal graph evaluation with no heap allocation on the real-time thread.
|
A native macOS, iOS, and Linux audio synthesis framework written in Swift. Implement `Generator` and `Synthesizer` protocols; the Lyrebird engine handles platform audio I/O (Core Audio on Apple, ALSA on Linux) and signal graph evaluation with no heap allocation on the real-time thread.
|
||||||
|
|
||||||
Informed by 20+ years of SuperCollider practice, adapted to Swift idioms and a single-process architecture.
|
Informed by 20+ years of SuperCollider practice, adapted to Swift idioms and a single-process architecture.
|
||||||
|
|
||||||
@@ -8,7 +8,7 @@ Informed by 20+ years of SuperCollider practice, adapted to Swift idioms and a s
|
|||||||
|
|
||||||
## A quick taste
|
## A quick taste
|
||||||
|
|
||||||
Three layers, each usable on its own: **Generators** are the unit signal graph, **Synthesizers** package a graph plus live parameters into a playable voice, and the **Engine** drives Core Audio and schedules voices sample-accurately.
|
Three layers, each usable on its own: **Generators** are the unit signal graph, **Synthesizers** package a graph plus live parameters into a playable voice, and the **Engine** drives the platform audio backend (Core Audio on Apple, ALSA on Linux) and schedules voices sample-accurately.
|
||||||
|
|
||||||
### Generators — compose a signal graph with operators
|
### Generators — compose a signal graph with operators
|
||||||
|
|
||||||
@@ -128,10 +128,15 @@ The REPL is text-only and works from any project that depends on Lyrebird; the s
|
|||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
| Platform | OS | Xcode | Swift |
|
| Platform | OS | IDE | Swift |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| macOS | 15+ | 16+ | 6.0 |
|
| macOS | 15+ | Xcode 16+ | 6.0 |
|
||||||
| iOS | 18+ | 16+ | 6.0 |
|
| iOS | 18+ | Xcode 16+ | 6.0 |
|
||||||
|
| Linux | Ubuntu 22.04+ ¹ | VS Code ² | 6.0 |
|
||||||
|
|
||||||
|
¹ Any swift.org-supported distribution with a Swift 6.0+ toolchain. Install `libasound2-dev` for live audio via the ALSA driver; offline/NRT rendering needs no audio device or ALSA.
|
||||||
|
|
||||||
|
² VS Code with the [Swift extension](https://marketplace.visualstudio.com/items?itemName=swiftlang.swift-vscode) (build/debug via SourceKit-LSP); any editor works with the `swift` CLI. Linux setup walk-through: [`docs/linux-getting-started.md`](docs/linux-getting-started.md).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -149,7 +154,24 @@ That's it — the `Lyrebird` product links **statically**, so there's no dynamic
|
|||||||
|
|
||||||
Full walk-through (SPM manifest form, local-path dev dependency, per-template details): [`INSTALLATION_AND_USAGE.md`](INSTALLATION_AND_USAGE.md). DocC version: **Getting Started ▸ Adding Lyrebird to your own Xcode project**.
|
Full walk-through (SPM manifest form, local-path dev dependency, per-template details): [`INSTALLATION_AND_USAGE.md`](INSTALLATION_AND_USAGE.md). DocC version: **Getting Started ▸ Adding Lyrebird to your own Xcode project**.
|
||||||
|
|
||||||
**On Linux?** The non-UI core — engine, generators, CLI, offline render, live ALSA audio, MIDI, and OSC — builds and runs on Linux (no Xcode, no SwiftUI). Start here: [`docs/linux-getting-started.md`](docs/linux-getting-started.md).
|
**On Linux (or any SwiftPM project without the Xcode UI)** — there's no "Add Package Dependencies" dialog, so declare it in `Package.swift`:
|
||||||
|
|
||||||
|
```swift
|
||||||
|
dependencies: [
|
||||||
|
.package(url: "https://realizedsound.mooo.com/josh/Lyrebird", from: "1.0.0"),
|
||||||
|
],
|
||||||
|
targets: [
|
||||||
|
.executableTarget(
|
||||||
|
name: "MyApp",
|
||||||
|
dependencies: [
|
||||||
|
.product(name: "Lyrebird", package: "Lyrebird"),
|
||||||
|
// .product(name: "LyrebirdUI", package: "Lyrebird"), // Apple-only — SwiftUI controls
|
||||||
|
]
|
||||||
|
),
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
Then `import LyrebirdSynth`. On Linux the non-UI core — engine, generators, CLI, offline render, live ALSA audio, MIDI, and OSC — builds and runs with no Xcode and no SwiftUI (`LyrebirdUI` is Apple-only; a GTK4 UI ships as a separate demo). Full setup: [`docs/linux-getting-started.md`](docs/linux-getting-started.md).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -192,6 +214,25 @@ Use `Lyrebird-Package` for day-to-day development of the engine and tests.
|
|||||||
| Build fails with Swift driver errors | Xcode 26 bug affecting the **demo workspace** (which dynamic-links for live-coding) — it already sets `SWIFT_USE_INTEGRATED_DRIVER = NO` + `parallelizeBuildables = NO`. Your own project links Lyrebird statically and is unaffected. |
|
| Build fails with Swift driver errors | Xcode 26 bug affecting the **demo workspace** (which dynamic-links for live-coding) — it already sets `SWIFT_USE_INTEGRATED_DRIVER = NO` + `parallelizeBuildables = NO`. Your own project links Lyrebird statically and is unaffected. |
|
||||||
| `dyld: Library not loaded` | Only the bundled demos/AUv3 use the dynamic `LyrebirdDynamic` product; their entitlements already set `disable-library-validation`. External consumers link the static `Lyrebird` product and never hit this. |
|
| `dyld: Library not loaded` | Only the bundled demos/AUv3 use the dynamic `LyrebirdDynamic` product; their entitlements already set `disable-library-validation`. External consumers link the static `Lyrebird` product and never hit this. |
|
||||||
|
|
||||||
|
### On Linux — VS Code or any editor (no Xcode)
|
||||||
|
|
||||||
|
Xcode, the `.xcworkspace`, and the schemes above are Apple-only. On Linux there's no workspace to open — point an editor at the package directory and drive it from the terminal:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
code --install-extension swiftlang.swift-vscode # once: the official Swift extension (SourceKit-LSP: autocomplete, jump-to-def, debug)
|
||||||
|
code . # open the package in VS Code
|
||||||
|
```
|
||||||
|
|
||||||
|
There are no schemes — run targets directly:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
swift build && swift test # build + run the Linux test suites
|
||||||
|
swift run LyrebirdCLI repl # the CLI (also `new`, scaffolding, …)
|
||||||
|
LYREBIRD_ENABLE_LINUX_UI=1 swift run LyrebirdUILinuxDemo # the GTK4 UI demo
|
||||||
|
```
|
||||||
|
|
||||||
|
The SwiftUI / AUv3 / iOS demos in the scheme table do not build on Linux. Full walk-through — toolchain, VS Code, building, running a sample: [`docs/linux-getting-started.md`](docs/linux-getting-started.md).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Building and testing from the terminal
|
## Building and testing from the terminal
|
||||||
|
|||||||
+51
@@ -7,6 +7,57 @@ functionality in a backward-compatible way.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## 2.2.0 — Live-parameter ramp origin primed at synth add
|
||||||
|
|
||||||
|
A small-but-behavioral release. One fix to how `@UIParam` / `@LiveParam` values
|
||||||
|
are delivered on a synth's first rendered block, plus the internal hook that
|
||||||
|
backs it. The public API is source-compatible — the one new protocol member is
|
||||||
|
internal-facing and ships with a default implementation — so this is drop-in
|
||||||
|
over 2.1.x, but the delivery change is observable and is called out below.
|
||||||
|
|
||||||
|
**Fix — a parameter set before the first render is now delivered flat.** When a
|
||||||
|
value is assigned to an `@UIParam` / `@LiveParam` *after the synth is
|
||||||
|
constructed but before it first renders* — most commonly when restoring saved
|
||||||
|
state onto a freshly built synth — the parameter is now delivered as a flat
|
||||||
|
block at that value from sample 0. Previously the first rendered block ramped
|
||||||
|
from the property-declaration default up to the assigned value over one
|
||||||
|
(sub-)block, because the property-wrapper setter advances the atomic target but
|
||||||
|
not the interpolation origin, which stayed at the construction-time default.
|
||||||
|
|
||||||
|
For most parameters that one-block (~a few ms) glide was benign. For a value
|
||||||
|
feeding a decision stage it was not: a `Schmidt` trigger fed a threshold that
|
||||||
|
swept up from the default would latch on the transient and, if the steady signal
|
||||||
|
sat inside the hysteresis band, never reset — e.g. a `NoiseGate` restored from a
|
||||||
|
saved rig would open on load and ignore its threshold. Priming the origin at add
|
||||||
|
removes the sweep.
|
||||||
|
|
||||||
|
Mechanically: `SynthesizerBase`, as part of the `Mirror`-based live-parameter
|
||||||
|
auto-registration it already runs at add time (`rebuildGraph()`, main thread,
|
||||||
|
before the node is visible to the RT thread), now also primes each parameter's
|
||||||
|
ramp origin to its current value via a new `LiveParameterValue._primeRampOrigin()`.
|
||||||
|
`ParameterNode` and `UIParamNode` implement it; external conformers inherit a
|
||||||
|
no-op default, so nothing is source-broken. A re-add (`remove` → change value →
|
||||||
|
`add`) likewise re-primes to the then-current value.
|
||||||
|
|
||||||
|
**Behavior change to be aware of.** Two deliveries changed, both toward "the
|
||||||
|
value you set before starting is the value you get":
|
||||||
|
|
||||||
|
- A value assigned between construction and first render is **flat** on block
|
||||||
|
one, not a ramp from the declaration default. Code that (knowingly or not)
|
||||||
|
relied on that opening glide will no longer see it. If you want an opening
|
||||||
|
ramp, drive the parameter from a source/envelope or change it after start.
|
||||||
|
- A synth removed, re-assigned while out of the tree, then re-added starts
|
||||||
|
**flat at the new value** rather than gliding from the value it last rendered.
|
||||||
|
|
||||||
|
Live changes made **while the synth is running** are unchanged — they still ramp
|
||||||
|
per (sub-)block from the last rendered value, as before. The source-slot /
|
||||||
|
crossfade path is unaffected (the source overwrites the origin each block).
|
||||||
|
Pinned by `LiveParamRampOriginTests` (flat delivery for `@UIParam` and
|
||||||
|
`@LiveParam`, live-change-still-ramps, remove/change/re-add, and source-slot
|
||||||
|
non-interference).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## 2.1.1 — Delay-click fix + internal consolidation
|
## 2.1.1 — Delay-click fix + internal consolidation
|
||||||
|
|
||||||
A patch release: one audible bug fix in the delay/comb/allpass family, plus a
|
A patch release: one audible bug fix in the delay/comb/allpass family, plus a
|
||||||
|
|||||||
@@ -82,6 +82,12 @@ at the end of `rebuildGraph()`. The property name (with the leading `_` of prope
|
|||||||
backing storage stripped) becomes the parameter key for `updateParameter` and
|
backing storage stripped) becomes the parameter key for `updateParameter` and
|
||||||
``LyrebirdMessageContext/set(_:to:on:)``. No `declareParameter` call is needed.
|
``LyrebirdMessageContext/set(_:to:on:)``. No `declareParameter` call is needed.
|
||||||
|
|
||||||
|
Auto-registration also **primes each parameter's ramp origin** to its current value (before the
|
||||||
|
RT thread sees the node), so a value assigned between construction and the synth's first render —
|
||||||
|
for example restoring saved state onto a freshly built synth — is delivered **flat on the first
|
||||||
|
block**, not as a ramp up from the property-declaration default. Changes made after the synth is
|
||||||
|
running still ramp as usual.
|
||||||
|
|
||||||
### Block-rate vs sub-block-rate ramping
|
### Block-rate vs sub-block-rate ramping
|
||||||
|
|
||||||
When `controlBlockSize == blockSize` (the engine default), the framework calls
|
When `controlBlockSize == blockSize` (the engine default), the framework calls
|
||||||
|
|||||||
@@ -245,7 +245,10 @@ Do not call `engine.remove` from within the RT callback.
|
|||||||
|
|
||||||
- `parameterTable.inputs` is populated by `_autoRegisterLiveParams()` at the end of
|
- `parameterTable.inputs` is populated by `_autoRegisterLiveParams()` at the end of
|
||||||
`rebuildGraph()` (main thread, before add) and read during `evaluate()` (RT thread,
|
`rebuildGraph()` (main thread, before add) and read during `evaluate()` (RT thread,
|
||||||
after add). No concurrent access.
|
after add). No concurrent access. The same pass also primes each live parameter's ramp
|
||||||
|
origin to its current value, so a value assigned before the first render (e.g. restored
|
||||||
|
state) is delivered flat; this write is main-thread-only and precedes the add, so it never
|
||||||
|
races the RT thread.
|
||||||
- `updateParameter` issues a releasing atomic store on the projected `ParameterNode` /
|
- `updateParameter` issues a releasing atomic store on the projected `ParameterNode` /
|
||||||
`UIParamNode`; the RT thread picks up the new value via an acquiring atomic load at the
|
`UIParamNode`; the RT thread picks up the new value via an acquiring atomic load at the
|
||||||
start of the next (sub-)block — no queue, no dictionary mutation on the RT thread.
|
start of the next (sub-)block — no queue, no dictionary mutation on the RT thread.
|
||||||
|
|||||||
@@ -34,6 +34,32 @@ public protocol LiveParameterValue: AnyObject {
|
|||||||
/// `UIParamNode` (`@Observable` stored property) satisfy this requirement via their
|
/// `UIParamNode` (`@Observable` stored property) satisfy this requirement via their
|
||||||
/// existing public `value` accessor.
|
/// existing public `value` accessor.
|
||||||
var value: Double { get }
|
var value: Double { get }
|
||||||
|
|
||||||
|
/// Moves the interpolation origin (`previousOutputValue`) to the current target value, so the
|
||||||
|
/// next rendered block is a flat buffer at that value with no ramp.
|
||||||
|
///
|
||||||
|
/// `SynthesizerBase` calls this on every live parameter when a synth is (re-)added to the engine
|
||||||
|
/// — on the main thread, before the RT thread sees the node. Any value assigned to the parameter
|
||||||
|
/// **before the first render** (e.g. restoring saved state) is therefore delivered flat, while a
|
||||||
|
/// value changed **after** the synth is running still ramps from the last rendered value.
|
||||||
|
///
|
||||||
|
/// Without this, assigning a parameter after construction leaves the ramp origin at the
|
||||||
|
/// property-declaration default, so the first block ramps default → assigned. For most
|
||||||
|
/// parameters that is a brief, benign glide; for a decision threshold feeding a `Schmidt`
|
||||||
|
/// trigger it can latch the trigger into the wrong state.
|
||||||
|
///
|
||||||
|
/// - Important: NOT RT-safe — must be called from the control side only, and only while the
|
||||||
|
/// node is not yet observed by the RT thread. It writes `previousOutputValue` (a plain
|
||||||
|
/// `Double`) without synchronisation, which is safe because `SynthesizerBase` calls it before
|
||||||
|
/// the add event is enqueued. A node shared with a synth that is already active must not be
|
||||||
|
/// primed.
|
||||||
|
func _primeRampOrigin()
|
||||||
|
}
|
||||||
|
|
||||||
|
public extension LiveParameterValue {
|
||||||
|
/// Default no-op so external conformers are not source-broken by this requirement. The two
|
||||||
|
/// in-tree conformers (`ParameterNode`, `UIParamNode`) provide real implementations.
|
||||||
|
func _primeRampOrigin() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A property wrapper that backs a synthesizer parameter with a `ParameterNode`.
|
/// A property wrapper that backs a synthesizer parameter with a `ParameterNode`.
|
||||||
|
|||||||
@@ -320,6 +320,12 @@ public final class ParameterNode: GeneratorBase, ControlGenerator, LiveParameter
|
|||||||
value = newValue
|
value = newValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `LiveParameterValue` conformance — resets the ramp origin to the current target so the next
|
||||||
|
/// block is flat (no ramp). See the protocol requirement for when `SynthesizerBase` calls this.
|
||||||
|
public func _primeRampOrigin() {
|
||||||
|
previousOutputValue = value
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Init-time priming
|
// MARK: - Init-time priming
|
||||||
|
|
||||||
/// Resets both the atomic backing and the ramp origin (`previousOutputValue`) to
|
/// Resets both the atomic backing and the ramp origin (`previousOutputValue`) to
|
||||||
|
|||||||
@@ -119,6 +119,13 @@ public final class UIParamNode: GeneratorBase, ControlGenerator, LiveParameterVa
|
|||||||
update(newValue)
|
update(newValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `LiveParameterValue` conformance — resets the ramp origin to the current target so the next
|
||||||
|
/// block is flat (no ramp). Delegates to `_node`, which owns the RT interpolation state the
|
||||||
|
/// render thread reads. See the protocol requirement for when `SynthesizerBase` calls this.
|
||||||
|
public func _primeRampOrigin() {
|
||||||
|
_node._primeRampOrigin()
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Source property (delegates to _node)
|
// MARK: - Source property (delegates to _node)
|
||||||
|
|
||||||
/// Generator wired into this parameter slot. When non-nil, the parameter's
|
/// Generator wired into this parameter slot. When non-nil, the parameter's
|
||||||
|
|||||||
@@ -666,9 +666,13 @@ open class SynthesizerBase: Synthesizer {
|
|||||||
///
|
///
|
||||||
/// **Value survival across re-add.** `parameterTable.inputs` is repopulated by
|
/// **Value survival across re-add.** `parameterTable.inputs` is repopulated by
|
||||||
/// `_autoRegisterLiveParams()` on every call, but each `@LiveParam` / `@UIParam` property
|
/// `_autoRegisterLiveParams()` on every call, but each `@LiveParam` / `@UIParam` property
|
||||||
/// wrapper holds its projected node (`ParameterNode` / `UIParamNode`) as a `let` —
|
/// wrapper holds its projected node (`ParameterNode` / `UIParamNode`) as a `let` — the same
|
||||||
/// the same instance is re-registered, so its atomic value and ramp state are preserved
|
/// instance is re-registered, so its **atomic value** is preserved across `engine.remove` +
|
||||||
/// across `engine.remove` + `engine.add` cycles.
|
/// `engine.add` cycles. The **ramp origin** is not preserved: `_autoRegisterLiveParams()`
|
||||||
|
/// re-primes it to that current value on every add (see
|
||||||
|
/// ``LiveParameterValue/_primeRampOrigin()``), so the first block after an add is flat at the
|
||||||
|
/// value in effect — a value assigned between construction (or a remove) and the add is
|
||||||
|
/// delivered without a ramp, while changes made after the synth is running still ramp.
|
||||||
///
|
///
|
||||||
/// - Precondition: the Synthesizer must NOT currently be active in the node tree.
|
/// - Precondition: the Synthesizer must NOT currently be active in the node tree.
|
||||||
/// Calling this while `evaluate()` may be running on the RT thread is a data race on
|
/// Calling this while `evaluate()` may be running on the RT thread is a data race on
|
||||||
@@ -708,7 +712,16 @@ open class SynthesizerBase: Synthesizer {
|
|||||||
guard let label: String = child.label else { continue }
|
guard let label: String = child.label else { continue }
|
||||||
let key: String = label.hasPrefix("_") ? String(label.dropFirst()) : label
|
let key: String = label.hasPrefix("_") ? String(label.dropFirst()) : label
|
||||||
if let wrapper: any LiveParameterWrapper = child.value as? LiveParameterWrapper {
|
if let wrapper: any LiveParameterWrapper = child.value as? LiveParameterWrapper {
|
||||||
parameterTable.inputs[key] = wrapper._projectedAsValidInput
|
let node: any ValidGeneratorInput = wrapper._projectedAsValidInput
|
||||||
|
parameterTable.inputs[key] = node
|
||||||
|
// Flatten the ramp origin to the value held right now (before the RT thread first
|
||||||
|
// sees this node). A value assigned after construction but before the engine
|
||||||
|
// starts — e.g. restoring saved state — is otherwise delivered as a first-block
|
||||||
|
// ramp from the property-declaration default, which can latch a downstream
|
||||||
|
// Schmidt/decision stage into the wrong state. Live changes after start still ramp.
|
||||||
|
if let primeable: any LiveParameterValue = node as? LiveParameterValue {
|
||||||
|
primeable._primeRampOrigin()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
/// The current Lyrebird framework and CLI version.
|
/// The current Lyrebird framework and CLI version.
|
||||||
public let lyrebirdVersion: String = "2.1.1"
|
public let lyrebirdVersion: String = "2.2.0"
|
||||||
|
|
||||||
/// The banner printed when the interactive shell or REPL session starts.
|
/// The banner printed when the interactive shell or REPL session starts.
|
||||||
public let welcomeBanner: String = """
|
public let welcomeBanner: String = """
|
||||||
|
|||||||
@@ -0,0 +1,120 @@
|
|||||||
|
// LiveParamRampOriginTests.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import Testing
|
||||||
|
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||||
|
|
||||||
|
/// A synth whose only output is a `@UIParam` written straight to a bus, so a rendered block
|
||||||
|
/// reveals the parameter's delivered ramp. Declaration default `0.1`.
|
||||||
|
@MainActor
|
||||||
|
private final class UIParamProbe: SynthesizerBase {
|
||||||
|
@UIParam var p: Double = 0.1
|
||||||
|
let bus: Int
|
||||||
|
init(bus: Int = 0) { self.bus = bus; super.init() }
|
||||||
|
override func build() {
|
||||||
|
output(bus: bus, source: $p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Same, but backed by `@LiveParam` (`ParameterNode`) — a separate priming code path from
|
||||||
|
/// `@UIParam`'s `UIParamNode` delegation.
|
||||||
|
@MainActor
|
||||||
|
private final class LiveParamProbe: SynthesizerBase {
|
||||||
|
@LiveParam var p: Double = 0.1
|
||||||
|
let bus: Int
|
||||||
|
init(bus: Int = 0) { self.bus = bus; super.init() }
|
||||||
|
override func build() {
|
||||||
|
output(bus: bus, source: $p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
@Suite("Live parameter ramp origin")
|
||||||
|
struct LiveParamRampOriginTests {
|
||||||
|
|
||||||
|
let engine: SynthesisEngine = makeTestEngine(blockSize: 16)
|
||||||
|
|
||||||
|
init() throws {
|
||||||
|
try engine.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func uiParamAssignedAfterConstructionIsDeliveredFlat() throws {
|
||||||
|
// Assign AFTER construction (declaration default 0.1) but BEFORE the first render. Without
|
||||||
|
// priming at add time the first block would ramp 0.1 → 0.9; the fix primes the ramp origin
|
||||||
|
// when the synth is added, so the block is flat at 0.9 from sample 0.
|
||||||
|
let probe: UIParamProbe = UIParamProbe(bus: 0)
|
||||||
|
probe.p = 0.9
|
||||||
|
try engine.add(probe)
|
||||||
|
engine.processBlock(inputSamples: [])
|
||||||
|
for i: Int in 0..<engine.blockSize {
|
||||||
|
#expect(abs(engine.audioBuses[0][i] - 0.9) < 1e-6,
|
||||||
|
"sample \(i) should be flat 0.9, not a ramp from the 0.1 default")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func liveParamAssignedAfterConstructionIsDeliveredFlat() throws {
|
||||||
|
// Same guarantee for @LiveParam (ParameterNode direct, no UIParamNode delegation).
|
||||||
|
let probe: LiveParamProbe = LiveParamProbe(bus: 0)
|
||||||
|
probe.p = 0.9
|
||||||
|
try engine.add(probe)
|
||||||
|
engine.processBlock(inputSamples: [])
|
||||||
|
for i: Int in 0..<engine.blockSize {
|
||||||
|
#expect(abs(engine.audioBuses[0][i] - 0.9) < 1e-6,
|
||||||
|
"@LiveParam sample \(i) should be flat 0.9, not a ramp from the 0.1 default")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func valueChangedWhileRunningStillRamps() throws {
|
||||||
|
// A change made while the synth is running must still ramp from the last rendered value —
|
||||||
|
// the fix must not flatten live updates, only prime the pre-first-render origin.
|
||||||
|
let probe: UIParamProbe = UIParamProbe(bus: 0) // starts at 0.1
|
||||||
|
try engine.add(probe)
|
||||||
|
engine.processBlock(inputSamples: []) // render a block, origin settles at 0.1
|
||||||
|
#expect(abs(engine.audioBuses[0][0] - 0.1) < 1e-6, "first block should be flat 0.1")
|
||||||
|
|
||||||
|
probe.p = 0.9 // live change → next block ramps
|
||||||
|
engine.processBlock(inputSamples: [])
|
||||||
|
let first: Float = engine.audioBuses[0][0]
|
||||||
|
let last: Float = engine.audioBuses[0][engine.blockSize - 1]
|
||||||
|
#expect(first < 0.9, "live change should ramp (first sample below target), got \(first)")
|
||||||
|
#expect(abs(last - 0.9) < 1e-5, "ramp should reach the target by block end, got \(last)")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func valueChangedWhileRemovedIsDeliveredFlatOnReAdd() throws {
|
||||||
|
// Add, render, remove, change the value while out of the tree, then re-add. The re-add
|
||||||
|
// re-primes the origin to the new value, so the first block after re-add is flat at 0.9
|
||||||
|
// (no glide up from the 0.1 it last rendered). Pins the "re-add re-primes" behaviour that
|
||||||
|
// the rebuildGraph doc describes.
|
||||||
|
let probe: UIParamProbe = UIParamProbe(bus: 0) // 0.1
|
||||||
|
try engine.add(probe)
|
||||||
|
engine.processBlock(inputSamples: []) // renders 0.1, origin now 0.1
|
||||||
|
_ = engine.remove(probe)
|
||||||
|
engine.processBlock(inputSamples: []) // the documented one block between remove and re-add
|
||||||
|
|
||||||
|
probe.p = 0.9 // changed while removed
|
||||||
|
try engine.add(probe)
|
||||||
|
engine.processBlock(inputSamples: [])
|
||||||
|
for i: Int in 0..<engine.blockSize {
|
||||||
|
#expect(abs(engine.audioBuses[0][i] - 0.9) < 1e-6,
|
||||||
|
"re-added synth sample \(i) should be flat 0.9, not a ramp from 0.1")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func sourceSlotSetBeforeAddIsUnaffectedByPriming() throws {
|
||||||
|
// With a generator wired into the parameter's source slot before add, the source output
|
||||||
|
// drives the block — priming the scalar ramp origin must not interfere. The source holds a
|
||||||
|
// constant 0.7, so the output is ~0.7 regardless of the 0.1 scalar default / 0.9 scalar set.
|
||||||
|
let probe: UIParamProbe = UIParamProbe(bus: 0)
|
||||||
|
probe.p = 0.9 // scalar value (should be overridden by source)
|
||||||
|
let constantSource: ParameterNode = ParameterNode(0.7)
|
||||||
|
probe.$p.source = constantSource
|
||||||
|
try engine.add(probe)
|
||||||
|
engine.processBlock(inputSamples: [])
|
||||||
|
let last: Float = engine.audioBuses[0][engine.blockSize - 1]
|
||||||
|
#expect(abs(last - 0.7) < 1e-5,
|
||||||
|
"source-slot output should be ~0.7, not the scalar value, got \(last)")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user