diff --git a/Sources/LyrebirdShoeGaze/PedalType.swift b/Sources/LyrebirdShoeGaze/PedalType.swift index 86dd486..7213ded 100644 --- a/Sources/LyrebirdShoeGaze/PedalType.swift +++ b/Sources/LyrebirdShoeGaze/PedalType.swift @@ -54,6 +54,11 @@ public extension PedalType { static let boutiqueLead = PedalType("Boutique Lead") static let boutiqueOD = PedalType("Boutique OD") static let caliHiGain = PedalType("Cali Hi-Gain") + static let command = PedalType("Command") + static let citrus = PedalType("Citrus") + static let sixtiesCombo = PedalType("Sixties Combo") + static let magnaVibrato = PedalType("Magna Vibrato") + static let anaheim = PedalType("Anaheim") static let chime = PedalType("Chime") static let chimeFifteen = PedalType("Chime 15") static let chimeNormal = PedalType("Chime Normal") diff --git a/Sources/LyrebirdShoeGaze/Pedals/AnaheimAmpPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/AnaheimAmpPedal.swift new file mode 100644 index 0000000..ce3546c --- /dev/null +++ b/Sources/LyrebirdShoeGaze/Pedals/AnaheimAmpPedal.swift @@ -0,0 +1,124 @@ +// AnaheimAmpPedal.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import LyrebirdSynth +import LyrebirdUI + +/// American **hybrid combo** — the Anaheim voice (Music Man lineage): a solid-state-flavoured +/// preamp into a tube power stage, with huge clean headroom, a **Bright** switch, a **Deep** +/// low-end switch, and a built-in **Limiter**. +/// +/// Distinct from the all-tube voices: the preamp stage runs symmetric (grid `bias 0`) — no +/// even-harmonic tube warmth, for the cleaner/more clinical solid-state character — and a +/// `LookAheadLimiter` (the amp's onboard limiter) can be switched into the output. +/// +/// > Note: the aggressive hard-knee solid-state clipping when pushed is approximated here by the +/// > symmetric preamp + high headroom; a true oversampled hard-clipper is a Lyrebird 1.7.x follow-up. +public final class AnaheimAmpPedal: AmpVoicePedal { + + /// Bright switch: `0` = flat, `1` = treble shelf engaged. + @UIParam public var bright: Double = 0.0 + /// Deep switch: `0` = flat, `1` = low-end resonance boost engaged. + @UIParam public var deep: Double = 0.0 + /// Limiter footswitch: `1` = the built-in output limiter is engaged, `0` = bypassed. + @UIParam public var limiter: Double = 1.0 + + /// Symmetric preamp bias (solid-state character — no even-harmonic tube warmth). + private let ssPreampBias: Double = 0.0 + private let brightFreqHz: Double = 3200.0 + private let brightMaxGainDb: Double = 6.0 + private let brightSlope: Double = 1.0 + private let deepFreqHz: Double = 100.0 + private let deepMaxGainDb: Double = 6.0 + private let deepSlope: Double = 0.7 + /// Limiter ceiling when engaged — below full scale, so it actually tames peaks (a peak + /// compressor, the amp's built-in limiter); when bypassed the ceiling is raised so it never acts. + private let limiterOnCeiling: Double = 0.5 + private let limiterOffCeiling: Double = 10.0 + private let limiterLookAhead: Double = 0.005 + private let limiterRelease: Double = 0.050 + + public override var toneStackModel: ToneStackModel { .fender } + public override var summaryText: String { + "American hybrid combo — solid-state-flavoured clean, huge headroom, Bright / Deep / Limiter." + } + + public override var effectSwitches: [PedalSwitch] { + [ + PedalSwitch( + label: "Bright", + node: $bright, + options: [ + PedalSwitch.Option(title: "Off", value: switchOffValue), + PedalSwitch.Option(title: "On", value: switchOnValue), + ] + ), + PedalSwitch( + label: "Deep", + node: $deep, + options: [ + PedalSwitch.Option(title: "Off", value: switchOffValue), + PedalSwitch.Option(title: "On", value: switchOnValue), + ] + ), + PedalSwitch( + label: "Limiter", + node: $limiter, + options: [ + PedalSwitch.Option(title: "Off", value: switchOffValue), + PedalSwitch.Option(title: "On", value: switchOnValue), + ] + ), + ] + } + + /// Wider card for the three switches. + public override var widthUnits: Int { 3 } + + /// Creates an Anaheim amp. + /// + /// - Parameters: + /// - inputBus: Audio bus index to read the dry input from. Defaults to `0`. + /// - outputBus: Audio bus index to write the processed output to. Defaults to `0`. + public init(inputBus: Int = 0, outputBus: Int = 0) { + super.init(name: "Anaheim", inputBus: inputBus, outputBus: outputBus) + gain = 3.0 // huge clean headroom + cab = 0.0 // American 1×12 + } + + /// Bright switch: a high-shelf lift ahead of the preamp (identity when off). + public override func inputShaping(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput { + let shelfGainDb: any ValidGeneratorInput = $bright * brightMaxGainDb + return RBJHighShelf.Audio( + input: signal, freq: brightFreqHz, gain: shelfGainDb, slope: brightSlope) + } + + /// Symmetric (solid-state-flavoured) preamp stage — `bias 0`, no even-harmonic tube warmth. + public override func preampStage(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput { + TriodeStage(input: signal, drive: $gain, bias: ssPreampBias, oversample: preampOversample) + } + + /// The built-in limiter, gated by the Limiter switch — placed *before* the power-amp stage (so + /// it limits the driven preamp/tone-stack signal, which can exceed the ceiling, rather than a + /// signal the power-amp `tanh` has already bounded). Off raises the ceiling so it never acts. + public override func onboardEffects(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput { + let ceiling: LinLin.Audio = LinLin.Audio( + $limiter, inLo: 0.0, inHi: 1.0, outLo: limiterOffCeiling, outHi: limiterOnCeiling) + return LookAheadLimiter( + in: signal, + maxAmplitude: ceiling, + lookAheadTime: limiterLookAhead, + releaseTime: limiterRelease, + sampleRate: sampleRate + ) + } + + /// Deep low-shelf (gated by the Deep switch), post power amp. + public override func shapeVoice(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput { + let deepGainDb: any ValidGeneratorInput = $deep * deepMaxGainDb + return RBJLowShelf.Audio(input: signal, freq: deepFreqHz, gain: deepGainDb, slope: deepSlope) + } +} diff --git a/Sources/LyrebirdShoeGaze/Pedals/CitrusAmpPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/CitrusAmpPedal.swift new file mode 100644 index 0000000..4f90c18 --- /dev/null +++ b/Sources/LyrebirdShoeGaze/Pedals/CitrusAmpPedal.swift @@ -0,0 +1,55 @@ +// CitrusAmpPedal.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import LyrebirdSynth +import LyrebirdUI + +/// British **mid-forward crunch** — the Citrus voice: a thick, punchy midrange with a single +/// **Shape** control that tilts the top end from dark to bright. +/// +/// A ``AmpVoicePedal`` on the `.marshall` stack with a fixed mid bump (the amp's signature push) +/// and a Shape high-shelf whose gain sweeps from cut to boost. +public final class CitrusAmpPedal: AmpVoicePedal { + + /// Shape in [0, 1]: `0` = dark (top cut), `0.5` = flat, `1` = bright (top boost). + @UIParam public var shape: Double = 0.5 + + private let midFreqHz: Double = 800.0 + private let midBumpDb: Double = 3.0 + private let midQ: Double = 0.8 + private let shapeFreqHz: Double = 2600.0 + private let shapeMinDb: Double = -6.0 + private let shapeMaxDb: Double = 6.0 + private let shapeSlope: Double = 0.8 + + public override var toneStackModel: ToneStackModel { .marshall } + public override var summaryText: String { + "British mid-forward crunch with a single Shape control (dark ↔ bright top end)." + } + public override var signatureKnobs: [PedalKnob] { + [PedalKnob(label: "Shape", node: $shape, range: signatureRange)] + } + + /// Creates a Citrus amp. + /// + /// - Parameters: + /// - inputBus: Audio bus index to read the dry input from. Defaults to `0`. + /// - outputBus: Audio bus index to write the processed output to. Defaults to `0`. + public init(inputBus: Int = 0, outputBus: Int = 0) { + super.init(name: "Citrus", inputBus: inputBus, outputBus: outputBus) + gain = 6.0 + cab = 1.0 // British 4×12 + } + + /// A fixed midrange bump (the Citrus push), then the Shape high-shelf tilt. + public override func shapeVoice(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput { + let midded: RBJPeakingEQ.Audio = RBJPeakingEQ.Audio( + input: signal, freq: midFreqHz, gain: midBumpDb, q: midQ) + let shapeDb: LinLin.Audio = LinLin.Audio( + $shape, inLo: 0.0, inHi: 1.0, outLo: shapeMinDb, outHi: shapeMaxDb) + return RBJHighShelf.Audio(input: midded, freq: shapeFreqHz, gain: shapeDb, slope: shapeSlope) + } +} diff --git a/Sources/LyrebirdShoeGaze/Pedals/CommandAmpPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/CommandAmpPedal.swift new file mode 100644 index 0000000..bc22fc1 --- /dev/null +++ b/Sources/LyrebirdShoeGaze/Pedals/CommandAmpPedal.swift @@ -0,0 +1,32 @@ +// CommandAmpPedal.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import LyrebirdSynth +import LyrebirdUI + +/// British **hi-fi clean** — the Command/DR-style workhorse: very loud, very clean, high headroom, +/// with Presence and a Bright switch. Breaks up late and stays tight. +/// +/// A ``BritishComboAmpPedal`` (non-master `.marshall` + Presence + Bright) voiced for maximum +/// headroom — a low default gain so it stays clean far up the dial. +public final class CommandAmpPedal: BritishComboAmpPedal { + + public override var summaryText: String { + "British hi-fi clean — loud, tight, high-headroom, with Presence and a Bright switch." + } + + /// Creates a Command amp. + /// + /// - Parameters: + /// - inputBus: Audio bus index to read the dry input from. Defaults to `0`. + /// - outputBus: Audio bus index to write the processed output to. Defaults to `0`. + public init(inputBus: Int = 0, outputBus: Int = 0) { + super.init(name: "Command", inputBus: inputBus, outputBus: outputBus) + gain = 4.0 // headroom-rich clean + treble = 0.55 // a touch of hi-fi top + cab = 1.0 // British 4×12 + } +} diff --git a/Sources/LyrebirdShoeGaze/Pedals/MagnaVibratoAmpPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/MagnaVibratoAmpPedal.swift new file mode 100644 index 0000000..c2c50a3 --- /dev/null +++ b/Sources/LyrebirdShoeGaze/Pedals/MagnaVibratoAmpPedal.swift @@ -0,0 +1,87 @@ +// MagnaVibratoAmpPedal.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import LyrebirdSynth +import LyrebirdUI + +/// American clean combo with **true pitch vibrato** — the Magnatone voice: a genuine +/// frequency-modulation warble (a swept delay line), not the amplitude-modulation "vibrato" other +/// amps label as such. +/// +/// A ``AmpVoicePedal`` (`.fender`) whose onboard effect is a delay line whose read position is swept +/// by an LFO — modulating pitch. `Depth` scales the sweep, `Speed` its rate, and a Vibrato +/// footswitch bypasses it (a fixed short delay, no warble). +public final class MagnaVibratoAmpPedal: AmpVoicePedal { + + /// Vibrato LFO rate in Hz. Range [0.5, 12]. + @UIParam public var speed: Double = 5.0 + /// Vibrato depth in [0, 1] → 0…`maxSweepSeconds` of delay-time sweep (pitch modulation). + @UIParam public var depth: Double = 0.3 + /// Vibrato footswitch: `1` = engaged, `0` = bypassed (`Speed`/`Depth` preserved). + @UIParam public var vibratoEnabled: Double = 1.0 + + /// Base delay time (the centre the LFO sweeps around), in seconds. + private let baseDelaySeconds: Double = 0.005 + /// Maximum ± sweep at full depth, in seconds. + private let maxSweepSeconds: Double = 0.002 + /// Delay-line capacity — must exceed base + max sweep. + private let maxDelaySeconds: Double = 0.010 + private let speedRange: ClosedRange = 0.5 ... 12.0 + private let depthRange: ClosedRange = 0.0 ... 1.0 + + public override var toneStackModel: ToneStackModel { .fender } + public override var summaryText: String { + "American clean combo with true pitch vibrato (a swept delay, not tremolo)." + } + public override var signatureKnobs: [PedalKnob] { + [ + PedalKnob(label: "Speed", node: $speed, range: speedRange), + PedalKnob(label: "Depth", node: $depth, range: depthRange), + ] + } + + public override var effectSwitches: [PedalSwitch] { + [ + PedalSwitch( + label: "Vibrato", + node: $vibratoEnabled, + options: [ + PedalSwitch.Option(title: "Off", value: switchOffValue), + PedalSwitch.Option(title: "On", value: switchOnValue), + ] + ), + ] + } + + /// Wider card for the vibrato knobs plus the Vibrato switch. + public override var widthUnits: Int { 3 } + + /// Creates a Magna Vibrato amp. + /// + /// - Parameters: + /// - inputBus: Audio bus index to read the dry input from. Defaults to `0`. + /// - outputBus: Audio bus index to write the processed output to. Defaults to `0`. + public init(inputBus: Int = 0, outputBus: Int = 0) { + super.init(name: "Magna Vibrato", inputBus: inputBus, outputBus: outputBus) + gain = 4.0 // clean platform for the vibrato + cab = 0.0 // American 1×12 + } + + /// True pitch vibrato: a delay line whose delay time is swept by a sine LFO. The footswitch + /// gates the sweep to zero (a fixed base delay, no warble) while keeping Speed/Depth. + public override func onboardEffects(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput { + let sweepSeconds: any ValidGeneratorInput = ($depth * $vibratoEnabled) * maxSweepSeconds + let delayTime: OscSin.Audio = OscSin.Audio( + freq: $speed, mul: sweepSeconds, add: baseDelaySeconds) + return DelayLine( + input: signal, + maxDelay: maxDelaySeconds, + delay: delayTime, + sampleRate: sampleRate, + interpolation: .linear + ) + } +} diff --git a/Sources/LyrebirdShoeGaze/Pedals/SixtiesComboAmpPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/SixtiesComboAmpPedal.swift new file mode 100644 index 0000000..c944a14 --- /dev/null +++ b/Sources/LyrebirdShoeGaze/Pedals/SixtiesComboAmpPedal.swift @@ -0,0 +1,75 @@ +// SixtiesComboAmpPedal.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import LyrebirdSynth +import LyrebirdUI + +/// American **'60s grit combo** — the small Supro/Silvertone-style amp: low headroom, gritty early +/// breakup, and an onboard **tremolo**. +/// +/// A ``AmpVoicePedal`` (`.fender`) driven hard into the power stage for early breakup, with a +/// tremolo (Speed / Intensity + footswitch) in the onboard-effects slot. +public final class SixtiesComboAmpPedal: AmpVoicePedal { + + /// Tremolo LFO rate in Hz. Range [0.5, 12]. + @UIParam public var speed: Double = 5.0 + /// Tremolo depth in [0, 1]. `0` = off, `1` = full swing. + @UIParam public var intensity: Double = 0.0 + /// Tremolo footswitch: `1` = engaged, `0` = bypassed (`Speed`/`Intensity` preserved). + @UIParam public var tremoloEnabled: Double = 1.0 + + /// Power-amp drive — well above the default fixed value so the small combo grits up early. + private let grittyPowerDrive: Double = 2.4 + private let speedRange: ClosedRange = 0.5 ... 12.0 + private let intensityRange: ClosedRange = 0.0 ... 1.0 + + public override var toneStackModel: ToneStackModel { .fender } + public override var summaryText: String { + "American '60s grit combo — early-breakup with onboard tremolo." + } + public override var signatureKnobs: [PedalKnob] { + [ + PedalKnob(label: "Speed", node: $speed, range: speedRange), + PedalKnob(label: "Intensity", node: $intensity, range: intensityRange), + ] + } + + public override var effectSwitches: [PedalSwitch] { + [ + PedalSwitch( + label: "Tremolo", + node: $tremoloEnabled, + options: [ + PedalSwitch.Option(title: "Off", value: switchOffValue), + PedalSwitch.Option(title: "On", value: switchOnValue), + ] + ), + ] + } + + /// Driven hard into the power stage, so 4× oversampling for anti-alias headroom. + public override var powerAmpOversample: Int { 4 } + public override var powerAmpDriveInput: any ValidGeneratorInput { grittyPowerDrive } + + /// Wider card for the tremolo knobs plus the Tremolo switch. + public override var widthUnits: Int { 3 } + + /// Creates a Sixties Combo amp. + /// + /// - Parameters: + /// - inputBus: Audio bus index to read the dry input from. Defaults to `0`. + /// - outputBus: Audio bus index to write the processed output to. Defaults to `0`. + public init(inputBus: Int = 0, outputBus: Int = 0) { + super.init(name: "Sixties Combo", inputBus: inputBus, outputBus: outputBus) + gain = 7.0 // gritty starting point + cab = 2.0 // Vintage Dark — small, dark + } + + /// Onboard tremolo (gated by the Tremolo footswitch), inserted after the tone stack. + public override func onboardEffects(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput { + tremolo(signal, speed: $speed, depth: $intensity, enabled: $tremoloEnabled) + } +} diff --git a/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift b/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift index 314ce40..c5adaa6 100644 --- a/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift +++ b/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift @@ -41,6 +41,11 @@ public enum PedalRegistry { "Boutique Lead": { BoutiqueLeadAmpPedal() }, "Boutique OD": { BoutiqueODAmpPedal() }, "Cali Hi-Gain": { CaliHiGainAmpPedal() }, + "Command": { CommandAmpPedal() }, + "Citrus": { CitrusAmpPedal() }, + "Sixties Combo": { SixtiesComboAmpPedal() }, + "Magna Vibrato": { MagnaVibratoAmpPedal() }, + "Anaheim": { AnaheimAmpPedal() }, "Chime": { ChimeAmpPedal() }, "Chime 15": { ChimeFifteenAmpPedal() }, "Chime Normal": { ChimeNormalAmpPedal() }, diff --git a/Sources/LyrebirdShoeGazeUI/PedalCategory.swift b/Sources/LyrebirdShoeGazeUI/PedalCategory.swift index f439668..5ffdad6 100644 --- a/Sources/LyrebirdShoeGazeUI/PedalCategory.swift +++ b/Sources/LyrebirdShoeGazeUI/PedalCategory.swift @@ -44,7 +44,7 @@ public enum PedalCategory: String, CaseIterable, Identifiable, Sendable { } private static let mapping: [String: PedalCategory] = [ - "California": .amp, "British": .amp, "British Plexi": .amp, "British JTM": .amp, "British Bluesbreaker": .amp, "British Master": .amp, "British Dual": .amp, "Boutique Lead": .amp, "Boutique OD": .amp, "Cali Hi-Gain": .amp, "Chime": .amp, "Chime 15": .amp, "Chime Normal": .amp, "Chime Baby": .amp, "Fullerton Reverb": .amp, "Fullerton Deluxe": .amp, "Fullerton Princeton": .amp, "Fullerton Drive": .amp, "Jazz Clean": .amp, "Chime Top Boost": .amp, "Neural Amp": .amp, + "California": .amp, "British": .amp, "British Plexi": .amp, "British JTM": .amp, "British Bluesbreaker": .amp, "British Master": .amp, "British Dual": .amp, "Boutique Lead": .amp, "Boutique OD": .amp, "Cali Hi-Gain": .amp, "Command": .amp, "Citrus": .amp, "Sixties Combo": .amp, "Magna Vibrato": .amp, "Anaheim": .amp, "Chime": .amp, "Chime 15": .amp, "Chime Normal": .amp, "Chime Baby": .amp, "Fullerton Reverb": .amp, "Fullerton Deluxe": .amp, "Fullerton Princeton": .amp, "Fullerton Drive": .amp, "Jazz Clean": .amp, "Chime Top Boost": .amp, "Neural Amp": .amp, "Overdrive": .gain, "Distortion": .gain, "Fuzz": .gain, "Volume": .gain, "Compressor": .dynamics, "Sustainer": .dynamics, "Limiter": .dynamics, "Noise Gate": .dynamics, "Graphic EQ": .filter, "Auto-Wah": .filter, "Wah": .filter, "Mutant": .filter, diff --git a/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift b/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift index 7141031..8a4b477 100644 --- a/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift +++ b/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift @@ -54,7 +54,7 @@ public struct PedalPaletteView: View { /// Preferred display order for the built-in pedals. Any registered pedal not listed here is /// appended afterwards (sorted) so the palette never silently drops a newly added pedal. private static let preferredOrder: [String] = [ - "California", "British", "British Plexi", "British JTM", "British Bluesbreaker", "British Master", "British Dual", "Boutique Lead", "Boutique OD", "Cali Hi-Gain", "Chime", "Chime 15", "Chime Normal", "Chime Baby", "Fullerton Reverb", "Fullerton Deluxe", "Fullerton Princeton", "Fullerton Drive", "Jazz Clean", "Chime Top Boost", "Neural Amp", "Overdrive", "Distortion", "Compressor", "Sustainer", "Limiter", "Noise Gate", "Fuzz", + "California", "British", "British Plexi", "British JTM", "British Bluesbreaker", "British Master", "British Dual", "Boutique Lead", "Boutique OD", "Cali Hi-Gain", "Command", "Citrus", "Sixties Combo", "Magna Vibrato", "Anaheim", "Chime", "Chime 15", "Chime Normal", "Chime Baby", "Fullerton Reverb", "Fullerton Deluxe", "Fullerton Princeton", "Fullerton Drive", "Jazz Clean", "Chime Top Boost", "Neural Amp", "Overdrive", "Distortion", "Compressor", "Sustainer", "Limiter", "Noise Gate", "Fuzz", "Volume", "Graphic EQ", "Tremolo", "Phaser", "Modulation", "Chorus", "Flanger", "Vibrato", "Rotary", "Auto-Wah", "Wah", "Mutant", "Cabinet", "Ring Modulator", "Diffuser", "Bitcrusher", "Granulator", diff --git a/Sources/LyrebirdShoeGazeUI/PedalView.swift b/Sources/LyrebirdShoeGazeUI/PedalView.swift index f9977d8..2b85b69 100644 --- a/Sources/LyrebirdShoeGazeUI/PedalView.swift +++ b/Sources/LyrebirdShoeGazeUI/PedalView.swift @@ -27,6 +27,11 @@ private func enclosureColor(for displayName: String) -> Color { case "Boutique Lead": return Color(red: 0.28, green: 0.12, blue: 0.16) // boutique oxblood case "Boutique OD": return Color(red: 0.30, green: 0.20, blue: 0.10) // D-style amber case "Cali Hi-Gain": return Color(red: 0.16, green: 0.16, blue: 0.18) // Mark-series black + case "Command": return Color(red: 0.20, green: 0.22, blue: 0.16) // hi-fi olive + case "Citrus": return Color(red: 0.85, green: 0.50, blue: 0.10) // orange tolex + case "Sixties Combo": return Color(red: 0.42, green: 0.30, blue: 0.16) // tweed brown + case "Magna Vibrato": return Color(red: 0.34, green: 0.26, blue: 0.44) // vibrato violet + case "Anaheim": return Color(red: 0.24, green: 0.30, blue: 0.32) // hybrid slate case "Chime": return Color(red: 0.16, green: 0.24, blue: 0.22) // vintage green case "Chime 15": return Color(red: 0.18, green: 0.28, blue: 0.22) // brighter vox green case "Chime Normal": return Color(red: 0.20, green: 0.26, blue: 0.20) // warm vox green diff --git a/Tests/LyrebirdShoeGazeTests/CharacterAmpsTests.swift b/Tests/LyrebirdShoeGazeTests/CharacterAmpsTests.swift new file mode 100644 index 0000000..ea6180a --- /dev/null +++ b/Tests/LyrebirdShoeGazeTests/CharacterAmpsTests.swift @@ -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(_ 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) + } +}