Files
ShoeGaze/Sources/LyrebirdShoeGaze/Pedals/FeedbackDelayPedal.swift
T
josh 42268b65a1 Relabel delay Feedback knob as Decay
The Delay, Feedback Delay, and Ping-Pong knobs labelled 'Feedback' actually
drive DelayLineFeedback's decayTime (seconds to -60 dB), not a feedback gain —
the engine clamps the internal feedback coefficient below 1, so the control
can never grow/self-oscillate. Relabel to 'Decay' so the knob reads honestly.
Phaser's feedback is a real coefficient and is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 21:40:45 -07:00

100 lines
3.2 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 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 {
// 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<Double> = 0.02 ... 1.5
private let feedbackRange: ClosedRange<Double> = 0.1 ... 8.0
private let toneRange: ClosedRange<Double> = 500.0 ... 8000.0
// MARK: - Knobs
public override var effectKnobs: [PedalKnob] {
[
PedalKnob(label: "Time", node: $time, range: timeRange),
PedalKnob(label: "Decay", 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
)
}
}