feat(amps): boutique high-gain — Boutique Lead / OD (Phase 6)
Add a shared BoutiqueAmpPedal base: a rebuildsOnChange Clean/Lead channel switch (Lead cascades a stage set by Drive), a Master (via masterDrive), and Presence (top-end high-shelf) + Depth (low-end low-shelf, RBJLowShelf) power-amp shaping; widthUnits 4, 4× power-amp oversample. - Boutique Lead — SLO-style aggressive super-lead (.marshall, hot Lead drive). - Boutique OD — D-style smooth overdrive (.fender) with a Mid Boost switch (RBJPeakingEQ peak scaled by the switch, identity when off) layered on the base Presence/Depth shaping. Registered across 6 sites as .amp. 10 tests (channel switch + rebuildsOnChange, presence/depth, master drives power amp via RMS-normalized SSD, drive, ceiling on lead channel, control surfaces, OD mid boost, round-trip, registry). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,165 @@
|
||||
// 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 = 18.0 }
|
||||
#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 = 25.0 }
|
||||
#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 = 30.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 = 30.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 == .marshall)
|
||||
#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 = 12.0
|
||||
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 == 12.0 && 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user