69f50b2037
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>
103 lines
3.3 KiB
Swift
103 lines
3.3 KiB
Swift
// 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
|
||
)
|
||
}
|
||
}
|