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

108 lines
3.5 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.
// 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 {
/// One-line description shown in the picker and info panel.
public override var summary: String {
"Brick-wall limiter with an input boost to push level safely to the ceiling."
}
// 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
)
}
}