fix(amps): true ±1 ceiling — hard safety clamp after the tanh stage

Review follow-up: the tanh output stage soft-limits but does not strictly bound
output — its DC-blocker (Nyquist gain ~1.0025) and the halfband oversampling
filters can leave a sub-percent transient overshoot above ±1, which the DAC
would still clip. The prior "can never overshoot" doc claim was overstated.

Add a final Clip(±1) after the tanh: the tanh does the musical analog-style
soft-limiting, the clamp only catches the inaudible ripple residue, so the amp
stage provably never emits a sample past ±1. Docs corrected (soft-limit is a
digital safety ceiling placed after the cab, not literal circuit order; master
Level ≤ 1 carries the ceiling through). Ceiling test tightened 1.05 → 1.0+1e-4.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-02 21:15:16 -07:00
parent fb50538e84
commit 544a07d569
2 changed files with 24 additions and 12 deletions
@@ -98,8 +98,9 @@ struct AmpVoicePedalTests {
}
@Test func outputStaysWithinDigitalCeiling() throws {
// The tanh output stage soft-limits to ±1 (a small margin allows for oversampling-filter
// ripple on transients). Drive every voice hard and check nothing hard-clips the DAC.
// The tanh soft-limits and the trailing Clip(±1) hard-clamps, so no sample may exceed ±1
// (a tiny epsilon covers float round-trip through the CAF). Drive every voice hard.
let ceilingEpsilon: Double = 1.0e-4
for voice in voices {
let hot: [Float] = try render(voice.make) { (pedal: AmpVoicePedal) in
pedal.gain = 30.0
@@ -107,7 +108,7 @@ struct AmpVoicePedalTests {
pedal.treble = 1.0
}
let peak: Double = hot.reduce(0.0) { Swift.max($0, abs(Double($1))) }
#expect(peak <= 1.05, "\(voice.name) peak \(peak) exceeds the digital ceiling")
#expect(peak <= 1.0 + ceilingEpsilon, "\(voice.name) peak \(peak) exceeds the ±1 ceiling")
#expect(peak > 0.3, "\(voice.name) unexpectedly quiet at max gain: \(peak)")
}
}