f9ddd6b160
Every amp's Gain (and the boutique/drive-channel Drive) is now a 1–11 dial — yes, it goes to eleven — instead of the raw 1–30 tube-drive number. - New AmpVoicePedal.taperedDrive(_:) maps the 1–11 dial to the 1–30 tube drive through an exponential LinExp taper, so 1 is nearly clean, 11 is full saturation, and the useful grind spreads across the dial (fine at the bottom, steep at the top) rather than bunching near the low end. - Wired into the base preampStage and every override that feeds a drive: Boutique / Fullerton Drive / Jazz Clean / British Dual (Drive channel), Anaheim (SS preamp), British Master (cascaded stage). - gainRange / driveRange → 1...11; every amp's default gain/drive reconverted from drive-space to the equivalent dial value (dial = 1 + 10·ln(drive)/ln(30)), so each amp's shipped voicing is preserved. - No preset migration (nothing shipped — per product owner); all knob work stays within ShoeGaze (no core Lyrebird change). - Tests updated to the 1–11 scale; added range + exponential-taper assertions. 671 tests pass. 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 == 4)
|
|
#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)
|
|
}
|
|
}
|