// FullertonReverbAmpPedal.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import LyrebirdSynth import LyrebirdUI /// American blackface-combo amp with a full onboard control surface: spring **reverb**, **tremolo** /// (Speed / Intensity), and a **Bright** switch — the loud, headroom-rich clean voice. /// /// A ``AmpVoicePedal`` fixed to the American tone stack that fills both subclass hooks: /// - ``inputShaping(_:)`` applies the Bright switch as a pre-preamp treble shelf. /// - ``onboardEffects(_:)`` inserts the spring reverb then the tremolo, between the tone stack and /// the power amp — the slot a combo amp's built-in reverb/tremolo occupy. /// /// The amp's "vibrato" channel is historically amplitude modulation (tremolo), not pitch vibrato, /// so `Intensity` drives a unipolar-sine gain LFO. Tremolo defaults off (`Intensity = 0`) so the /// amp opens as a clean, reverbed platform. public final class FullertonReverbAmpPedal: AmpVoicePedal { // MARK: - Onboard-effect parameters /// Spring-reverb wet mix in [0, 1]. `0` = dry, `1` = fully wet. @UIParam public var reverb: Double = 0.25 /// Tremolo LFO rate in Hz. Range [0.5, 12]. @UIParam public var speed: Double = 4.0 /// Tremolo depth in [0, 1]. `0` = off (clean), `1` = full silence-to-unity swing. @UIParam public var intensity: Double = 0.0 /// Bright switch: `0` = flat, `1` = treble shelf engaged. @UIParam public var bright: Double = 0.0 // MARK: - Constants /// Bright-switch shelf corner in Hz. private let brightFreqHz: Double = 2500.0 /// Bright-switch shelf lift in dB when engaged. private let brightMaxGainDb: Double = 6.0 /// Bright-switch shelf slope. private let brightSlope: Double = 0.8 /// Tremolo depth scaling — at full `intensity` the LFO swings over half the normalised range so /// the peak gain is 1.0 and the trough is `1 − intensity`. private let tremoloDepthScale: Double = 0.5 private let reverbRange: ClosedRange = 0.0 ... 1.0 private let speedRange: ClosedRange = 0.5 ... 12.0 private let intensityRange: ClosedRange = 0.0 ... 1.0 private let brightOffValue: Double = 0.0 private let brightOnValue: Double = 1.0 // MARK: - Voice configuration public override var toneStackModel: ToneStackModel { .fender } public override var summaryText: String { "American blackface clean — spring reverb, tremolo, and a Bright switch." } public override var signatureKnobs: [PedalKnob] { [ PedalKnob(label: "Reverb", node: $reverb, range: reverbRange), PedalKnob(label: "Speed", node: $speed, range: speedRange), PedalKnob(label: "Intensity", node: $intensity, range: intensityRange), ] } /// Wider card to hold the extra reverb/tremolo knobs plus the Bright switch. public override var widthUnits: Int { 3 } // MARK: - Init /// Creates a Fullerton Reverb 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: "Fullerton Reverb", inputBus: inputBus, outputBus: outputBus) gain = 4.0 // headroom-rich clean default } // MARK: - Switches public override var effectSwitches: [PedalSwitch] { [ PedalSwitch( label: "Bright", node: $bright, options: [ PedalSwitch.Option(title: "Off", value: brightOffValue), PedalSwitch.Option(title: "On", value: brightOnValue), ] ), ] } // MARK: - Hooks /// Bright switch: a high-shelf lift ahead of the preamp. The switch value (`0`/`1`) scales the /// shelf gain, so "Off" is a true identity and the effect is live (no rebuild). 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) } /// Spring reverb → tremolo, inserted after the tone stack and before the power amp. public override func onboardEffects(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput { let reverbed: SpringReverb.Audio = SpringReverb.Audio( input: signal, mix: $reverb, sampleRate: sampleRate) // Unipolar sine LFO over [1 − intensity, 1]: peak gain 1.0, trough 1 − intensity. let lfoScale: any ValidGeneratorInput = $intensity * tremoloDepthScale let lfoOffset: any ValidGeneratorInput = 1.0 - ($intensity * tremoloDepthScale) let lfo: OscSin.Audio = OscSin.Audio(freq: $speed, mul: lfoScale, add: lfoOffset) return reverbed * lfo } }