Files
ShoeGaze/Sources/LyrebirdShoeGaze/Pedals/LimiterPedal.swift
T
josh e697789bd7 feat(pedals): limiter Release knob + compressor safety limiter; bump Lyrebird 1.6.4
Consume Lyrebird 1.6.4, which decouples LookAheadLimiter's release time from
its look-ahead window.

- LimiterPedal: add a Release knob (0.01–0.5 s) wired to the new
  LookAheadLimiter.releaseTime. A too-fast release modulated the gain within a
  low-frequency cycle and distorted sustained notes when driven hard.
- CompressorPedal: add an opt-in Safety switch (off by default) that inserts a
  brick-wall LookAheadLimiter after the compressor to catch transient overshoot
  that could clip the output. Built as both branches with Select picking live;
  engaging it adds the limiter's short look-ahead delay.

Tests cover the new knob/switch exposure, release-time effect, and that the
safety limiter caps peaks.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 18:22:43 -07:00

119 lines
4.1 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`.
/// - release: Gain-release time in seconds. Too short a release modulates the gain
/// within a waveform cycle and distorts low notes; longer is cleaner but lets the
/// level swell back more slowly. Range `[0.01, 0.5]`. Defaults to `0.05`.
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
/// Gain-release time in seconds. Range [0.01, 0.5].
@UIParam public var release: Double = 0.05
// 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
/// Release knob range in seconds.
private let releaseRange: ClosedRange<Double> = 0.01 ... 0.5
public override var effectKnobs: [PedalKnob] {
[
PedalKnob(label: "Boost", node: $boost, range: boostRange),
PedalKnob(label: "Ceiling", node: $ceiling, range: ceilingRange),
PedalKnob(label: "Release", node: $release, range: releaseRange),
]
}
// 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,
releaseTime: $release,
sampleRate: sampleRate
)
}
}