Add Limiter, Noise Gate, and Graphic EQ pedals + vertical-fader UI control
Three new pedals: - LimiterPedal: linear boost gain stage into a LookAheadLimiter brick-wall ceiling. Reads engine sampleRate injected by PedalBoard.add at build time. - NoiseGatePedal: AmplitudeFollower -> hysteretic Schmidt gate -> LinLin floor map -> Lag smoothing. Tuneable residual floor when the gate is closed. - GraphicEQPedal: five cascaded RBJ filters (low/high shelf + three peaking mids) with per-band dB gains and a linear master output gain. New UI control: - PedalSlider descriptor and Pedal.effectSliders hook, alongside effectKnobs and effectSwitches. - VerticalParameterSlider: a vertical fader bound to a UIParamNode. - PedalView renders the fader bank and widens the enclosure to fit it. Persistence/registry: - PedalState.sliderValues (decodeIfPresent for backward compatibility); capture and apply in Pedal+Preset. - Registry entries and palette ordering for all three pedals. Tests: non-silent builds, limiter ceiling enforcement, gate open/closed/unity floor power ratios, EQ flat output, global-gain scaling, and 6-slider preset round-trip. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,165 @@
|
||||
// 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 {
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
// LimiterPedal.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import LyrebirdSynth
|
||||
import LyrebirdUI
|
||||
|
||||
/// Limiter pedal: a clean gain-boost stage feeding a brick-wall look-ahead limiter.
|
||||
///
|
||||
/// Signal chain (inside `effect(_:)`):
|
||||
/// ```
|
||||
/// dry → × boost → LookAheadLimiter(maxAmplitude: ceiling) → mono out
|
||||
/// ```
|
||||
///
|
||||
/// The boost stage drives the signal up *before* the limiter, so cranking `boost`
|
||||
/// pushes more of the signal into limiting and raises sustain/perceived loudness while
|
||||
/// the look-ahead limiter guarantees the output peak never exceeds `ceiling`.
|
||||
///
|
||||
/// The wet/dry mix and bypass switching are handled by the `Pedal` base class.
|
||||
///
|
||||
/// ## Parameters
|
||||
///
|
||||
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - boost: Pre-limit input gain as a linear multiplier. `1.0` = unity. Higher values
|
||||
/// drive harder into the limiter. Range `[1, 12]`. Defaults to `1.0`.
|
||||
/// - ceiling: Output peak ceiling as a linear amplitude in `[0, 1]`. The limited output
|
||||
/// never exceeds this absolute value. Range `[0.1, 1.0]`. Defaults to `0.95`.
|
||||
public final class LimiterPedal: Pedal {
|
||||
|
||||
// MARK: - Parameters
|
||||
|
||||
/// Pre-limit input gain (linear multiplier). Range [1, 12].
|
||||
@UIParam public var boost: Double = 1.0
|
||||
|
||||
/// Output peak ceiling (linear amplitude). Range [0.1, 1.0].
|
||||
@UIParam public var ceiling: Double = 0.95
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
/// Default wet/dry blend — fully wet; the limiter sits in-line.
|
||||
private static let defaultMix: Double = 1.0
|
||||
|
||||
/// Look-ahead / output delay in seconds. Fixed at a short window that catches
|
||||
/// transients without smearing attack.
|
||||
private let lookAheadTime: Double = 0.005
|
||||
|
||||
// MARK: - UI knobs
|
||||
|
||||
/// Boost knob range (linear pre-limit gain).
|
||||
private let boostRange: ClosedRange<Double> = 1.0 ... 12.0
|
||||
|
||||
/// Ceiling knob range (linear output peak).
|
||||
private let ceilingRange: ClosedRange<Double> = 0.1 ... 1.0
|
||||
|
||||
public override var effectKnobs: [PedalKnob] {
|
||||
[
|
||||
PedalKnob(label: "Boost", node: $boost, range: boostRange),
|
||||
PedalKnob(label: "Ceiling", node: $ceiling, range: ceilingRange),
|
||||
]
|
||||
}
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// Creates a limiter 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: "Limiter",
|
||||
inputBus: inputBus,
|
||||
outputBus: outputBus,
|
||||
initialMix: LimiterPedal.defaultMix
|
||||
)
|
||||
}
|
||||
|
||||
// MARK: - Effect
|
||||
|
||||
/// Boosts the dry signal then constrains its peak with a look-ahead limiter.
|
||||
///
|
||||
/// Output is mono.
|
||||
///
|
||||
/// - Parameter dry: Dry mono input signal.
|
||||
/// - Returns: Boosted, peak-limited mono output.
|
||||
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||
let boosted: any ValidGeneratorInput = dry * $boost
|
||||
return LookAheadLimiter(
|
||||
in: boosted,
|
||||
maxAmplitude: $ceiling,
|
||||
lookAheadTime: lookAheadTime,
|
||||
sampleRate: sampleRate
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
// NoiseGatePedal.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import LyrebirdSynth
|
||||
import LyrebirdUI
|
||||
|
||||
/// Noise-gate pedal: an amplitude-tracked gate with a tuneable residual floor.
|
||||
///
|
||||
/// Signal chain (inside `effect(_:)`):
|
||||
/// ```
|
||||
/// dry ─┬─────────────────────────────────────────────────────────┐
|
||||
/// └→ AmplitudeFollower → Schmidt(lo: thr, hi: thr×ratio) │
|
||||
/// → LinLin(0…1 → floor…1) │
|
||||
/// → Lag(smooth) ───────────── × ──┴→ mono out
|
||||
/// ```
|
||||
///
|
||||
/// An `AmplitudeFollower` tracks the dry signal level. A Schmitt trigger turns that
|
||||
/// envelope into an open/closed gate with hysteresis (opens above `threshold × openRatio`,
|
||||
/// closes below `threshold`) so the gate does not chatter around the threshold. The 0/1
|
||||
/// gate is mapped to a gain in `[floor, 1]` and smoothed before multiplying the dry signal:
|
||||
/// when the gate is closed the signal is attenuated to `floor` rather than hard-muted, so
|
||||
/// `floor` sets how much of the quiet signal/noise tail bleeds through.
|
||||
///
|
||||
/// The wet/dry mix and bypass switching are handled by the `Pedal` base class.
|
||||
///
|
||||
/// ## Parameters
|
||||
///
|
||||
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - threshold: Gate close threshold as a linear amplitude. Envelope below this closes
|
||||
/// the gate. Range `[0, 0.2]`. Defaults to `0.02`.
|
||||
/// - floor: Residual gain applied while the gate is closed, in `[0, 1]`. `0` = full
|
||||
/// mute, `1` = no gating. Range `[0, 1]`. Defaults to `0.0`.
|
||||
public final class NoiseGatePedal: Pedal {
|
||||
|
||||
// MARK: - Parameters
|
||||
|
||||
/// Gate close threshold (linear amplitude). Range [0, 0.2].
|
||||
@UIParam public var threshold: Double = 0.02
|
||||
|
||||
/// Residual gain while closed, [0, 1]. Range [0, 1].
|
||||
@UIParam public var floor: Double = 0.0
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
/// Default wet/dry blend — fully wet; the gate sits in-line.
|
||||
private static let defaultMix: Double = 1.0
|
||||
|
||||
/// Envelope-follower attack time, in seconds — fast so the gate opens promptly on a note.
|
||||
private let detectAttack: Double = 0.002
|
||||
|
||||
/// Envelope-follower release time, in seconds — slower so the gate holds through decay.
|
||||
private let detectRelease: Double = 0.05
|
||||
|
||||
/// Open-threshold multiplier. The gate opens above `threshold × openRatio` and closes
|
||||
/// below `threshold`, giving hysteresis that prevents chatter near the threshold.
|
||||
private let openRatio: Double = 2.0
|
||||
|
||||
/// Gain-smoothing lag time, in seconds — removes the click of an instantaneous 0↔1 gate.
|
||||
private let gainSmoothTime: Double = 0.01
|
||||
|
||||
/// Gate signal bounds for the `LinLin` floor map.
|
||||
private let gateLo: Double = 0.0
|
||||
private let gateHi: Double = 1.0
|
||||
|
||||
/// Upper gain the open gate maps to (unity).
|
||||
private let openGain: Double = 1.0
|
||||
|
||||
// MARK: - UI knobs
|
||||
|
||||
/// Threshold knob range (linear amplitude).
|
||||
private let thresholdRange: ClosedRange<Double> = 0.0 ... 0.2
|
||||
|
||||
/// Floor knob range (residual gain).
|
||||
private let floorRange: ClosedRange<Double> = 0.0 ... 1.0
|
||||
|
||||
public override var effectKnobs: [PedalKnob] {
|
||||
[
|
||||
PedalKnob(label: "Threshold", node: $threshold, range: thresholdRange),
|
||||
PedalKnob(label: "Floor", node: $floor, range: floorRange),
|
||||
]
|
||||
}
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// Creates a noise-gate 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: "Noise Gate",
|
||||
inputBus: inputBus,
|
||||
outputBus: outputBus,
|
||||
initialMix: NoiseGatePedal.defaultMix
|
||||
)
|
||||
}
|
||||
|
||||
// MARK: - Effect
|
||||
|
||||
/// Gates the dry signal below `threshold`, attenuating closed passages to `floor`.
|
||||
///
|
||||
/// Output is mono.
|
||||
///
|
||||
/// - Parameter dry: Dry mono input signal.
|
||||
/// - Returns: Gated mono output.
|
||||
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||
// Track the dry signal's amplitude envelope.
|
||||
let envelope: AmplitudeFollower.Audio = AmplitudeFollower.Audio(
|
||||
in: dry,
|
||||
attackTime: detectAttack,
|
||||
releaseTime: detectRelease
|
||||
)
|
||||
|
||||
// Hysteretic open/closed gate: opens above threshold×openRatio, closes below threshold.
|
||||
let gate: Schmidt.Audio = Schmidt.Audio(
|
||||
input: envelope,
|
||||
lo: $threshold,
|
||||
hi: $threshold * openRatio
|
||||
)
|
||||
|
||||
// Map the 0/1 gate to a gain in [floor, 1] so closed passages bleed `floor`, not silence.
|
||||
let gain: LinLin.Audio = LinLin.Audio(
|
||||
gate,
|
||||
inLo: gateLo,
|
||||
inHi: gateHi,
|
||||
outLo: $floor,
|
||||
outHi: openGain
|
||||
)
|
||||
|
||||
// Smooth the gain to remove the click of an instantaneous gate transition.
|
||||
let smoothed: Lag.Audio = Lag.Audio(
|
||||
input: gain,
|
||||
time: gainSmoothTime
|
||||
)
|
||||
|
||||
return dry * smoothed
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user