Harden new generators against non-finite control inputs
Sanitise control-rate reads (finite check + clamp) before they reach seconds→frames Int conversions or feedback math, so a NaN/inf/huge size, delay, downsample, bits, decay, shimmer, damp, or feedback can never trap the Int() conversion nor poison a feedback loop: - ShimmerReverb: clamp() helper; bound size to maxSizeSeconds before Int. - ReverseDelay: finite-clamp delay (to maxDelaySeconds) and feedback. - SampleRateDecimate: clamp downsample to [1, maximumFactor] before Int. - BitReduce: finite-guard bits before Int(bits.rounded()). Adds a ShimmerReverb regression test (NaN controls → finite output). Keeps `import Foundation` in ShimmerReverb (cos for the init-time Hann table) with a clarifying comment. Suite 256. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -57,7 +57,10 @@ public final class BitReduce: GeneratorBase, AudioGenerator {
|
||||
_checkCount(count)
|
||||
guard count > 0 else { return _result }
|
||||
|
||||
let bits: Double = min(max(_bits.floatValue(graph: graph), minimumBits), maximumBits)
|
||||
// Sanitise the control read (finite + clamped) so `Int(bits.rounded())` can't trap on a
|
||||
// NaN/inf input.
|
||||
let rawBits: Double = _bits.floatValue(graph: graph)
|
||||
let bits: Double = rawBits.isFinite ? min(max(rawBits, minimumBits), maximumBits) : minimumBits
|
||||
// Number of quantisation levels = 2^bits, via an integer shift (avoids importing `pow`).
|
||||
// Clamp the shift amount directly too: `1 << bitsInt` is only safe while bits ∈ [1, 16].
|
||||
let bitsInt: Int = min(max(Int(bits.rounded()), 1), 16)
|
||||
|
||||
Reference in New Issue
Block a user