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:
@@ -63,6 +63,24 @@ struct ModernHighGainAmpPedalTests {
|
||||
#expect(windowedSSD(stiff, saggy) > 0, "Sag had no effect")
|
||||
}
|
||||
|
||||
@Test func sagAttenuatesWithoutPhaseInversion() throws {
|
||||
// With Presence/Depth maxed the shelf boosts push the sag envelope above 1; the sag gain
|
||||
// must stay positive (attenuation), never go negative (phase inversion). Assert the sag'd
|
||||
// output correlates positively with the stiff one (not an inverted copy).
|
||||
let cfg: (ModernHighGainAmpPedal) -> Void = { (p: ModernHighGainAmpPedal) in
|
||||
p.gain = 20.0; p.channel = 1.0; p.presence = 1.0; p.depth = 1.0
|
||||
}
|
||||
let stiff: [Float] = try render { cfg($0); $0.sag = 0.0 }
|
||||
let saggy: [Float] = try render { cfg($0); $0.sag = 1.0 }
|
||||
let skip: Int = 4096, window: Int = 4096
|
||||
guard stiff.count >= skip + window, saggy.count >= skip + window else {
|
||||
Issue.record("render too short"); return
|
||||
}
|
||||
let corr: Double = zip(stiff[skip..<(skip + window)], saggy[skip..<(skip + window)])
|
||||
.reduce(0.0) { acc, pair in acc + Double(pair.0) * Double(pair.1) }
|
||||
#expect(corr > 0, "sag phase-inverted the signal (correlation \(corr) < 0)")
|
||||
}
|
||||
|
||||
@Test func tightSwitchChangesOutput() throws {
|
||||
let loose: [Float] = try render { $0.tight = 0.0 }
|
||||
let tight: [Float] = try render { $0.tight = 1.0 }
|
||||
|
||||
Reference in New Issue
Block a user