fix(amps): clamp Modern High-Gain sag gain (no phase inversion)
Review blocker: sag gain 1 - sag*envelope went negative because the envelope follows the post-Presence/Depth-shelf signal, which exceeds 1 (shelves add up to +8/+6 dB) — at high sag+presence+depth it phase-inverted loud content instead of drooping (verified ~-1.0 correlation). Clamp the sag gain to [sagGainFloor(0.15), 1] so it always attenuates, never inverts. Doc/const nits fixed (per-const docs, "switches" not "sweeps" for the binary Tight). Regression test asserts positive correlation (no inversion) at presence/depth/sag maxed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -26,10 +26,16 @@ public final class ModernHighGainAmpPedal: BoutiqueAmpPedal {
|
||||
private let sagAttackSeconds: Double = 0.02
|
||||
/// Sag envelope-follower release — slow, so the sag lingers and blooms back (supply recovery).
|
||||
private let sagReleaseSeconds: Double = 0.30
|
||||
/// Tight low-cut: high-pass corner sweeps from ~20 Hz (loose, no cut) to `tightFreqHz`.
|
||||
/// Tight low-cut: high-pass corner is ~20 Hz (loose, no cut) or `tightFreqHz` (tight).
|
||||
private let tightLooseFreqHz: Double = 20.0
|
||||
/// Tight-switch-on high-pass corner in Hz.
|
||||
private let tightFreqHz: Double = 120.0
|
||||
/// Tight high-pass Q (Butterworth).
|
||||
private let tightQ: Double = 0.707
|
||||
/// Lowest the sag gain can droop to. Bounds sag depth and — crucially — keeps the gain strictly
|
||||
/// positive: the envelope tracks a post-shelf signal that can exceed 1, so an unclamped
|
||||
/// `1 − sag·env` would go negative and phase-invert loud content instead of drooping.
|
||||
private let sagGainFloor: Double = 0.15
|
||||
|
||||
public override var toneStackModel: ToneStackModel { .mesa }
|
||||
public override var summaryText: String {
|
||||
@@ -65,8 +71,8 @@ public final class ModernHighGainAmpPedal: BoutiqueAmpPedal {
|
||||
cab = 1.0 // British 4×12 — tight, aggressive
|
||||
}
|
||||
|
||||
/// Tight switch: a pre-preamp high-pass whose corner sweeps from ~20 Hz (loose) to
|
||||
/// `tightFreqHz` (tight), firming the low end without a rebuild.
|
||||
/// Tight switch: a pre-preamp high-pass whose corner switches between ~20 Hz (loose, negligible
|
||||
/// cut) and `tightFreqHz` (tight), firming the low end — live, no rebuild.
|
||||
public override func inputShaping(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||
let cutoff: LinLin.Audio = LinLin.Audio(
|
||||
$tight, inLo: 0.0, inHi: 1.0, outLo: tightLooseFreqHz, outHi: tightFreqHz)
|
||||
@@ -79,8 +85,11 @@ public final class ModernHighGainAmpPedal: BoutiqueAmpPedal {
|
||||
let shaped: any ValidGeneratorInput = super.shapeVoice(signal)
|
||||
let envelope: AmplitudeFollower.Audio = AmplitudeFollower.Audio(
|
||||
in: shaped, attackTime: sagAttackSeconds, releaseTime: sagReleaseSeconds)
|
||||
// Gain droops toward (1 − sag) as the envelope rises; |signal| ≤ ~1 so gain stays in [0, 1].
|
||||
let sagGain: any ValidGeneratorInput = 1.0 - ($sag * envelope)
|
||||
// Gain droops toward `sagGainFloor` as the envelope rises. The Presence/Depth shelves can
|
||||
// push the envelope above 1, so clamp to `[sagGainFloor, 1]` — an unclamped `1 − sag·env`
|
||||
// would go negative and phase-invert loud content instead of attenuating it.
|
||||
let sagGain: any ValidGeneratorInput = Clip.Audio(
|
||||
1.0 - ($sag * envelope), lo: sagGainFloor, hi: 1.0)
|
||||
return shaped * sagGain
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user