// 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 around the base delay /// (the LFO is bipolar, so the delay swings both above and below `baseDelaySeconds`). @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), ] ), ] } /// 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 = 5.08 // 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 ) } }