// 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. /// /// A **Reverb** and a **Vibrato** switch model the amp's two-button footswitch: each bypasses its /// effect (dry pass-through) while preserving the knob positions, so a player can stomp the FX in /// and out without losing their settings. 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 /// Reverb footswitch: `1` = reverb engaged, `0` = bypassed (dry pass-through, `Reverb` knob /// setting preserved). Models the amp's reverb footswitch. @UIParam public var reverbEnabled: Double = 1.0 /// Vibrato footswitch: `1` = tremolo engaged, `0` = bypassed (`Speed`/`Intensity` preserved). /// Models the amp's vibrato footswitch. @UIParam public var vibratoEnabled: Double = 1.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 switchOffValue: Double = 0.0 private let switchOnValue: 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: switchOffValue), PedalSwitch.Option(title: "On", value: switchOnValue), ] ), PedalSwitch( label: "Reverb", node: $reverbEnabled, options: [ PedalSwitch.Option(title: "Off", value: switchOffValue), PedalSwitch.Option(title: "On", value: switchOnValue), ] ), PedalSwitch( label: "Vibrato", node: $vibratoEnabled, options: [ PedalSwitch.Option(title: "Off", value: switchOffValue), PedalSwitch.Option(title: "On", value: switchOnValue), ] ), ] } // 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. /// /// The `reverbEnabled` / `vibratoEnabled` footswitches gate each effect live by scaling its wet /// amount to zero: reverb collapses to a dry pass-through and the tremolo LFO collapses to a /// constant `1.0` (identity), each while preserving its knob positions and needing no rebuild. public override func onboardEffects(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput { // Footswitch gates the wet mix to 0 → SpringReverb passes the dry signal through. let reverbMix: any ValidGeneratorInput = $reverb * $reverbEnabled let reverbed: SpringReverb.Audio = SpringReverb.Audio( input: signal, mix: reverbMix, sampleRate: sampleRate) // Footswitch gates depth to 0 → LFO is a constant 1.0. Unipolar sine over [1 − depth, 1]: // peak gain 1.0, trough 1 − depth. let depth: any ValidGeneratorInput = $intensity * $vibratoEnabled let lfoScale: any ValidGeneratorInput = depth * tremoloDepthScale let lfoOffset: any ValidGeneratorInput = 1.0 - (depth * tremoloDepthScale) let lfo: OscSin.Audio = OscSin.Audio(freq: $speed, mul: lfoScale, add: lfoOffset) return reverbed * lfo } }