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:
@@ -125,11 +125,16 @@ public final class ReverseDelay: GeneratorBase, AudioGenerator {
|
||||
guard count > 0 else { return _result }
|
||||
|
||||
let sampleRate: Double = graph.engine.sampleRate
|
||||
let delaySeconds: Double = _delay.floatValue(graph: graph)
|
||||
// Sanitise control reads (finite + clamped): a NaN/inf/huge `delay` would otherwise trap the
|
||||
// seconds→frames `Int` conversion, and a NaN `feedback` would poison the loop.
|
||||
let maxDelaySeconds: Double = Double(_maxFrames) / sampleRate
|
||||
let rawDelay: Double = _delay.floatValue(graph: graph)
|
||||
let delaySeconds: Double = rawDelay.isFinite ? min(max(rawDelay, 0.0), maxDelaySeconds) : 0.0
|
||||
let rawFeedback: Double = _feedback.floatValue(graph: graph)
|
||||
let feedback: Double = min(max(rawFeedback, 0.0), maxFeedback)
|
||||
let feedback: Double = rawFeedback.isFinite ? min(max(rawFeedback, 0.0), maxFeedback) : 0.0
|
||||
|
||||
// Target segment length, applied at the next boundary so a read never changes length mid-segment.
|
||||
// `delaySeconds` is bounded to `maxDelaySeconds`, so the `Int` conversion cannot overflow.
|
||||
let targetLen: Int = min(max(Int((delaySeconds * sampleRate).rounded()), 1), _maxFrames)
|
||||
|
||||
let inputSamples: [Double] = _inputIsGenerator
|
||||
|
||||
Reference in New Issue
Block a user