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>
163 lines
7.9 KiB
Swift
163 lines
7.9 KiB
Swift
// CharacterAmpsTests.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("Character amps")
|
|
struct CharacterAmpsTests {
|
|
|
|
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 peak(_ s: [Float]) -> Double { s.reduce(0.0) { Swift.max($0, abs(Double($1))) } }
|
|
|
|
private let all: [(name: String, make: () -> AmpVoicePedal)] = [
|
|
("Command", { CommandAmpPedal() }),
|
|
("Citrus", { CitrusAmpPedal() }),
|
|
("Sixties Combo", { SixtiesComboAmpPedal() }),
|
|
("Magna Vibrato", { MagnaVibratoAmpPedal() }),
|
|
("Anaheim", { AnaheimAmpPedal() }),
|
|
]
|
|
|
|
@Test func allBuildNonSilentFiniteWithinCeiling() throws {
|
|
for a: (name: String, make: () -> AmpVoicePedal) in all {
|
|
let hot: [Float] = try render(a.make) { $0.gain = 11.0; $0.bass = 1.0; $0.treble = 1.0 }
|
|
#expect(hasNonSilentOutput(hot), "\(a.name) silent")
|
|
#expect(hot.allSatisfy { $0.isFinite }, "\(a.name) non-finite")
|
|
#expect(peak(hot) <= 1.0 + 1.0e-4, "\(a.name) exceeds ±1 ceiling: \(peak(hot))")
|
|
}
|
|
}
|
|
|
|
@Test func toneStackModels() throws {
|
|
#expect(CommandAmpPedal().toneStackModel == .marshall)
|
|
#expect(CitrusAmpPedal().toneStackModel == .marshall)
|
|
#expect(SixtiesComboAmpPedal().toneStackModel == .fender)
|
|
#expect(MagnaVibratoAmpPedal().toneStackModel == .fender)
|
|
#expect(AnaheimAmpPedal().toneStackModel == .fender)
|
|
}
|
|
|
|
// MARK: - Command (Hiwatt)
|
|
|
|
@Test func commandInheritsPresenceAndBright() throws {
|
|
let pedal: CommandAmpPedal = CommandAmpPedal()
|
|
#expect(pedal.effectKnobs.map { $0.label } == ["Gain", "Bass", "Mid", "Treble", "Presence"])
|
|
#expect(pedal.effectSwitches.map { $0.label } == ["Bright"])
|
|
let flat: [Float] = try render({ CommandAmpPedal() }) { $0.presence = 0.0 }
|
|
let lifted: [Float] = try render({ CommandAmpPedal() }) { $0.presence = 1.0 }
|
|
#expect(windowedSSD(flat, lifted) > 0, "Command Presence had no effect")
|
|
}
|
|
|
|
// MARK: - Citrus (Orange)
|
|
|
|
@Test func citrusShapeChangesOutput() throws {
|
|
let dark: [Float] = try render({ CitrusAmpPedal() }) { $0.shape = 0.0 }
|
|
let bright: [Float] = try render({ CitrusAmpPedal() }) { $0.shape = 1.0 }
|
|
#expect(windowedSSD(dark, bright) > 0, "Citrus Shape had no effect")
|
|
#expect(CitrusAmpPedal().effectKnobs.map { $0.label } == ["Gain", "Bass", "Mid", "Treble", "Shape"])
|
|
}
|
|
|
|
// MARK: - Sixties Combo (Supro)
|
|
|
|
@Test func sixtiesTremoloWorksAndBypasses() throws {
|
|
let off: [Float] = try render({ SixtiesComboAmpPedal() }) { $0.intensity = 0.0 }
|
|
let on: [Float] = try render({ SixtiesComboAmpPedal() }) { $0.intensity = 1.0; $0.speed = 6.0 }
|
|
#expect(windowedSSD(off, on) > 0, "Sixties tremolo had no effect")
|
|
// Footswitch off with intensity up == no tremolo (bit-exact, shared tremolo helper).
|
|
let bypassed: [Float] = try render({ SixtiesComboAmpPedal() }) {
|
|
$0.intensity = 1.0; $0.speed = 6.0; $0.tremoloEnabled = 0.0
|
|
}
|
|
let noTrem: [Float] = try render({ SixtiesComboAmpPedal() }) { $0.intensity = 0.0 }
|
|
#expect(windowedSSD(bypassed, noTrem) == 0.0, "Sixties tremolo footswitch off should be identity")
|
|
}
|
|
|
|
// MARK: - Magna Vibrato (Magnatone)
|
|
|
|
@Test func magnaPitchVibratoWorks() throws {
|
|
let off: [Float] = try render({ MagnaVibratoAmpPedal() }) { $0.vibratoEnabled = 0.0; $0.depth = 0.5 }
|
|
let on: [Float] = try render({ MagnaVibratoAmpPedal() }) { $0.vibratoEnabled = 1.0; $0.depth = 0.5; $0.speed = 6.0 }
|
|
#expect(windowedSSD(off, on) > 0, "Magna vibrato had no effect")
|
|
// With vibrato off the sweep is zero → the delay is fixed, so Speed is irrelevant (identical).
|
|
let offSlow: [Float] = try render({ MagnaVibratoAmpPedal() }) { $0.vibratoEnabled = 0.0; $0.speed = 1.0 }
|
|
let offFast: [Float] = try render({ MagnaVibratoAmpPedal() }) { $0.vibratoEnabled = 0.0; $0.speed = 10.0 }
|
|
#expect(windowedSSD(offSlow, offFast) == 0.0, "vibrato off should ignore Speed (fixed delay)")
|
|
#expect(MagnaVibratoAmpPedal().effectSwitches.map { $0.label } == ["Vibrato"])
|
|
}
|
|
|
|
// MARK: - Anaheim (Music Man)
|
|
|
|
@Test func anaheimSwitchesWork() throws {
|
|
let a: AnaheimAmpPedal = AnaheimAmpPedal()
|
|
#expect(a.effectKnobs.map { $0.label } == ["Gain", "Bass", "Mid", "Treble"])
|
|
#expect(a.effectSwitches.map { $0.label } == ["Bright", "Deep", "Limiter"])
|
|
let flat: [Float] = try render({ AnaheimAmpPedal() }) { $0.bright = 0.0 }
|
|
let bright: [Float] = try render({ AnaheimAmpPedal() }) { $0.bright = 1.0 }
|
|
#expect(windowedSSD(flat, bright) > 0, "Anaheim Bright had no effect")
|
|
let noDeep: [Float] = try render({ AnaheimAmpPedal() }) { $0.deep = 0.0 }
|
|
let deep: [Float] = try render({ AnaheimAmpPedal() }) { $0.deep = 1.0 }
|
|
#expect(windowedSSD(noDeep, deep) > 0, "Anaheim Deep had no effect")
|
|
}
|
|
|
|
@Test func anaheimLimiterActsWhenDrivenHot() throws {
|
|
// Driven hard, the built-in limiter (on) compresses vs bypassed (off) → different output.
|
|
let limited: [Float] = try render({ AnaheimAmpPedal() }) { $0.gain = 10.5; $0.limiter = 1.0 }
|
|
let unlimited: [Float] = try render({ AnaheimAmpPedal() }) { $0.gain = 10.5; $0.limiter = 0.0 }
|
|
#expect(windowedSSD(limited, unlimited) > 0, "Anaheim limiter had no effect")
|
|
}
|
|
|
|
@Test func roundTripThroughState() throws {
|
|
let pedal: AnaheimAmpPedal = AnaheimAmpPedal()
|
|
pedal.bright = 1.0; pedal.deep = 1.0; pedal.limiter = 0.0; pedal.cab = 2.0
|
|
let restored: AnaheimAmpPedal = AnaheimAmpPedal()
|
|
restored.applyState(pedal.captureState())
|
|
#expect(restored.bright == 1.0 && restored.deep == 1.0 && restored.limiter == 0.0 && restored.cab == 2.0)
|
|
}
|
|
|
|
@Test func registeredInBuiltInRegistry() throws {
|
|
#expect(PedalRegistry.makePedal(type: "Command") is CommandAmpPedal)
|
|
#expect(PedalRegistry.makePedal(type: "Citrus") is CitrusAmpPedal)
|
|
#expect(PedalRegistry.makePedal(type: "Sixties Combo") is SixtiesComboAmpPedal)
|
|
#expect(PedalRegistry.makePedal(type: "Magna Vibrato") is MagnaVibratoAmpPedal)
|
|
#expect(PedalRegistry.makePedal(type: "Anaheim") is AnaheimAmpPedal)
|
|
}
|
|
}
|