Fix Shimmer DC offset: DC-block the feedback path

High shimmer built a DC offset: the octave-up of DC is DC and the damping
one-pole passes DC, so the loop DC gain (~decay + shimmer) exceeds 1 above
~shimmer 0.25 at high decay and accumulates a clamped offset. Add a one-pole
DC blocker (~7 Hz, sub-bass only) on the feedback path so the loop has no DC
gain; the shimmer wash is unaffected.

Adds a regression test (zero-mean input, max shimmer/decay, small tank →
no DC offset vs the no-shimmer baseline). Suite 257.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-28 14:40:18 -07:00
parent 8775134d4f
commit f573d1e9a6
2 changed files with 34 additions and 2 deletions
@@ -104,6 +104,20 @@ struct ShimmerReverbTests {
#expect(samples.allSatisfy { $0.isFinite }, "non-finite controls produced NaN/inf output")
}
@Test func highShimmerDoesNotAccumulateDCOffset() throws {
// The octave-up of DC is DC and the damping filter passes DC, so without a feedback
// DC-blocker the loop DC gain (~decay + shimmer) exceeds 1 at high settings and builds an
// offset. Aggressive small-tank settings iterate the loop many times within the read window.
func meanDC(_ shimmer: Double) throws -> Double {
let s: [Float] = try render(oscFreq: 440.0, dc: 0.0, size: 0.005, decay: 0.92, shimmer: shimmer)
return s.reduce(0.0) { $0 + Double($1) } / Double(max(s.count, 1))
}
let noShimmer: Double = try meanDC(0.0)
let maxShimmer: Double = try meanDC(0.85)
#expect(abs(maxShimmer) < 0.015, "high shimmer accumulated a DC offset (mean = \(maxShimmer))")
#expect(abs(maxShimmer - noShimmer) < 0.012, "shimmer added DC vs the no-shimmer baseline")
}
@Test func decayChangesTheTail() throws {
// Small tank so feedback round-trips compound within the reader's window; different decay
// must change the tail (direction-agnostic — a tuned comb is not monotonic in level).