// VibratoPedal.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import LyrebirdSynth import LyrebirdUI /// Pitch vibrato. /// /// A single delay line whose time is swept by a sine LFO produces a periodic pitch wobble. Unlike /// `TremoloPedal` (which modulates *volume*), vibrato modulates *pitch*, and unlike `ChorusPedal` /// it is heard fully wet — there is no dry voice underneath, so the result is pure pitch movement. /// /// ## Knobs /// - `rate`: LFO rate in Hz. Range `[0.1, 8]`. /// - `depth`: Delay-sweep depth in seconds (half-swing around the base delay). Range /// `[0.0005, 0.006]`. public final class VibratoPedal: Pedal { /// One-line description shown in the picker and info panel. public override var summary: String { "Periodic pitch wobble — a sine-swept delay heard fully wet." } // MARK: - Parameters /// LFO rate in Hz. Range [0.1, 8]. @UIParam public var rate: Double = 5.0 /// Delay-sweep depth in seconds. Range [0.0005, 0.006]. @UIParam public var depth: Double = 0.002 // MARK: - Constants /// Vibrato is pure pitch movement — fully wet, no dry voice underneath. private static let defaultMix: Double = 1.0 /// Base delay around which the LFO sweeps, in seconds. private let baseDelayTime: Double = 0.006 /// Maximum delay the line is allocated for, in seconds. Covers `baseDelayTime + max depth`. private let maxDelayTime: Double = 0.02 // MARK: - Ranges private let rateRange: ClosedRange = 0.1 ... 8.0 private let depthRange: ClosedRange = 0.0005 ... 0.006 // MARK: - Knobs public override var tempoSyncableParams: [TempoSyncableParam] { [ TempoSyncableParam(key: "rate", label: "Rate", node: $rate, kind: .rate, range: rateRange), ] } public override var effectKnobs: [PedalKnob] { [ PedalKnob(label: "Rate", node: $rate, range: rateRange), PedalKnob(label: "Depth", node: $depth, range: depthRange), ] } // MARK: - Init /// Creates a vibrato pedal. /// /// - 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: "Vibrato", inputBus: inputBus, outputBus: outputBus, initialMix: VibratoPedal.defaultMix ) } // MARK: - Effect public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput { let sweep: OscSin.Audio = OscSin.Audio( freq: $rate, phase: 0.0, mul: $depth, add: baseDelayTime ) return DelayLine( input: dry, maxDelay: maxDelayTime, delay: sweep, sampleRate: sampleRate, interpolation: .linear ) } }