feat(amps): character amps — Command/Citrus/Sixties/Magna/Anaheim (Phase 8)
Five character voices: - Command (Hiwatt) — BritishCombo variant: loud hi-fi clean, high headroom. - Citrus (Orange) — .marshall, fixed mid bump + a single Shape tilt control. - Sixties Combo (Supro) — .fender, gritty early breakup + onboard tremolo (shared tremolo helper + footswitch). - Magna Vibrato (Magnatone) — .fender, TRUE pitch vibrato: a DelayLine whose delay is swept by an LFO (Speed/Depth + footswitch), not amplitude tremolo. - Anaheim (Music Man hybrid) — .fender, symmetric-bias (solid-state-flavoured) preamp, huge headroom, Bright + Deep switches, and a built-in Limiter (LookAheadLimiter, ceiling 0.5 when engaged, before the power amp). True oversampled hard-clip SS shaper deferred to Lyrebird 1.7.x. Registered across 6 sites as .amp. New CharacterAmpsTests suite (10 tests): per-amp control/effect changes, Sixties tremolo bit-exact bypass, Magna vibrato on≠off + fixed-delay-when-off, Anaheim switches + limiter engages hot, ceiling at max for all five, tone-stack models, round-trip, registry. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
// 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 = 30.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 = 25.0; $0.limiter = 1.0 }
|
||||
let unlimited: [Float] = try render({ AnaheimAmpPedal() }) { $0.gain = 25.0; $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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user