Files
ShoeGaze/Sources/LyrebirdShoeGaze/Pedals/ReverbPedal.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

116 lines
3.8 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.
// ReverbPedal.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import LyrebirdSynth
import LyrebirdUI
/// Reverb pedal: Freeverb stereo reverb folded to mono.
///
/// Signal chain (inside `effect(_:)`):
/// ```
/// dry → FreeVerb.Audio(mix: 1.0, roomSize:, damping:) → stereo (2 ch)
/// → SumChannels.Audio(mul: 0.5) → mono (fold + compensate)
/// ```
///
/// `FreeVerb` is driven at `mix: 1.0` so it produces a pure wet signal; the base
/// `Pedal` class handles the wet/dry blend via its `mix` parameter. The stereo
/// output from `FreeVerb` is summed to mono with a ×0.5 gain to compensate for
/// the channel doubling.
///
/// ## Parameters
///
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
///
/// - Parameters:
/// - roomSize: Room size in [0, 1]. Larger values produce longer, denser tails.
/// Defaults to `0.6`.
/// - damping: High-frequency damping in [0, 1]. Higher values produce darker,
/// shorter tails. Defaults to `0.5`.
public final class ReverbPedal: Pedal {
/// One-line description shown in the picker and info panel.
public override var summary: String {
"Reverb adding space and ambience, from small rooms to vast halls."
}
// MARK: - Parameters
/// Room size in [0, 1]. Larger = longer reverb tail.
@UIParam public var roomSize: Double = 0.6
/// High-frequency damping in [0, 1]. Higher = darker tail.
@UIParam public var damping: Double = 0.5
// MARK: - Constants
/// FreeVerb mix value. Set to 1.0 so FreeVerb produces pure wet output;
/// the base Pedal handles dry/wet blending via its own `mix` parameter.
private let freeVerbWetMix: Double = 1.0
/// Gain applied to the summed stereo→mono fold to compensate for the doubling
/// of energy when two channels are added together.
private let stereoSumGain: Double = 0.5
/// Default wet/dry blend — a partial mix so the dry signal stays up front.
private static let defaultMix: Double = 0.3
// MARK: - UI knobs
/// Room-size and damping knob range (both normalised [0, 1]).
private let normalizedRange: ClosedRange<Double> = 0.0 ... 1.0
// MARK: - Init
/// Creates a reverb 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: "Reverb",
inputBus: inputBus,
outputBus: outputBus,
initialMix: ReverbPedal.defaultMix
)
}
public override var effectKnobs: [PedalKnob] {
[
PedalKnob(label: "Room", node: $roomSize, range: normalizedRange),
PedalKnob(label: "Damp", node: $damping, range: normalizedRange),
]
}
// MARK: - Effect
/// Applies Freeverb stereo reverb and folds the result to mono.
///
/// Returns a mono wet signal. The base `Pedal` class mixes this with the
/// dry signal according to the `mix` parameter.
///
/// - Parameter dry: Dry mono input signal.
/// - Returns: Wet mono reverberated output.
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
// FreeVerb produces a 2-channel stereo output.
let stereoVerb: FreeVerb.Audio = FreeVerb.Audio(
source: dry,
roomSize: $roomSize,
damping: $damping,
mix: freeVerbWetMix,
sampleRate: sampleRate
)
// Sum stereo → mono with ×0.5 to avoid level doubling.
return SumChannels.Audio(
input: stereoVerb,
mul: stereoSumGain
)
}
}