v2.2.0 release: live-parameter ramp origin primed at synth add
A @UIParam/@LiveParam value assigned after construction but before the first render is now delivered flat on the first block instead of ramping from the property- declaration default (fixes e.g. a NoiseGate restored from saved rig state latching open and ignoring its threshold). Backed by a new internal-facing LiveParameterValue._primeRampOrigin() (default no-op, source-compatible); live changes after start still ramp. See RELEASES.md for the full behavior-change note. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -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