Files
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

171 lines
6.2 KiB
Swift
Raw Permalink 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.
// GraphicEQPedal.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import LyrebirdSynth
import LyrebirdUI
/// Five-band graphic EQ pedal built from cascaded RBJ filters, with a master output gain.
///
/// Signal chain (inside `effect(_:)`):
/// ```
/// dry → RBJLowShelf(80 Hz) → RBJPeakingEQ(240 Hz) → RBJPeakingEQ(750 Hz)
/// → RBJPeakingEQ(2.2 kHz) → RBJHighShelf(6.5 kHz) → × globalGain → mono out
/// ```
///
/// Each band's gain is an `@UIParam` in decibels and is published as a vertical fader via
/// ``effectSliders`` — the pedalboard UI renders the bank as a row of graphic-EQ sliders.
/// The trailing master fader (`globalGain`, a linear multiplier) trims the overall level
/// after the EQ curve so boosting several bands need not clip the output.
///
/// Band centre frequencies and filter Q/slope are fixed; only the per-band gains and the
/// master output level are adjustable.
///
/// The wet/dry mix and bypass switching are handled by the `Pedal` base class.
///
/// ## Parameters
///
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
///
/// - Parameters:
/// - lowGain: Low-shelf gain at 80 Hz, in dB. Range `[-12, 12]`. Defaults to `0.0`.
/// - lowMidGain: Peaking gain at 240 Hz, in dB. Range `[-12, 12]`. Defaults to `0.0`.
/// - midGain: Peaking gain at 750 Hz, in dB. Range `[-12, 12]`. Defaults to `0.0`.
/// - highMidGain: Peaking gain at 2.2 kHz, in dB. Range `[-12, 12]`. Defaults to `0.0`.
/// - highGain: High-shelf gain at 6.5 kHz, in dB. Range `[-12, 12]`. Defaults to `0.0`.
/// - globalGain: Master output gain in dB. `0` = unity. Range `[-12, 12]`.
/// Defaults to `0.0`.
public final class GraphicEQPedal: Pedal {
/// One-line description shown in the picker and info panel.
public override var summary: String {
"Five-band graphic EQ with per-band faders and a master output level."
}
// MARK: - Parameters
/// Low-shelf gain in dB. Range [-12, 12].
@UIParam public var lowGain: Double = 0.0
/// Low-mid peaking gain in dB. Range [-12, 12].
@UIParam public var lowMidGain: Double = 0.0
/// Mid peaking gain in dB. Range [-12, 12].
@UIParam public var midGain: Double = 0.0
/// High-mid peaking gain in dB. Range [-12, 12].
@UIParam public var highMidGain: Double = 0.0
/// High-shelf gain in dB. Range [-12, 12].
@UIParam public var highGain: Double = 0.0
/// Master output gain in dB. Range [-12, 12]. `0` = unity.
@UIParam public var globalGain: Double = 0.0
// MARK: - Constants
/// Default wet/dry blend — fully wet; the EQ sits in-line.
private static let defaultMix: Double = 1.0
/// Band centre frequencies in Hz (low shelf, three peaks, high shelf).
private let lowFreq: Double = 80.0
private let lowMidFreq: Double = 240.0
private let midFreq: Double = 750.0
private let highMidFreq: Double = 2200.0
private let highFreq: Double = 6500.0
/// Shelf slope. `1.0` = maximum (steepest) shelf with no overshoot.
private let shelfSlope: Double = 1.0
/// Peaking-band quality factor — moderate bandwidth so adjacent bands overlap smoothly.
private let peakQ: Double = 0.9
/// dB → natural-exponent scale, `ln(10) / 20`. `exp(dB · scale) == 10^(dB/20)`, the
/// linear amplitude multiplier for a dB gain. Applied to the master output gain.
private let dbToLinExpScale: Double = 0.115_129_254_649_702_28
// MARK: - UI sliders
/// Per-band gain fader range, in dB.
private let bandGainRange: ClosedRange<Double> = -12.0 ... 12.0
/// Master output fader range, in dB.
private let globalGainRange: ClosedRange<Double> = -12.0 ... 12.0
public override var effectSliders: [PedalSlider] {
[
PedalSlider(label: "80", node: $lowGain, range: bandGainRange),
PedalSlider(label: "240", node: $lowMidGain, range: bandGainRange),
PedalSlider(label: "750", node: $midGain, range: bandGainRange),
PedalSlider(label: "2.2k", node: $highMidGain, range: bandGainRange),
PedalSlider(label: "6.5k", node: $highGain, range: bandGainRange),
PedalSlider(label: "Gain", node: $globalGain, range: globalGainRange),
]
}
// MARK: - Init
/// Creates a five-band graphic EQ 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: "Graphic EQ",
inputBus: inputBus,
outputBus: outputBus,
initialMix: GraphicEQPedal.defaultMix
)
}
// MARK: - Effect
/// Applies the cascaded five-band RBJ EQ curve, then the master output gain.
///
/// Output is mono.
///
/// - Parameter dry: Dry mono input signal.
/// - Returns: Equalised, level-trimmed mono output.
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
let lowShelf: RBJLowShelf.Audio = RBJLowShelf.Audio(
input: dry,
freq: lowFreq,
gain: $lowGain,
slope: shelfSlope
)
let lowMid: RBJPeakingEQ.Audio = RBJPeakingEQ.Audio(
input: lowShelf,
freq: lowMidFreq,
gain: $lowMidGain,
q: peakQ
)
let mid: RBJPeakingEQ.Audio = RBJPeakingEQ.Audio(
input: lowMid,
freq: midFreq,
gain: $midGain,
q: peakQ
)
let highMid: RBJPeakingEQ.Audio = RBJPeakingEQ.Audio(
input: mid,
freq: highMidFreq,
gain: $highMidGain,
q: peakQ
)
let highShelf: RBJHighShelf.Audio = RBJHighShelf.Audio(
input: highMid,
freq: highFreq,
gain: $highGain,
slope: shelfSlope
)
// Convert the master dB gain to a linear amplitude multiplier: 10^(dB/20).
let masterGain: Exp.Audio = Exp.Audio($globalGain * dbToLinExpScale)
return highShelf * masterGain
}
}