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>
This commit is contained in:
2026-07-31 18:22:43 -07:00
parent 09fa4e8d4b
commit e697789bd7
6 changed files with 172 additions and 5 deletions
@@ -32,6 +32,12 @@ import LyrebirdUI
/// compressed. Range `[-40, 0]` dB. Defaults to `-12.0`.
/// - ratio: Compression ratio `≥ 1.0`. `1.0` = bypass, `4.0` = 4:1 compression.
/// Range `[1, 20]`. Defaults to `4.0`.
///
/// A feed-forward compressor can overshoot on fast transients (its attack is non-zero),
/// so a hot input plus makeup gain can push peaks past full scale and clip the output.
/// The **Safety** switch inserts a brick-wall `LookAheadLimiter` after the compressor to
/// catch those peaks; it is off by default (leave adding a limiter to the user) and adds
/// a short look-ahead output delay when engaged.
public final class CompressorPedal: Pedal {
/// One-line description shown in the picker and info panel.
@@ -50,6 +56,10 @@ public final class CompressorPedal: Pedal {
/// Compression ratio. Range [1, 20].
@UIParam public var ratio: Double = 4.0
/// Safety limiter engage state. `0` = off (compressor may overshoot), `1` = on
/// (brick-wall look-ahead limiter catches transient peaks).
@UIParam public var safetyLimiter: Double = 0.0
// MARK: - Constants
/// Default wet/dry blend — fully wet; the compressor is inserted in-line.
@@ -71,6 +81,20 @@ public final class CompressorPedal: Pedal {
/// Makeup gain in dB applied after compression to restore perceived loudness.
private let makeupGainDB: Double = 4.0
/// Safety-limiter peak ceiling (linear amplitude), just below full scale.
private let safetyCeiling: Double = 0.98
/// Safety-limiter look-ahead / output delay in seconds. Short enough to catch
/// transients without smearing attack; only in circuit when Safety is engaged.
private let safetyLookAheadTime: Double = 0.005
/// Safety-limiter gain-release time in seconds.
private let safetyReleaseTime: Double = 0.05
/// Safety switch position values.
private let safetyOffValue: Double = 0.0
private let safetyOnValue: Double = 1.0
// MARK: - UI knobs
/// Input-gain knob range in dB.
@@ -90,6 +114,19 @@ public final class CompressorPedal: Pedal {
]
}
public override var effectSwitches: [PedalSwitch] {
[
PedalSwitch(
label: "Safety",
node: $safetyLimiter,
options: [
PedalSwitch.Option(title: "Off", value: safetyOffValue),
PedalSwitch.Option(title: "On", value: safetyOnValue),
]
)
]
}
// MARK: - Init
/// Creates a compressor pedal.
@@ -121,7 +158,7 @@ public final class CompressorPedal: Pedal {
// Convert the input-gain dB to a linear multiplier (10^(dB/20)) and apply before compression.
let inputGainLinear: Exp.Audio = Exp.Audio($inputGain * dbToLinExpScale)
let boosted: any ValidGeneratorInput = dry * inputGainLinear
return Compressor.Audio(
let compressed: Compressor.Audio = Compressor.Audio(
in: boosted,
threshold: $threshold,
ratio: $ratio,
@@ -130,5 +167,18 @@ public final class CompressorPedal: Pedal {
kneeWidth: kneeWidth,
makeupGain: makeupGainDB
)
// Brick-wall safety limiter after the compressor. Both branches are always built;
// `Select` picks per the Safety switch (0 = compressor only, 1 = limited).
let limited: LookAheadLimiter = LookAheadLimiter(
in: compressed,
maxAmplitude: safetyCeiling,
lookAheadTime: safetyLookAheadTime,
releaseTime: safetyReleaseTime,
sampleRate: sampleRate
)
return Select.Audio(
which: $safetyLimiter,
inputs: [compressed, limited]
)
}
}
@@ -29,6 +29,9 @@ import LyrebirdUI
/// 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.
@@ -44,6 +47,9 @@ public final class LimiterPedal: Pedal {
/// 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.
@@ -61,10 +67,14 @@ public final class LimiterPedal: Pedal {
/// 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),
]
}
@@ -101,6 +111,7 @@ public final class LimiterPedal: Pedal {
in: boosted,
maxAmplitude: $ceiling,
lookAheadTime: lookAheadTime,
releaseTime: $release,
sampleRate: sampleRate
)
}