rename(reverb): Freeze → FreezVerb, and FreezVerb → TunedVerb

Shuffle the two new reverbs' display names:
- the spectral snapshot/hold pedal (was "Freeze") becomes "FreezVerb"
  (FreezePedal → FreezVerbPedal); its Freeze footswitch keeps its label.
- the filter-from-the-current-moment pedal (was "FreezVerb") becomes
  "TunedVerb" (FreezVerbPedal → TunedVerbPedal).

Renames the types, registry keys, category entries, classes, files and tests,
and updates the cross-reference between them. Behaviour unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-24 20:55:45 -08:00
parent b1e59d2c03
commit 4c09825c2e
10 changed files with 800 additions and 800 deletions
@@ -10,36 +10,14 @@ import LyrebirdSynth
import LyrebirdUI
@testable import LyrebirdShoeGaze
/// A source that crossfades between two tones under a `morph` parameter, so a test can capture the
/// filter on tone A, then switch to tone B and show the locked spectrum shapes B differently than
/// live tracking would.
/// A steady sine whose level can be muted mid-render via its `gain` parameter — lets a test silence
/// the live input while a snapshot is held, to prove the pad sustains from the freeze and not from
/// the ongoing signal.
@MainActor
private final class TwoToneSource: SynthesizerBase {
private let targetBus: Int
private let freqA: Double
private let freqB: Double
/// `0` = tone A, `1` = tone B.
@UIParam var morph: Double = 0.0
init(targetBus: Int, freqA: Double, freqB: Double) {
self.targetBus = targetBus
self.freqA = freqA
self.freqB = freqB
super.init()
}
override func build() {
let a: BinaryOpGenerator = OscSin.Audio(freq: freqA, mul: 0.5) * (1.0 - $morph)
let b: BinaryOpGenerator = OscSin.Audio(freq: freqB, mul: 0.5) * $morph
output(bus: targetBus, source: a + b)
}
}
/// A steady sine for the non-silent / determinism / pan / bypass checks.
@MainActor
private final class TestSineSource: SynthesizerBase {
private final class GatedSineSource: SynthesizerBase {
private let targetBus: Int
private let freq: Double
@UIParam var gain: Double = 0.5
init(targetBus: Int, freq: Double) {
self.targetBus = targetBus
@@ -48,7 +26,7 @@ private final class TestSineSource: SynthesizerBase {
}
override func build() {
output(bus: targetBus, source: OscSin.Audio(freq: freq, mul: 0.5))
output(bus: targetBus, source: OscSin.Audio(freq: freq) * $gain)
}
}
@@ -57,9 +35,9 @@ private final class TestSineSource: SynthesizerBase {
struct FreezVerbPedalTests {
private let sampleRate: Double = 44_100.0
private let toneHz: Double = 220.0
private let sineHz: Double = 220.0
// MARK: - One-shot NRT render
// MARK: - One-shot NRT render (no mid-render control)
private func render(
duration: Double,
@@ -73,13 +51,13 @@ struct FreezVerbPedalTests {
defer { try? FileManager.default.removeItem(at: url) }
let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 2)
let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
defer {
engine.busAllocator.releaseAudioBus(srcBus)
engine.busAllocator.releaseAudioBus(dstBus)
}
let source: TestSineSource = TestSineSource(targetBus: srcBus.index, freq: toneHz)
let source: GatedSineSource = GatedSineSource(targetBus: srcBus.index, freq: sineHz)
let pedal: FreezVerbPedal = FreezVerbPedal(inputBus: srcBus.index, outputBus: dstBus.index)
configure(pedal)
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index)
@@ -92,13 +70,15 @@ struct FreezVerbPedalTests {
return readStereoCAF(url: url)
}
// MARK: - Block-stepped render (mid-render capture / input morph)
// MARK: - Block-stepped render with mid-render freeze / mute control
/// Steps the engine block-by-block, invoking `onFrame` before each block so a test can engage the
/// freeze or mute the source at chosen frames. Returns the left output channel.
private func stepRender(
totalFrames: Int,
blockSize: Int,
configure: (FreezVerbPedal) -> Void,
onFrame: (_ frame: Int, _ source: TwoToneSource, _ pedal: FreezVerbPedal) -> Void
onFrame: (_ frame: Int, _ source: GatedSineSource, _ pedal: FreezVerbPedal) -> Void
) throws -> [Float] {
let numAudioBuses: Int = 64
let numControlBuses: Int = 512
@@ -114,13 +94,13 @@ struct FreezVerbPedalTests {
)
let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 2)
let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
defer {
engine.busAllocator.releaseAudioBus(srcBus)
engine.busAllocator.releaseAudioBus(dstBus)
}
let source: TwoToneSource = TwoToneSource(targetBus: srcBus.index, freqA: 180.0, freqB: 900.0)
let source: GatedSineSource = GatedSineSource(targetBus: srcBus.index, freq: sineHz)
let pedal: FreezVerbPedal = FreezVerbPedal(inputBus: srcBus.index, outputBus: dstBus.index)
configure(pedal)
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index)
@@ -151,84 +131,101 @@ struct FreezVerbPedalTests {
let b: Int = min(hiFrame, samples.count)
guard b > a else { return 0.0 }
var sum: Double = 0.0
for i: Int in a ..< b { let v: Double = Double(samples[i]); sum += v * v }
for i: Int in a ..< b {
let v: Double = Double(samples[i])
sum += v * v
}
return (sum / Double(b - a)).squareRoot()
}
private func rmsDiff(_ a: [Float], _ b: [Float], loFrame: Int, hiFrame: Int) -> Double {
let lo: Int = max(0, loFrame)
let hi: Int = min(hiFrame, min(a.count, b.count))
guard hi > lo else { return 0.0 }
var sum: Double = 0.0
for i: Int in lo ..< hi { let d: Double = Double(a[i]) - Double(b[i]); sum += d * d }
return (sum / Double(hi - lo)).squareRoot()
}
private func maxStep(_ x: [Float], lo: Int, hi: Int) -> Double {
let a: Int = max(1, lo)
let b: Int = min(hi, x.count)
guard b > a else { return 0.0 }
var m: Double = 0.0
for i: Int in a ..< b { let d: Double = abs(Double(x[i]) - Double(x[i - 1])); if d > m { m = d } }
for i: Int in a ..< b {
let d: Double = abs(Double(x[i]) - Double(x[i - 1]))
if d > m { m = d }
}
return m
}
// MARK: - Behaviour
@Test func buildsAndProducesNonSilentOutput() throws {
let out: [Float] = try render(duration: 0.8) { _ in }
// Unfrozen, the dry signal passes straight through — output is never silent.
let out: [Float] = try render(duration: 1.0) { _ in }
#expect(!out.isEmpty)
#expect(hasNonSilentOutput(out), "FreezVerb output was silent")
#expect(hasNonSilentOutput(out), "Freeze output was silent")
}
@Test func renderIsDeterministic() throws {
let a: [Float] = try render(duration: 0.8) { pedal in pedal.time = 4.0; pedal.damp = 0.4 }
let b: [Float] = try render(duration: 0.8) { pedal in pedal.time = 4.0; pedal.damp = 0.4 }
#expect(a == b, "deterministic capture-reverb renders of the same setting should be bit-identical")
// No RNG anywhere in the graph, so two identical renders are bit-identical.
let a: [Float] = try render(duration: 1.0) { pedal in pedal.verb = 0.6; pedal.tone = 0.4 }
let b: [Float] = try render(duration: 1.0) { pedal in pedal.verb = 0.6; pedal.tone = 0.4 }
#expect(a == b, "deterministic freeze-reverb renders of the same setting should be bit-identical")
}
@Test func panShiftsTheLeftLeg() throws {
// Fully wet, the output follows the panned wash. Hard left fills the left leg; hard right
// nearly empties it. (Tests exercise the left output leg; the right is board-wired live.)
let hardLeft: [Float] = try render(duration: 0.6) { pedal in pedal.mix = 1.0; pedal.pan = -1.0 }
let hardRight: [Float] = try render(duration: 0.6) { pedal in pedal.mix = 1.0; pedal.pan = 1.0 }
let leftRMS: Double = rms(hardLeft, loFrame: 0, hiFrame: hardLeft.count)
let rightRMS: Double = rms(hardRight, loFrame: 0, hiFrame: hardRight.count)
#expect(leftRMS > rightRMS * 3.0,
"panning hard left should fill the left leg far more than hard right: L \(leftRMS) vs R \(rightRMS)")
}
@Test func captureLocksTheFilterSoAChangedInputIsShapedDifferently() throws {
// Capture the filter on tone A, then morph the input to tone B. A locked filter (shaped by A)
// masks B differently than a filter that keeps tracking the live input — so the two renders
// diverge once the input has changed.
@Test func snapshotSustainsAfterInputStops() throws {
// The defining behaviour: engage Freeze while a tone plays, then MUTE the input. A held
// spectral snapshot keeps ringing; without the freeze the pad gate is shut, so once the dry
// input is gone the output falls silent. Compare the two in the same late window.
let blockSize: Int = 512
let totalFrames: Int = Int(1.4 * sampleRate)
let captureFrame: Int = Int(0.4 * sampleRate)
let morphFrame: Int = Int(0.6 * sampleRate)
let windowLo: Int = Int(0.95 * sampleRate)
let windowHi: Int = Int(1.35 * sampleRate)
let totalFrames: Int = Int(1.6 * sampleRate)
let freezeFrame: Int = Int(0.45 * sampleRate)
let muteFrame: Int = Int(0.75 * sampleRate)
let windowLo: Int = Int(1.1 * sampleRate)
let windowHi: Int = Int(1.5 * sampleRate)
var captured: Bool = false
let locked: [Float] = try stepRender(totalFrames: totalFrames, blockSize: blockSize) { pedal in
pedal.mix = 1.0; pedal.time = 3.0
let frozen: [Float] = try stepRender(totalFrames: totalFrames, blockSize: blockSize) { pedal in
pedal.verb = 0.6; pedal.tone = 0.5; pedal.rise = 0.05
} onFrame: { frame, source, pedal in
if frame >= captureFrame, !captured { pedal.toggleCapture(); captured = true }
if frame >= morphFrame { source.morph = 1.0 } // switch to tone B
if frame >= freezeFrame, !pedal.holding { pedal.toggleFreeze() }
if frame >= muteFrame { source.gain = 0.0 }
}
let tracking: [Float] = try stepRender(totalFrames: totalFrames, blockSize: blockSize) { pedal in
pedal.mix = 1.0; pedal.time = 3.0
let control: [Float] = try stepRender(totalFrames: totalFrames, blockSize: blockSize) { pedal in
pedal.verb = 0.6; pedal.tone = 0.5; pedal.rise = 0.05
} onFrame: { frame, source, _ in
// Never capture; morph at the same frame.
if frame >= morphFrame { source.morph = 1.0 }
// Never freeze; mute at the same frame.
if frame >= muteFrame { source.gain = 0.0 }
}
let signal: Double = rms(tracking, loFrame: windowLo, hiFrame: windowHi)
let diff: Double = rmsDiff(locked, tracking, loFrame: windowLo, hiFrame: windowHi)
#expect(signal > 1.0e-4, "control render should be audible on tone B, got \(signal)")
#expect(diff > signal * 0.25,
"a captured filter should shape the changed input differently: diff \(diff) vs signal \(signal)")
let heldTail: Double = rms(frozen, loFrame: windowLo, hiFrame: windowHi)
let unfrozenTail: Double = rms(control, loFrame: windowLo, hiFrame: windowHi)
#expect(heldTail > 1.0e-3, "a held snapshot should still ring after the input stops, tail RMS \(heldTail)")
#expect(heldTail > unfrozenTail * 10.0,
"frozen tail \(heldTail) should dwarf the unfrozen tail \(unfrozenTail) once the input is muted")
}
@Test func releaseFadesThePadOut() throws {
// Freeze, mute the input, then release: after the Rise fade the held pad should fall away,
// leaving the late window far quieter than while it was held.
let blockSize: Int = 512
let totalFrames: Int = Int(2.0 * sampleRate)
let freezeFrame: Int = Int(0.4 * sampleRate)
let muteFrame: Int = Int(0.7 * sampleRate)
let releaseFrame: Int = Int(1.1 * sampleRate)
let heldLo: Int = Int(0.95 * sampleRate)
let heldHi: Int = Int(1.05 * sampleRate)
let afterLo: Int = Int(1.7 * sampleRate)
let afterHi: Int = Int(1.95 * sampleRate)
var froze: Bool = false
var released: Bool = false
let out: [Float] = try stepRender(totalFrames: totalFrames, blockSize: blockSize) { pedal in
pedal.verb = 0.5; pedal.tone = 0.5; pedal.rise = 0.1
} onFrame: { frame, source, pedal in
if frame >= freezeFrame, !froze { pedal.toggleFreeze(); froze = true }
if frame >= muteFrame { source.gain = 0.0 }
if frame >= releaseFrame, froze, !released { pedal.toggleFreeze(); released = true }
}
let heldRMS: Double = rms(out, loFrame: heldLo, hiFrame: heldHi)
let afterRMS: Double = rms(out, loFrame: afterLo, hiFrame: afterHi)
#expect(heldRMS > 1.0e-3, "pad should be audible while held, got \(heldRMS)")
#expect(afterRMS < heldRMS * 0.5, "releasing should fade the pad out: after \(afterRMS) vs held \(heldRMS)")
}
// MARK: - Bypass
@@ -237,11 +234,12 @@ struct FreezVerbPedalTests {
let blockSize: Int = 512
let totalFrames: Int = Int(0.6 * sampleRate)
let flipFrame: Int = Int(0.35 * sampleRate)
// Steady-state window ends before the flip; a settle margin after it covers the fade tail.
let steadyLo: Int = Int(0.22 * sampleRate)
let steadyHi: Int = Int(0.33 * sampleRate)
let settleMargin: Int = Int(0.045 * sampleRate)
let left: [Float] = try stepRender(totalFrames: totalFrames, blockSize: blockSize) { pedal in
pedal.mix = 0.5
pedal.verb = 0.5
} onFrame: { frame, _, pedal in
if frame >= flipFrame { pedal.bypass = 1.0 }
}
@@ -258,49 +256,54 @@ struct FreezVerbPedalTests {
@Test func exposesControls() throws {
let pedal: FreezVerbPedal = FreezVerbPedal()
#expect(pedal.effectKnobs.map { $0.label } == ["Time", "Damp", "Pan"])
#expect(pedal.effectTransportButtons.map { $0.label } == ["Capture"])
#expect(pedal.channelKind == .widener)
#expect(pedal.effectKnobs.map { $0.label } == ["Verb", "Tone", "Rise"])
#expect(pedal.effectTransportButtons.map { $0.label } == ["Freeze"])
#expect(pedal.showsMixControl == false)
}
@Test func captureTogglesHoldState() throws {
@Test func freezeTogglesHoldState() throws {
// The transport latch flips the held state without needing a running engine.
let pedal: FreezVerbPedal = FreezVerbPedal()
#expect(pedal.holding == false)
pedal.toggleCapture()
pedal.toggleFreeze()
#expect(pedal.holding == true)
#expect(pedal.captured == 1.0)
pedal.toggleCapture()
#expect(pedal.frozen == 1.0)
pedal.toggleFreeze()
#expect(pedal.holding == false)
#expect(pedal.captured == 0.0)
#expect(pedal.frozen == 0.0)
}
@Test func presetRoundTripPreservesControls() throws {
let pedal: FreezVerbPedal = FreezVerbPedal()
pedal.time = 8.5
pedal.damp = 0.7
pedal.pan = -0.6
pedal.verb = 0.33
pedal.tone = 0.8
pedal.rise = 1.5
let state: PedalState = pedal.captureState()
let restored: FreezVerbPedal = FreezVerbPedal()
restored.applyState(state)
#expect(restored.time == 8.5)
#expect(restored.damp == 0.7)
#expect(restored.pan == -0.6)
#expect(restored.verb == 0.33)
#expect(restored.tone == 0.8)
#expect(restored.rise == 1.5)
}
@Test func capturedStateIsNotPersisted() throws {
// `captured` is transport state, not a preset control.
@Test func heldSnapshotIsNotPersisted() throws {
// `frozen` is transport state, not a preset control: a pedal captured mid-freeze must restore
// released, with no phantom pad blooming on load.
let pedal: FreezVerbPedal = FreezVerbPedal()
pedal.toggleCapture()
#expect(pedal.captured == 1.0)
pedal.verb = 0.4
pedal.toggleFreeze()
#expect(pedal.holding == true)
#expect(pedal.frozen == 1.0)
let state: PedalState = pedal.captureState()
let restored: FreezVerbPedal = FreezVerbPedal()
restored.applyState(state)
#expect(restored.captured == 0.0, "a locked filter must not persist into a preset")
#expect(restored.frozen == 0.0, "a held snapshot must not persist into a preset")
#expect(restored.holding == false)
#expect(restored.verb == 0.4)
}
@Test func registeredInBuiltInRegistry() throws {
@@ -1,313 +0,0 @@
// FreezePedalTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
import Foundation
import LyrebirdSynth
import LyrebirdUI
@testable import LyrebirdShoeGaze
/// A steady sine whose level can be muted mid-render via its `gain` parameter — lets a test silence
/// the live input while a snapshot is held, to prove the pad sustains from the freeze and not from
/// the ongoing signal.
@MainActor
private final class GatedSineSource: SynthesizerBase {
private let targetBus: Int
private let freq: Double
@UIParam var gain: Double = 0.5
init(targetBus: Int, freq: Double) {
self.targetBus = targetBus
self.freq = freq
super.init()
}
override func build() {
output(bus: targetBus, source: OscSin.Audio(freq: freq) * $gain)
}
}
@MainActor
@Suite("FreezePedal")
struct FreezePedalTests {
private let sampleRate: Double = 44_100.0
private let sineHz: Double = 220.0
// MARK: - One-shot NRT render (no mid-render control)
private func render(
duration: Double,
configure: (FreezePedal) -> Void
) throws -> [Float] {
let numAudioBuses: Int = 64
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
duration: duration,
numAudioBuses: numAudioBuses
)
defer { try? FileManager.default.removeItem(at: url) }
let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
defer {
engine.busAllocator.releaseAudioBus(srcBus)
engine.busAllocator.releaseAudioBus(dstBus)
}
let source: GatedSineSource = GatedSineSource(targetBus: srcBus.index, freq: sineHz)
let pedal: FreezePedal = FreezePedal(inputBus: srcBus.index, outputBus: dstBus.index)
configure(pedal)
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index)
try engine.add(source)
try engine.add(pedal, position: NodePosition.after(source))
try engine.add(master, position: NodePosition.after(pedal))
try engine.start()
return readStereoCAF(url: url)
}
// MARK: - Block-stepped render with mid-render freeze / mute control
/// Steps the engine block-by-block, invoking `onFrame` before each block so a test can engage the
/// freeze or mute the source at chosen frames. Returns the left output channel.
private func stepRender(
totalFrames: Int,
blockSize: Int,
configure: (FreezePedal) -> Void,
onFrame: (_ frame: Int, _ source: GatedSineSource, _ pedal: FreezePedal) -> Void
) throws -> [Float] {
let numAudioBuses: Int = 64
let numControlBuses: Int = 512
let driver: OfflineDriver = OfflineDriver()
let engine: SynthesisEngine = SynthesisEngine(
blockSize: blockSize,
sampleRate: sampleRate,
numOutputChannels: 2,
numInputChannels: 0,
numAudioBuses: numAudioBuses,
numControlBuses: numControlBuses,
driver: driver
)
let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
defer {
engine.busAllocator.releaseAudioBus(srcBus)
engine.busAllocator.releaseAudioBus(dstBus)
}
let source: GatedSineSource = GatedSineSource(targetBus: srcBus.index, freq: sineHz)
let pedal: FreezePedal = FreezePedal(inputBus: srcBus.index, outputBus: dstBus.index)
configure(pedal)
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index)
try engine.add(source)
try engine.add(pedal, position: NodePosition.after(source))
try engine.add(master, position: NodePosition.after(pedal))
try engine.start()
let noInput: [[Float]] = []
var left: [Float] = []
left.reserveCapacity(totalFrames)
var frame: Int = 0
while frame < totalFrames {
onFrame(frame, source, pedal)
engine.processBlock(inputSamples: noInput)
left.append(contentsOf: engine.audioBuses[0])
frame += blockSize
}
engine.stop()
return left
}
// MARK: - Analysis
private func rms(_ samples: [Float], loFrame: Int, hiFrame: Int) -> Double {
let a: Int = max(0, loFrame)
let b: Int = min(hiFrame, samples.count)
guard b > a else { return 0.0 }
var sum: Double = 0.0
for i: Int in a ..< b {
let v: Double = Double(samples[i])
sum += v * v
}
return (sum / Double(b - a)).squareRoot()
}
private func maxStep(_ x: [Float], lo: Int, hi: Int) -> Double {
let a: Int = max(1, lo)
let b: Int = min(hi, x.count)
guard b > a else { return 0.0 }
var m: Double = 0.0
for i: Int in a ..< b {
let d: Double = abs(Double(x[i]) - Double(x[i - 1]))
if d > m { m = d }
}
return m
}
// MARK: - Behaviour
@Test func buildsAndProducesNonSilentOutput() throws {
// Unfrozen, the dry signal passes straight through — output is never silent.
let out: [Float] = try render(duration: 1.0) { _ in }
#expect(!out.isEmpty)
#expect(hasNonSilentOutput(out), "Freeze output was silent")
}
@Test func renderIsDeterministic() throws {
// No RNG anywhere in the graph, so two identical renders are bit-identical.
let a: [Float] = try render(duration: 1.0) { pedal in pedal.verb = 0.6; pedal.tone = 0.4 }
let b: [Float] = try render(duration: 1.0) { pedal in pedal.verb = 0.6; pedal.tone = 0.4 }
#expect(a == b, "deterministic freeze-reverb renders of the same setting should be bit-identical")
}
@Test func snapshotSustainsAfterInputStops() throws {
// The defining behaviour: engage Freeze while a tone plays, then MUTE the input. A held
// spectral snapshot keeps ringing; without the freeze the pad gate is shut, so once the dry
// input is gone the output falls silent. Compare the two in the same late window.
let blockSize: Int = 512
let totalFrames: Int = Int(1.6 * sampleRate)
let freezeFrame: Int = Int(0.45 * sampleRate)
let muteFrame: Int = Int(0.75 * sampleRate)
let windowLo: Int = Int(1.1 * sampleRate)
let windowHi: Int = Int(1.5 * sampleRate)
let frozen: [Float] = try stepRender(totalFrames: totalFrames, blockSize: blockSize) { pedal in
pedal.verb = 0.6; pedal.tone = 0.5; pedal.rise = 0.05
} onFrame: { frame, source, pedal in
if frame >= freezeFrame, !pedal.holding { pedal.toggleFreeze() }
if frame >= muteFrame { source.gain = 0.0 }
}
let control: [Float] = try stepRender(totalFrames: totalFrames, blockSize: blockSize) { pedal in
pedal.verb = 0.6; pedal.tone = 0.5; pedal.rise = 0.05
} onFrame: { frame, source, _ in
// Never freeze; mute at the same frame.
if frame >= muteFrame { source.gain = 0.0 }
}
let heldTail: Double = rms(frozen, loFrame: windowLo, hiFrame: windowHi)
let unfrozenTail: Double = rms(control, loFrame: windowLo, hiFrame: windowHi)
#expect(heldTail > 1.0e-3, "a held snapshot should still ring after the input stops, tail RMS \(heldTail)")
#expect(heldTail > unfrozenTail * 10.0,
"frozen tail \(heldTail) should dwarf the unfrozen tail \(unfrozenTail) once the input is muted")
}
@Test func releaseFadesThePadOut() throws {
// Freeze, mute the input, then release: after the Rise fade the held pad should fall away,
// leaving the late window far quieter than while it was held.
let blockSize: Int = 512
let totalFrames: Int = Int(2.0 * sampleRate)
let freezeFrame: Int = Int(0.4 * sampleRate)
let muteFrame: Int = Int(0.7 * sampleRate)
let releaseFrame: Int = Int(1.1 * sampleRate)
let heldLo: Int = Int(0.95 * sampleRate)
let heldHi: Int = Int(1.05 * sampleRate)
let afterLo: Int = Int(1.7 * sampleRate)
let afterHi: Int = Int(1.95 * sampleRate)
var froze: Bool = false
var released: Bool = false
let out: [Float] = try stepRender(totalFrames: totalFrames, blockSize: blockSize) { pedal in
pedal.verb = 0.5; pedal.tone = 0.5; pedal.rise = 0.1
} onFrame: { frame, source, pedal in
if frame >= freezeFrame, !froze { pedal.toggleFreeze(); froze = true }
if frame >= muteFrame { source.gain = 0.0 }
if frame >= releaseFrame, froze, !released { pedal.toggleFreeze(); released = true }
}
let heldRMS: Double = rms(out, loFrame: heldLo, hiFrame: heldHi)
let afterRMS: Double = rms(out, loFrame: afterLo, hiFrame: afterHi)
#expect(heldRMS > 1.0e-3, "pad should be audible while held, got \(heldRMS)")
#expect(afterRMS < heldRMS * 0.5, "releasing should fade the pad out: after \(afterRMS) vs held \(heldRMS)")
}
// MARK: - Bypass
@Test func bypassSwitchIsClickFree() throws {
let blockSize: Int = 512
let totalFrames: Int = Int(0.6 * sampleRate)
let flipFrame: Int = Int(0.35 * sampleRate)
// Steady-state window ends before the flip; a settle margin after it covers the fade tail.
let steadyLo: Int = Int(0.22 * sampleRate)
let steadyHi: Int = Int(0.33 * sampleRate)
let settleMargin: Int = Int(0.045 * sampleRate)
let left: [Float] = try stepRender(totalFrames: totalFrames, blockSize: blockSize) { pedal in
pedal.verb = 0.5
} onFrame: { frame, _, pedal in
if frame >= flipFrame { pedal.bypass = 1.0 }
}
#expect(hasNonSilentOutput(left), "bypass-flip render was silent")
let steadyStep: Double = maxStep(left, lo: steadyLo, hi: steadyHi)
let fadeFrames: Int = Int(0.03 * sampleRate)
let transStep: Double = maxStep(left, lo: flipFrame - blockSize, hi: flipFrame + fadeFrames + settleMargin)
#expect(transStep <= steadyStep * 4.0,
"bypass transition stepped \(transStep) vs steady \(steadyStep) — a click leaked through")
}
// MARK: - Wiring
@Test func exposesControls() throws {
let pedal: FreezePedal = FreezePedal()
#expect(pedal.effectKnobs.map { $0.label } == ["Verb", "Tone", "Rise"])
#expect(pedal.effectTransportButtons.map { $0.label } == ["Freeze"])
#expect(pedal.showsMixControl == false)
}
@Test func freezeTogglesHoldState() throws {
// The transport latch flips the held state without needing a running engine.
let pedal: FreezePedal = FreezePedal()
#expect(pedal.holding == false)
pedal.toggleFreeze()
#expect(pedal.holding == true)
#expect(pedal.frozen == 1.0)
pedal.toggleFreeze()
#expect(pedal.holding == false)
#expect(pedal.frozen == 0.0)
}
@Test func presetRoundTripPreservesControls() throws {
let pedal: FreezePedal = FreezePedal()
pedal.verb = 0.33
pedal.tone = 0.8
pedal.rise = 1.5
let state: PedalState = pedal.captureState()
let restored: FreezePedal = FreezePedal()
restored.applyState(state)
#expect(restored.verb == 0.33)
#expect(restored.tone == 0.8)
#expect(restored.rise == 1.5)
}
@Test func heldSnapshotIsNotPersisted() throws {
// `frozen` is transport state, not a preset control: a pedal captured mid-freeze must restore
// released, with no phantom pad blooming on load.
let pedal: FreezePedal = FreezePedal()
pedal.verb = 0.4
pedal.toggleFreeze()
#expect(pedal.holding == true)
#expect(pedal.frozen == 1.0)
let state: PedalState = pedal.captureState()
let restored: FreezePedal = FreezePedal()
restored.applyState(state)
#expect(restored.frozen == 0.0, "a held snapshot must not persist into a preset")
#expect(restored.holding == false)
#expect(restored.verb == 0.4)
}
@Test func registeredInBuiltInRegistry() throws {
let pedal: Pedal? = PedalRegistry.makePedal(type: "Freeze")
#expect(pedal is FreezePedal)
}
}
@@ -0,0 +1,310 @@
// TunedVerbPedalTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
import Foundation
import LyrebirdSynth
import LyrebirdUI
@testable import LyrebirdShoeGaze
/// A source that crossfades between two tones under a `morph` parameter, so a test can capture the
/// filter on tone A, then switch to tone B and show the locked spectrum shapes B differently than
/// live tracking would.
@MainActor
private final class TwoToneSource: SynthesizerBase {
private let targetBus: Int
private let freqA: Double
private let freqB: Double
/// `0` = tone A, `1` = tone B.
@UIParam var morph: Double = 0.0
init(targetBus: Int, freqA: Double, freqB: Double) {
self.targetBus = targetBus
self.freqA = freqA
self.freqB = freqB
super.init()
}
override func build() {
let a: BinaryOpGenerator = OscSin.Audio(freq: freqA, mul: 0.5) * (1.0 - $morph)
let b: BinaryOpGenerator = OscSin.Audio(freq: freqB, mul: 0.5) * $morph
output(bus: targetBus, source: a + b)
}
}
/// A steady sine for the non-silent / determinism / pan / bypass checks.
@MainActor
private final class TestSineSource: SynthesizerBase {
private let targetBus: Int
private let freq: Double
init(targetBus: Int, freq: Double) {
self.targetBus = targetBus
self.freq = freq
super.init()
}
override func build() {
output(bus: targetBus, source: OscSin.Audio(freq: freq, mul: 0.5))
}
}
@MainActor
@Suite("TunedVerbPedal")
struct TunedVerbPedalTests {
private let sampleRate: Double = 44_100.0
private let toneHz: Double = 220.0
// MARK: - One-shot NRT render
private func render(
duration: Double,
configure: (TunedVerbPedal) -> Void
) throws -> [Float] {
let numAudioBuses: Int = 64
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
duration: duration,
numAudioBuses: numAudioBuses
)
defer { try? FileManager.default.removeItem(at: url) }
let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 2)
defer {
engine.busAllocator.releaseAudioBus(srcBus)
engine.busAllocator.releaseAudioBus(dstBus)
}
let source: TestSineSource = TestSineSource(targetBus: srcBus.index, freq: toneHz)
let pedal: TunedVerbPedal = TunedVerbPedal(inputBus: srcBus.index, outputBus: dstBus.index)
configure(pedal)
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index)
try engine.add(source)
try engine.add(pedal, position: NodePosition.after(source))
try engine.add(master, position: NodePosition.after(pedal))
try engine.start()
return readStereoCAF(url: url)
}
// MARK: - Block-stepped render (mid-render capture / input morph)
private func stepRender(
totalFrames: Int,
blockSize: Int,
configure: (TunedVerbPedal) -> Void,
onFrame: (_ frame: Int, _ source: TwoToneSource, _ pedal: TunedVerbPedal) -> Void
) throws -> [Float] {
let numAudioBuses: Int = 64
let numControlBuses: Int = 512
let driver: OfflineDriver = OfflineDriver()
let engine: SynthesisEngine = SynthesisEngine(
blockSize: blockSize,
sampleRate: sampleRate,
numOutputChannels: 2,
numInputChannels: 0,
numAudioBuses: numAudioBuses,
numControlBuses: numControlBuses,
driver: driver
)
let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 2)
defer {
engine.busAllocator.releaseAudioBus(srcBus)
engine.busAllocator.releaseAudioBus(dstBus)
}
let source: TwoToneSource = TwoToneSource(targetBus: srcBus.index, freqA: 180.0, freqB: 900.0)
let pedal: TunedVerbPedal = TunedVerbPedal(inputBus: srcBus.index, outputBus: dstBus.index)
configure(pedal)
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index)
try engine.add(source)
try engine.add(pedal, position: NodePosition.after(source))
try engine.add(master, position: NodePosition.after(pedal))
try engine.start()
let noInput: [[Float]] = []
var left: [Float] = []
left.reserveCapacity(totalFrames)
var frame: Int = 0
while frame < totalFrames {
onFrame(frame, source, pedal)
engine.processBlock(inputSamples: noInput)
left.append(contentsOf: engine.audioBuses[0])
frame += blockSize
}
engine.stop()
return left
}
// MARK: - Analysis
private func rms(_ samples: [Float], loFrame: Int, hiFrame: Int) -> Double {
let a: Int = max(0, loFrame)
let b: Int = min(hiFrame, samples.count)
guard b > a else { return 0.0 }
var sum: Double = 0.0
for i: Int in a ..< b { let v: Double = Double(samples[i]); sum += v * v }
return (sum / Double(b - a)).squareRoot()
}
private func rmsDiff(_ a: [Float], _ b: [Float], loFrame: Int, hiFrame: Int) -> Double {
let lo: Int = max(0, loFrame)
let hi: Int = min(hiFrame, min(a.count, b.count))
guard hi > lo else { return 0.0 }
var sum: Double = 0.0
for i: Int in lo ..< hi { let d: Double = Double(a[i]) - Double(b[i]); sum += d * d }
return (sum / Double(hi - lo)).squareRoot()
}
private func maxStep(_ x: [Float], lo: Int, hi: Int) -> Double {
let a: Int = max(1, lo)
let b: Int = min(hi, x.count)
guard b > a else { return 0.0 }
var m: Double = 0.0
for i: Int in a ..< b { let d: Double = abs(Double(x[i]) - Double(x[i - 1])); if d > m { m = d } }
return m
}
// MARK: - Behaviour
@Test func buildsAndProducesNonSilentOutput() throws {
let out: [Float] = try render(duration: 0.8) { _ in }
#expect(!out.isEmpty)
#expect(hasNonSilentOutput(out), "TunedVerb output was silent")
}
@Test func renderIsDeterministic() throws {
let a: [Float] = try render(duration: 0.8) { pedal in pedal.time = 4.0; pedal.damp = 0.4 }
let b: [Float] = try render(duration: 0.8) { pedal in pedal.time = 4.0; pedal.damp = 0.4 }
#expect(a == b, "deterministic capture-reverb renders of the same setting should be bit-identical")
}
@Test func panShiftsTheLeftLeg() throws {
// Fully wet, the output follows the panned wash. Hard left fills the left leg; hard right
// nearly empties it. (Tests exercise the left output leg; the right is board-wired live.)
let hardLeft: [Float] = try render(duration: 0.6) { pedal in pedal.mix = 1.0; pedal.pan = -1.0 }
let hardRight: [Float] = try render(duration: 0.6) { pedal in pedal.mix = 1.0; pedal.pan = 1.0 }
let leftRMS: Double = rms(hardLeft, loFrame: 0, hiFrame: hardLeft.count)
let rightRMS: Double = rms(hardRight, loFrame: 0, hiFrame: hardRight.count)
#expect(leftRMS > rightRMS * 3.0,
"panning hard left should fill the left leg far more than hard right: L \(leftRMS) vs R \(rightRMS)")
}
@Test func captureLocksTheFilterSoAChangedInputIsShapedDifferently() throws {
// Capture the filter on tone A, then morph the input to tone B. A locked filter (shaped by A)
// masks B differently than a filter that keeps tracking the live input — so the two renders
// diverge once the input has changed.
let blockSize: Int = 512
let totalFrames: Int = Int(1.4 * sampleRate)
let captureFrame: Int = Int(0.4 * sampleRate)
let morphFrame: Int = Int(0.6 * sampleRate)
let windowLo: Int = Int(0.95 * sampleRate)
let windowHi: Int = Int(1.35 * sampleRate)
var captured: Bool = false
let locked: [Float] = try stepRender(totalFrames: totalFrames, blockSize: blockSize) { pedal in
pedal.mix = 1.0; pedal.time = 3.0
} onFrame: { frame, source, pedal in
if frame >= captureFrame, !captured { pedal.toggleCapture(); captured = true }
if frame >= morphFrame { source.morph = 1.0 } // switch to tone B
}
let tracking: [Float] = try stepRender(totalFrames: totalFrames, blockSize: blockSize) { pedal in
pedal.mix = 1.0; pedal.time = 3.0
} onFrame: { frame, source, _ in
// Never capture; morph at the same frame.
if frame >= morphFrame { source.morph = 1.0 }
}
let signal: Double = rms(tracking, loFrame: windowLo, hiFrame: windowHi)
let diff: Double = rmsDiff(locked, tracking, loFrame: windowLo, hiFrame: windowHi)
#expect(signal > 1.0e-4, "control render should be audible on tone B, got \(signal)")
#expect(diff > signal * 0.25,
"a captured filter should shape the changed input differently: diff \(diff) vs signal \(signal)")
}
// MARK: - Bypass
@Test func bypassSwitchIsClickFree() throws {
let blockSize: Int = 512
let totalFrames: Int = Int(0.6 * sampleRate)
let flipFrame: Int = Int(0.35 * sampleRate)
let steadyLo: Int = Int(0.22 * sampleRate)
let steadyHi: Int = Int(0.33 * sampleRate)
let settleMargin: Int = Int(0.045 * sampleRate)
let left: [Float] = try stepRender(totalFrames: totalFrames, blockSize: blockSize) { pedal in
pedal.mix = 0.5
} onFrame: { frame, _, pedal in
if frame >= flipFrame { pedal.bypass = 1.0 }
}
#expect(hasNonSilentOutput(left), "bypass-flip render was silent")
let steadyStep: Double = maxStep(left, lo: steadyLo, hi: steadyHi)
let fadeFrames: Int = Int(0.03 * sampleRate)
let transStep: Double = maxStep(left, lo: flipFrame - blockSize, hi: flipFrame + fadeFrames + settleMargin)
#expect(transStep <= steadyStep * 4.0,
"bypass transition stepped \(transStep) vs steady \(steadyStep) — a click leaked through")
}
// MARK: - Wiring
@Test func exposesControls() throws {
let pedal: TunedVerbPedal = TunedVerbPedal()
#expect(pedal.effectKnobs.map { $0.label } == ["Time", "Damp", "Pan"])
#expect(pedal.effectTransportButtons.map { $0.label } == ["Capture"])
#expect(pedal.channelKind == .widener)
}
@Test func captureTogglesHoldState() throws {
let pedal: TunedVerbPedal = TunedVerbPedal()
#expect(pedal.holding == false)
pedal.toggleCapture()
#expect(pedal.holding == true)
#expect(pedal.captured == 1.0)
pedal.toggleCapture()
#expect(pedal.holding == false)
#expect(pedal.captured == 0.0)
}
@Test func presetRoundTripPreservesControls() throws {
let pedal: TunedVerbPedal = TunedVerbPedal()
pedal.time = 8.5
pedal.damp = 0.7
pedal.pan = -0.6
let state: PedalState = pedal.captureState()
let restored: TunedVerbPedal = TunedVerbPedal()
restored.applyState(state)
#expect(restored.time == 8.5)
#expect(restored.damp == 0.7)
#expect(restored.pan == -0.6)
}
@Test func capturedStateIsNotPersisted() throws {
// `captured` is transport state, not a preset control.
let pedal: TunedVerbPedal = TunedVerbPedal()
pedal.toggleCapture()
#expect(pedal.captured == 1.0)
let state: PedalState = pedal.captureState()
let restored: TunedVerbPedal = TunedVerbPedal()
restored.applyState(state)
#expect(restored.captured == 0.0, "a locked filter must not persist into a preset")
#expect(restored.holding == false)
}
@Test func registeredInBuiltInRegistry() throws {
let pedal: Pedal? = PedalRegistry.makePedal(type: "TunedVerb")
#expect(pedal is TunedVerbPedal)
}
}