Files
ShoeGaze/Tests/LyrebirdShoeGazeTests/FullertonReverbAmpPedalTests.swift
T
josh 27fb6e6898 fix(amps): disambiguate Reverb footswitch label; comment bypass test
Review nits: rename the reverb-enable switch "Reverb" → "Reverb FX" so it no
longer collides with the "Reverb" level knob in the flat control surface
(clearer, better for VoiceOver). Note in the vibrato bypass test why the
differing speed between the two renders is intentional (depth gated to 0 makes
the LFO a constant regardless of frequency).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-03 07:59:12 -07:00

157 lines
7.0 KiB
Swift

// FullertonReverbAmpPedalTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
import Foundation
import LyrebirdSynth
import LyrebirdUI
@testable import LyrebirdShoeGaze
@MainActor
@Suite("FullertonReverbAmpPedal")
struct FullertonReverbAmpPedalTests {
private let sampleRate: Double = 48000.0
private func render(configure: (FullertonReverbAmpPedal) -> Void = { _ in }) throws -> [Float] {
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
duration: 0.3, sampleRate: sampleRate, numAudioBuses: 64)
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: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
let pedal: FullertonReverbAmpPedal = FullertonReverbAmpPedal(
inputBus: srcBus.index, outputBus: dstBus.index)
pedal.sampleRate = sampleRate
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, sampleRate: sampleRate)
}
private func windowedSSD(_ a: [Float], _ b: [Float], skip: Int = 4096, window: Int = 4096) -> Double {
guard a.count >= skip + window, b.count >= skip + window else { return 0.0 }
return zip(a[skip..<(skip + window)], b[skip..<(skip + window)]).reduce(0.0) { acc, pair in
let d: Double = Double(pair.0 - pair.1); return acc + d * d
}
}
@Test func buildsNonSilentFiniteOutput() throws {
let samples: [Float] = try render()
#expect(!samples.isEmpty)
#expect(hasNonSilentOutput(samples), "Fullerton Reverb produced silence")
#expect(samples.allSatisfy { $0.isFinite }, "Fullerton Reverb produced non-finite output")
}
@Test func reverbMixChangesOutput() throws {
let dry: [Float] = try render { $0.reverb = 0.0 }
let wet: [Float] = try render { $0.reverb = 0.9 }
#expect(windowedSSD(dry, wet) > 0, "reverb mix had no effect")
}
@Test func tremoloIntensityChangesOutput() throws {
let off: [Float] = try render { $0.intensity = 0.0 }
let on: [Float] = try render { $0.intensity = 1.0; $0.speed = 6.0 }
#expect(windowedSSD(off, on) > 0, "tremolo intensity had no effect")
}
@Test func tremoloSpeedChangesOutput() throws {
let slow: [Float] = try render { $0.intensity = 1.0; $0.speed = 1.0 }
let fast: [Float] = try render { $0.intensity = 1.0; $0.speed = 10.0 }
#expect(windowedSSD(slow, fast) > 0, "tremolo speed had no effect")
}
@Test func brightSwitchChangesOutput() throws {
let flat: [Float] = try render { $0.bright = 0.0 }
let bright: [Float] = try render { $0.bright = 1.0 }
#expect(windowedSSD(flat, bright) > 0, "bright switch had no effect")
}
@Test func reverbFootswitchBypassesToDry() throws {
// Footswitch off with the Reverb knob up must equal the dry signal (knob at 0), and must
// differ from the same knob with the footswitch on.
let bypassed: [Float] = try render { $0.reverb = 0.9; $0.reverbEnabled = 0.0 }
let dry: [Float] = try render { $0.reverb = 0.0; $0.reverbEnabled = 1.0 }
#expect(windowedSSD(bypassed, dry) == 0.0, "reverb footswitch off should be a dry pass-through")
let engaged: [Float] = try render { $0.reverb = 0.9; $0.reverbEnabled = 1.0 }
#expect(windowedSSD(bypassed, engaged) > 0, "reverb footswitch had no effect")
}
@Test func vibratoFootswitchBypassesToIdentity() throws {
// Footswitch off with Intensity up must equal no tremolo (Intensity 0), and must differ
// from the same Intensity with the footswitch on. The differing `speed` is intentional and
// harmless: with depth gated to 0 the LFO is a constant 1.0 regardless of its frequency.
let bypassed: [Float] = try render { $0.intensity = 1.0; $0.speed = 6.0; $0.vibratoEnabled = 0.0 }
let noTremolo: [Float] = try render { $0.intensity = 0.0 }
#expect(windowedSSD(bypassed, noTremolo) == 0.0, "vibrato footswitch off should be identity")
let engaged: [Float] = try render { $0.intensity = 1.0; $0.speed = 6.0; $0.vibratoEnabled = 1.0 }
#expect(windowedSSD(bypassed, engaged) > 0, "vibrato footswitch had no effect")
}
@Test func outputStaysWithinCeilingWithFXEngaged() throws {
let ceilingEpsilon: Double = 1.0e-4
let hot: [Float] = try render { (pedal: FullertonReverbAmpPedal) in
pedal.gain = 30.0
pedal.bass = 1.0
pedal.treble = 1.0
pedal.reverb = 1.0
pedal.bright = 1.0
pedal.intensity = 1.0
pedal.speed = 6.0
}
let peak: Double = hot.reduce(0.0) { Swift.max($0, abs(Double($1))) }
#expect(peak <= 1.0 + ceilingEpsilon, "peak \(peak) exceeds the ±1 ceiling")
#expect(peak > 0.3, "unexpectedly quiet at max gain: \(peak)")
}
@Test func exposesFullControlSurface() throws {
let pedal: FullertonReverbAmpPedal = FullertonReverbAmpPedal()
#expect(pedal.effectKnobs.map { $0.label }
== ["Gain", "Bass", "Mid", "Treble", "Reverb", "Speed", "Intensity"])
#expect(pedal.effectSwitches.map { $0.label } == ["Bright", "Reverb FX", "Vibrato"])
#expect(pedal.effectSelectors.map { $0.label } == ["Cab"])
#expect(pedal.effectSelectors.first?.rebuildsOnChange == true)
#expect(pedal.widthUnits == 3)
#expect(pedal.showsMixControl == false)
#expect(pedal.toneStackModel == .fender)
}
@Test func controlsRoundTripThroughState() throws {
let pedal: FullertonReverbAmpPedal = FullertonReverbAmpPedal()
pedal.gain = 8.0
pedal.reverb = 0.7
pedal.speed = 9.0
pedal.intensity = 0.6
pedal.bright = 1.0
pedal.cab = 2.0
pedal.reverbEnabled = 0.0
pedal.vibratoEnabled = 0.0
let restored: FullertonReverbAmpPedal = FullertonReverbAmpPedal()
restored.applyState(pedal.captureState())
#expect(restored.gain == 8.0)
#expect(restored.reverb == 0.7)
#expect(restored.speed == 9.0)
#expect(restored.intensity == 0.6)
#expect(restored.bright == 1.0)
#expect(restored.cab == 2.0)
#expect(restored.reverbEnabled == 0.0)
#expect(restored.vibratoEnabled == 0.0)
}
@Test func registeredInBuiltInRegistry() throws {
#expect(PedalRegistry.makePedal(type: "Fullerton Reverb") is FullertonReverbAmpPedal)
}
}