From 7a39a2477e60af74e2bc6a848a40438dd2113aa6 Mon Sep 17 00:00:00 2001 From: Joshua Parmenter Date: Sun, 28 Jun 2026 09:33:24 -0700 Subject: [PATCH] ShimmerReverb: flush denormals in tank feedback; clarify grain-read doc Review nits: denormal-flush the recirculated tank value (not just the damping state) so denormals can't persist in the buffer and burn RT CPU; document that the octave-up grains read the recent wet tank content. Co-Authored-By: Claude Opus 4.8 --- Sources/LyrebirdShoeGaze/Generators/ShimmerReverb.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/LyrebirdShoeGaze/Generators/ShimmerReverb.swift b/Sources/LyrebirdShoeGaze/Generators/ShimmerReverb.swift index a4ba69a..a97d0f1 100644 --- a/Sources/LyrebirdShoeGaze/Generators/ShimmerReverb.swift +++ b/Sources/LyrebirdShoeGaze/Generators/ShimmerReverb.swift @@ -25,9 +25,10 @@ private let shimmerReverbZeroBlock: [Double] = makeSampleBuffer() /// feedback = decay·damped + shimmer·pitched → written back into the tank /// ``` /// -/// The octave-up is a two-grain, 50%-overlap, Hann-windowed reader running at 2× over the tank -/// buffer (a tape-style pitch raise). A per-sample safety clamp + denormal flush keep the loop -/// bounded even at high `decay` / `shimmer`. +/// The octave-up is a two-grain, 50%-overlap, Hann-windowed reader running at 2× over the most +/// recent `grain` samples of the tank (the live wet content), a tape-style pitch raise whose +/// pitched output recirculates through the feedback. A per-sample safety clamp + denormal flush +/// keep the loop bounded even at high `decay` / `shimmer`. /// /// `size`, `decay`, `shimmer`, and `damp` are read at control rate (once per block). Output is mono. /// @@ -214,6 +215,8 @@ public final class ShimmerReverb: GeneratorBase, AudioGenerator { var writeVal: Double = diffused + decay * damped + shimmer * pitched if writeVal > safetyClamp { writeVal = safetyClamp } else if writeVal < -safetyClamp { writeVal = -safetyClamp } + // Flush denormals so they never recirculate in the tank (RT CPU guard). + if abs(writeVal) < denormalFloor { writeVal = 0.0 } tank[writePos] = writeVal out[i] = damped