Files
ShoeGaze/Sources/LyrebirdShoeGaze/Pedals/FeedbackDelayPedal.swift
T
josh f29ab609bd Add Chorus, Sustainer, Ring Modulator pedals + pedal-info UI
Pedals (each registered, with PedalType static, enclosure color, palette order,
summary, and tests):
- Chorus: true-stereo widener (two anti-phase modulated delay lines), distinct
  from the mono-summed Modulation chorus.
- Sustainer: one-knob compressor (sustain drives threshold/ratio/makeup via
  LinLin) + tone low-pass.
- Ring Modulator: dry × tunable sine carrier.

Pedal-info UI:
- Pedal.summary (open var, overridden by all 21 pedals; mandatory going forward).
- PedalRegistry.summary(for:) for the picker.
- PedalPaletteView rows show the summary as a subtitle.
- PedalView gains an ⓘ button → PedalInfoView sheet showing the description and
  the effect controls (knobs/sliders/switches) with ranges/options — excludes
  the common Mix/Level/bypass.

Tests: per-pedal build/param-change/knob-list; every built-in pedal has a
non-empty summary; info excludes common controls. 183 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 18:05:30 -07:00

105 lines
3.4 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 {
/// 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<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 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
)
}
}