f29ab609bd
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>
109 lines
3.4 KiB
Swift
109 lines
3.4 KiB
Swift
// DelayPedal.swift
|
||
// Lyrebird
|
||
//
|
||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||
// SPDX-License-Identifier: MIT
|
||
|
||
import LyrebirdSynth
|
||
import LyrebirdUI
|
||
|
||
/// Delay pedal: feedback delay line.
|
||
///
|
||
/// Signal chain (inside `effect(_:)`):
|
||
/// ```
|
||
/// dry → DelayLineFeedback(delay: time, decayTime: feedback) → mono wet out
|
||
/// ```
|
||
///
|
||
/// `effect` returns the pure wet delay signal. The base `Pedal` class handles
|
||
/// wet/dry blending via `mix`, so do not pre-blend inside `effect`.
|
||
///
|
||
/// ## Parameters
|
||
///
|
||
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
||
///
|
||
/// - Parameters:
|
||
/// - time: Delay time in seconds. Range `[0.01, 1.5]`. Defaults to `0.25`.
|
||
/// - feedback: Feedback amount expressed as decay time in seconds — the time
|
||
/// for echoes to fall to `targetAmp` (−60 dB). Longer values produce more
|
||
/// repeats. Range `[0.05, 6.0]` seconds. Defaults to `1.0`.
|
||
public final class DelayPedal: Pedal {
|
||
|
||
/// One-line description shown in the picker and info panel.
|
||
public override var summary: String {
|
||
"Echo delay with adjustable time and decay, from slapback to long repeats."
|
||
}
|
||
|
||
// MARK: - Parameters
|
||
|
||
/// Delay time in seconds. Range [0.01, 1.5].
|
||
@UIParam public var time: Double = 0.25
|
||
|
||
/// Feedback decay time in seconds (time to reach −60 dB amplitude).
|
||
@UIParam public var feedback: Double = 1.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
|
||
|
||
/// Default wet/dry blend — a partial mix so dry signal and echoes coexist.
|
||
private static let defaultMix: Double = 0.35
|
||
|
||
// MARK: - UI knobs
|
||
|
||
/// Delay-time knob range in seconds.
|
||
private let timeRange: ClosedRange<Double> = 0.01 ... 1.5
|
||
|
||
/// Feedback (decay-time) knob range in seconds.
|
||
private let feedbackRange: ClosedRange<Double> = 0.05 ... 6.0
|
||
|
||
// MARK: - Init
|
||
|
||
/// Creates a delay 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: "Delay",
|
||
inputBus: inputBus,
|
||
outputBus: outputBus,
|
||
initialMix: DelayPedal.defaultMix
|
||
)
|
||
}
|
||
|
||
public override var effectKnobs: [PedalKnob] {
|
||
[
|
||
PedalKnob(label: "Time", node: $time, range: timeRange),
|
||
PedalKnob(label: "Decay Time", node: $feedback, range: feedbackRange),
|
||
]
|
||
}
|
||
|
||
// MARK: - Effect
|
||
|
||
/// Applies a feedback delay line. Returns the pure wet (delayed) signal.
|
||
///
|
||
/// The base class `Pedal` mixes this with the dry signal via the `mix` parameter.
|
||
///
|
||
/// - Parameter dry: Dry mono input signal.
|
||
/// - Returns: Pure wet mono delayed output.
|
||
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||
DelayLineFeedback(
|
||
input: dry,
|
||
maxDelay: maxDelayTime,
|
||
delay: $time,
|
||
decayTime: $feedback,
|
||
targetAmp: targetAmp,
|
||
sampleRate: sampleRate,
|
||
interpolation: .linear
|
||
)
|
||
}
|
||
}
|