292261a088
Follow-up cleanup now that card width is content-derived. Redefine widthUnits as the card's base width in knob columns (1 = 3-wide, 2 = 4-wide) — both the knob-grid column count and the card's minimum width — with selector/switch rows able to push wider. Values above 2 no longer do anything. - Delete the now-misleading widthUnits 3/4 overrides on 11 amps; they inherit AmpVoicePedal's 2 (all full-surface amps → the same tight 4-wide card). - Remove Mutant's redundant override (2 knobs + 2 switches → 3-wide either way). - Cabinet: keep widthUnits 2 so it's 4-wide like the amps — its Cab/Mic/Mic B selector captions (voice names) need the room to stay readable (per request). - Looper keeps widthUnits 3 (the one pedal still using the flat multiple for its bespoke timeline/knobs/transport layout). - Refresh the widthUnits docs (base + AmpVoicePedal + Cabinet); update the amp tests' widthUnits assertions (3/4 → 2; Looper stays 3). 675 tests pass; no visual change to the amps, Cabinet now matches their width. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
166 lines
7.6 KiB
Swift
166 lines
7.6 KiB
Swift
// BoutiqueAmpPedalTests.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("Boutique high-gain amps")
|
|
struct BoutiqueAmpPedalTests {
|
|
|
|
private let sampleRate: Double = 48000.0
|
|
|
|
private func render<P: AmpVoicePedal>(_ make: () -> P, configure: (P) -> 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: P = make()
|
|
pedal.inputBus = srcBus.index
|
|
pedal.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
|
|
}
|
|
}
|
|
|
|
private func rmsNormalizedSSD(_ a: [Float], _ b: [Float], skip: Int = 4096, window: Int = 4096) -> Double {
|
|
guard a.count >= skip + window, b.count >= skip + window else { return 0.0 }
|
|
let aw: ArraySlice<Float> = a[skip..<(skip + window)]
|
|
let bw: ArraySlice<Float> = b[skip..<(skip + window)]
|
|
func rms(_ x: ArraySlice<Float>) -> Double {
|
|
let sumSq: Double = x.reduce(0.0) { $0 + Double($1) * Double($1) }
|
|
return (sumSq / Double(x.count)).squareRoot()
|
|
}
|
|
let ra: Double = rms(aw)
|
|
let rb: Double = rms(bw)
|
|
guard ra > 0.0, rb > 0.0 else { return 0.0 }
|
|
return zip(aw, bw).reduce(0.0) { acc, pair in
|
|
let d: Double = Double(pair.0) / ra - Double(pair.1) / rb
|
|
return acc + d * d
|
|
}
|
|
}
|
|
|
|
private func peak(_ s: [Float]) -> Double { s.reduce(0.0) { Swift.max($0, abs(Double($1))) } }
|
|
|
|
private let voices: [(name: String, make: () -> BoutiqueAmpPedal)] = [
|
|
("Boutique Lead", { BoutiqueLeadAmpPedal() }),
|
|
("Boutique OD", { BoutiqueODAmpPedal() }),
|
|
]
|
|
|
|
@Test func allBuildNonSilentFinite() throws {
|
|
for v: (name: String, make: () -> BoutiqueAmpPedal) in voices {
|
|
let s: [Float] = try render(v.make)
|
|
#expect(hasNonSilentOutput(s), "\(v.name) produced silence")
|
|
#expect(s.allSatisfy { $0.isFinite }, "\(v.name) produced non-finite output")
|
|
}
|
|
}
|
|
|
|
@Test func channelSwitchChangesOutputAndRebuilds() throws {
|
|
for v: (name: String, make: () -> BoutiqueAmpPedal) in voices {
|
|
let clean: [Float] = try render(v.make) { $0.channel = 0.0 }
|
|
let lead: [Float] = try render(v.make) { $0.channel = 1.0; $0.drive = 9.5 }
|
|
#expect(windowedSSD(clean, lead) > 0, "\(v.name) channel switch had no effect")
|
|
let channel: PedalSwitch? = v.make().effectSwitches.first { $0.label == "Channel" }
|
|
#expect(channel?.rebuildsOnChange == true, "\(v.name) Channel should rebuild on change")
|
|
}
|
|
}
|
|
|
|
@Test func presenceAndDepthChangeOutput() throws {
|
|
for v: (name: String, make: () -> BoutiqueAmpPedal) in voices {
|
|
let pLow: [Float] = try render(v.make) { $0.presence = 0.0 }
|
|
let pHigh: [Float] = try render(v.make) { $0.presence = 1.0 }
|
|
#expect(windowedSSD(pLow, pHigh) > 0, "\(v.name) Presence had no effect")
|
|
let dLow: [Float] = try render(v.make) { $0.depth = 0.0 }
|
|
let dHigh: [Float] = try render(v.make) { $0.depth = 1.0 }
|
|
#expect(windowedSSD(dLow, dHigh) > 0, "\(v.name) Depth had no effect")
|
|
}
|
|
}
|
|
|
|
@Test func masterDrivesPowerAmp() throws {
|
|
for v: (name: String, make: () -> BoutiqueAmpPedal) in voices {
|
|
let low: [Float] = try render(v.make) { $0.gain = 8.0; $0.master = 0.1 }
|
|
let high: [Float] = try render(v.make) { $0.gain = 8.0; $0.master = 1.0 }
|
|
#expect(rmsNormalizedSSD(low, high) > 1.0e-3, "\(v.name) Master changed level but not tone")
|
|
}
|
|
}
|
|
|
|
@Test func driveKnobChangesLeadChannel() throws {
|
|
for v: (name: String, make: () -> BoutiqueAmpPedal) in voices {
|
|
let low: [Float] = try render(v.make) { $0.channel = 1.0; $0.drive = 2.0 }
|
|
let high: [Float] = try render(v.make) { $0.channel = 1.0; $0.drive = 10.5 }
|
|
#expect(windowedSSD(low, high) > 0, "\(v.name) Drive had no effect on the lead channel")
|
|
}
|
|
}
|
|
|
|
@Test func stayWithinCeilingOnLeadChannel() throws {
|
|
for v: (name: String, make: () -> BoutiqueAmpPedal) in voices {
|
|
let hot: [Float] = try render(v.make) { (p: BoutiqueAmpPedal) in
|
|
p.gain = 11.0; p.bass = 1.0; p.treble = 1.0
|
|
p.presence = 1.0; p.depth = 1.0; p.master = 1.0; p.channel = 1.0; p.drive = 11.0
|
|
}
|
|
#expect(peak(hot) <= 1.0 + 1.0e-4, "\(v.name) exceeds the ±1 ceiling on the lead channel")
|
|
}
|
|
}
|
|
|
|
@Test func exposesControlSurfaces() throws {
|
|
let lead: BoutiqueLeadAmpPedal = BoutiqueLeadAmpPedal()
|
|
#expect(lead.effectKnobs.map { $0.label }
|
|
== ["Gain", "Bass", "Mid", "Treble", "Presence", "Depth", "Master", "Drive"])
|
|
#expect(lead.effectSwitches.map { $0.label } == ["Channel"])
|
|
#expect(lead.widthUnits == 2)
|
|
#expect(lead.toneStackModel == .soldano)
|
|
#expect(lead.powerAmpOversample == 4)
|
|
|
|
let od: BoutiqueODAmpPedal = BoutiqueODAmpPedal()
|
|
#expect(od.effectSwitches.map { $0.label } == ["Channel", "Mid Boost"])
|
|
#expect(od.toneStackModel == .fender)
|
|
}
|
|
|
|
@Test func odMidBoostChangesOutput() throws {
|
|
let flat: [Float] = try render({ BoutiqueODAmpPedal() }) { $0.midBoost = 0.0 }
|
|
let boosted: [Float] = try render({ BoutiqueODAmpPedal() }) { $0.midBoost = 1.0 }
|
|
#expect(windowedSSD(flat, boosted) > 0, "Mid Boost had no effect")
|
|
}
|
|
|
|
@Test func roundTripsThroughState() throws {
|
|
let pedal: BoutiqueODAmpPedal = BoutiqueODAmpPedal()
|
|
pedal.presence = 0.6; pedal.depth = 0.7; pedal.master = 0.8; pedal.drive = 8.3
|
|
pedal.channel = 1.0; pedal.midBoost = 1.0; pedal.cab = 2.0
|
|
let restored: BoutiqueODAmpPedal = BoutiqueODAmpPedal()
|
|
restored.applyState(pedal.captureState())
|
|
#expect(restored.presence == 0.6 && restored.depth == 0.7 && restored.master == 0.8)
|
|
#expect(restored.drive == 8.3 && restored.channel == 1.0 && restored.midBoost == 1.0 && restored.cab == 2.0)
|
|
}
|
|
|
|
@Test func registeredInBuiltInRegistry() throws {
|
|
#expect(PedalRegistry.makePedal(type: "Boutique Lead") is BoutiqueLeadAmpPedal)
|
|
#expect(PedalRegistry.makePedal(type: "Boutique OD") is BoutiqueODAmpPedal)
|
|
}
|
|
}
|