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:
@@ -95,6 +95,15 @@ struct ShimmerReverbTests {
|
||||
#expect(abs(h / l - 2.0) < 0.01, "DC gain should be exactly linear (ratio 2.0)")
|
||||
}
|
||||
|
||||
@Test func nonFiniteControlsProduceFiniteOutput() throws {
|
||||
// NaN control reads must be sanitised (not trap the seconds→frames conversion nor poison
|
||||
// the feedback): the output must stay finite.
|
||||
let samples: [Float] = try render(
|
||||
oscFreq: 440.0, dc: 0.0, size: Double.nan, decay: Double.nan, shimmer: Double.nan
|
||||
)
|
||||
#expect(samples.allSatisfy { $0.isFinite }, "non-finite controls produced NaN/inf output")
|
||||
}
|
||||
|
||||
@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).
|
||||
|
||||
Reference in New Issue
Block a user