fix(noise-gate): smooth asymmetric close + Attack/Release knobs
Reported bug: a sustained note popped into a different tone mid-decay (~3.63s in the user's recording). Root cause confirmed by rendering the user's rig with their input file: the gate keyed off the raw guitar and, as a note decayed through the threshold, snapped its gain 1.0 -> floor in ~10 ms (symmetric 10 ms Lag). With heavy downstream gain (the rig's Fuzz, ~50x) amplifying that step, the ~-9 dB duck read as an audible pop. Fix: replace the symmetric Lag with an asymmetric LagUpDown — fast open (so a note's attack isn't softened) / slow close (fades the gate shut and rides out envelope chatter at the threshold). Verified against the user's input file: the gate gain now fades 1.0 -> floor smoothly over ~70 ms, monotonic, no snap. Feature (per request): expose Attack (open) and Release (close) time as knobs in the advanced pop-over rather than a separate near-duplicate "Vari" gate. Placed in advancedKnobs so they persist append-only in advancedValues — gates saved before this load with the timing at defaults, no migration (verified by test). Release default 0.08 = the smooth close; range 10 ms..500 ms. Tests: gate close lingers longer with a longer Release and the default lingers well past a fast close (guards the pop fix + the Release control); Attack/ Release exposed in the pop-over (not the face), round-trip through state, and a legacy no-advancedValues preset defaults the timing. 675 tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -14,15 +14,17 @@ import LyrebirdUI
|
||||
/// dry ─┬─────────────────────────────────────────────────────────┐
|
||||
/// └→ AmplitudeFollower → Schmidt(lo: thr, hi: thr×ratio) │
|
||||
/// → LinLin(0…1 → floor…1) │
|
||||
/// → Lag(smooth) ───────────── × ──┴→ mono out
|
||||
/// → LagUpDown(fast open/slow close) × ─┴→ 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.
|
||||
/// gate is mapped to a gain in `[floor, 1]` and smoothed **asymmetrically** — opening fast so a
|
||||
/// note's attack isn't softened, closing slowly so the gate fades shut instead of snapping (a fast
|
||||
/// close popped audibly when heavy downstream gain amplified the step). 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.
|
||||
///
|
||||
@@ -35,6 +37,8 @@ import LyrebirdUI
|
||||
/// 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`.
|
||||
/// - attack: Gate open time in seconds (advanced pop-over). Range `[0.001, 0.05]`. Defaults to `0.005`.
|
||||
/// - release: Gate close time in seconds (advanced pop-over). Range `[0.01, 0.5]`. Defaults to `0.08`.
|
||||
public final class NoiseGatePedal: Pedal {
|
||||
|
||||
/// One-line description shown in the picker and info panel.
|
||||
@@ -50,6 +54,15 @@ public final class NoiseGatePedal: Pedal {
|
||||
/// Residual gain while closed, [0, 1]. Range [0, 1].
|
||||
@UIParam public var floor: Double = 0.0
|
||||
|
||||
/// Gate **Attack** (open time) in seconds — how fast the gate opens on a note. Short keeps
|
||||
/// transients crisp. Range `[0.001, 0.05]`. Surfaced in the advanced pop-over.
|
||||
@UIParam public var attack: Double = 0.005
|
||||
|
||||
/// Gate **Release** (close time) in seconds — how gradually the gate fades shut as a note decays
|
||||
/// through the threshold. Short = a tight, fast gate; long = a gentle swell-down (and it rides
|
||||
/// out chatter at the threshold). Range `[0.01, 0.5]`. Surfaced in the advanced pop-over.
|
||||
@UIParam public var release: Double = 0.08
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
/// Default wet/dry blend — fully wet; the gate sits in-line.
|
||||
@@ -65,8 +78,11 @@ public final class NoiseGatePedal: Pedal {
|
||||
/// 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-gain smoothing is **asymmetric** (``attack`` open / ``release`` close) so the gate opens
|
||||
// promptly (a new note's attack isn't softened) but closes gently. A fast symmetric close
|
||||
// snapped the gain from unity to `floor` in ~10 ms, which — with heavy downstream gain
|
||||
// (fuzz/boost) amplifying the step — read as an audible "pop" as a sustained note decayed
|
||||
// through the threshold. A slower `release` fades the gate shut instead and rides out chatter.
|
||||
|
||||
/// Gate signal bounds for the `LinLin` floor map.
|
||||
private let gateLo: Double = 0.0
|
||||
@@ -83,6 +99,12 @@ public final class NoiseGatePedal: Pedal {
|
||||
/// Floor knob range (residual gain).
|
||||
private let floorRange: ClosedRange<Double> = 0.0 ... 1.0
|
||||
|
||||
/// Attack (open-time) knob range, seconds.
|
||||
private let attackRange: ClosedRange<Double> = 0.001 ... 0.05
|
||||
|
||||
/// Release (close-time) knob range, seconds.
|
||||
private let releaseRange: ClosedRange<Double> = 0.01 ... 0.5
|
||||
|
||||
public override var effectKnobs: [PedalKnob] {
|
||||
[
|
||||
PedalKnob(label: "Threshold", node: $threshold, range: thresholdRange),
|
||||
@@ -90,6 +112,16 @@ public final class NoiseGatePedal: Pedal {
|
||||
]
|
||||
}
|
||||
|
||||
/// Timing controls, tucked behind the pedal card's advanced pop-over: **Attack** (open time) and
|
||||
/// **Release** (close time). Live nodes, append-only in `advancedValues` — a gate saved before
|
||||
/// these existed loads with them at their defaults, no migration.
|
||||
public override var advancedKnobs: [PedalKnob] {
|
||||
[
|
||||
PedalKnob(label: "Attack", node: $attack, range: attackRange),
|
||||
PedalKnob(label: "Release", node: $release, range: releaseRange),
|
||||
]
|
||||
}
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// Creates a noise-gate pedal.
|
||||
@@ -141,10 +173,12 @@ public final class NoiseGatePedal: Pedal {
|
||||
outHi: openGain
|
||||
)
|
||||
|
||||
// Smooth the gain to remove the click of an instantaneous gate transition.
|
||||
let smoothed: Lag.Audio = Lag.Audio(
|
||||
// Smooth the gain asymmetrically: open fast (prompt on a note), close slowly (gentle fade,
|
||||
// no pop, and it rides out chatter as the envelope hovers at the threshold).
|
||||
let smoothed: LagUpDown.Audio = LagUpDown.Audio(
|
||||
input: gain,
|
||||
time: gainSmoothTime
|
||||
lagUp: $attack,
|
||||
lagDown: $release
|
||||
)
|
||||
|
||||
return dry * smoothed
|
||||
|
||||
Reference in New Issue
Block a user