// FeedbackDelayPedal.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import LyrebirdSynth import LyrebirdUI /// Feedback (tape-style) delay pedal with multiple regenerating repeats. /// /// Signal chain (inside `effect(_:)`): /// ``` /// dry → DelayLineFeedback(delay: time, decayTime: feedback) → RBJLowPass(tone) → wet /// ``` /// /// The feedback path regenerates the echo so a single note produces a train of repeats /// that decays over `feedback` seconds. A `Tone` lowpass darkens the wet signal for the /// warm, rolled-off character of a tape echo (cubic interpolation adds the same smear). /// `effect` returns the pure wet signal — the base `Pedal` blends it via `mix`. /// /// ## Knobs /// - `time`: Delay time between repeats, in seconds. /// - `feedback`: Repeat decay time in seconds — how long the echoes regenerate before /// falling to −60 dB. Longer values produce more audible repeats. /// - `tone`: Lowpass cutoff in Hz applied to the wet signal; lower darkens the echoes. public final class FeedbackDelayPedal: Pedal { /// One-line description shown in the picker and info panel. public override var summary: String { "Feedback delay with a tone-shaped repeat for dub-style echoes." } // MARK: - Parameters /// Delay time between repeats, in seconds. @UIParam public var time: Double = 0.3 /// Repeat decay time in seconds (time for echoes to reach −60 dB). Longer = more repeats. @UIParam public var feedback: Double = 2.5 /// Tone (lowpass) cutoff in Hz applied to the wet echoes. @UIParam public var tone: Double = 4000.0 // MARK: - Constants /// Maximum supported delay time in seconds. Sizes the delay-line buffer at init. private let maxDelayTime: Double = 1.5 /// Amplitude target for the `decayTime` calculation (−60 dB). private let targetAmp: Double = 0.001 /// Butterworth Q for the tone lowpass (no resonant peak). private let toneQ: Double = 0.707 /// Partial wet/dry blend so the dry note and its echoes coexist. private static let defaultMix: Double = 0.35 // MARK: - Ranges private let timeRange: ClosedRange = 0.02 ... 1.5 private let feedbackRange: ClosedRange = 0.1 ... 8.0 private let toneRange: ClosedRange = 500.0 ... 8000.0 // MARK: - Knobs public override var effectKnobs: [PedalKnob] { [ PedalKnob(label: "Time", node: $time, range: timeRange), PedalKnob(label: "Decay Time", node: $feedback, range: feedbackRange), PedalKnob(label: "Tone", node: $tone, range: toneRange), ] } // MARK: - Init public init(inputBus: Int = 0, outputBus: Int = 0) { super.init( name: "Feedback Delay", inputBus: inputBus, outputBus: outputBus, initialMix: FeedbackDelayPedal.defaultMix ) } // MARK: - Effect public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput { let echoes: DelayLineFeedback = DelayLineFeedback( input: dry, maxDelay: maxDelayTime, delay: $time, decayTime: $feedback, targetAmp: targetAmp, sampleRate: sampleRate, interpolation: .cubic ) return RBJLowPass.Audio( input: echoes, freq: $tone, q: toneQ ) } }