diff --git a/Sources/LyrebirdShoeGaze/Pedals/AmpVoicePedal.swift b/Sources/LyrebirdShoeGaze/Pedals/AmpVoicePedal.swift index 80b33fe..2a57350 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/AmpVoicePedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/AmpVoicePedal.swift @@ -350,7 +350,10 @@ open class AmpVoicePedal: Pedal { /// > low-pass) — expected; a cabinet is what tames the top end. var isCabinetBypassed: Bool { guard cab.isFinite else { return false } - return Int(cab.rounded()) >= CabinetVoice.allCases.count + // Clamp in Double space before converting: a huge finite `cab` (from a corrupted/hand-edited + // rig) would otherwise trap `Int(_:)` — same defense as `CabinetVoice.voice(atSelectorValue:)`. + let bounded: Double = Swift.min(Swift.max(cab, 0.0), Double(CabinetVoice.allCases.count)) + return Int(bounded.rounded()) >= CabinetVoice.allCases.count } /// The per-channel cabinet + output stage: cabinet convolver (or a straight pass at the "None" diff --git a/Tests/LyrebirdShoeGazeTests/AmpVoicePedalTests.swift b/Tests/LyrebirdShoeGazeTests/AmpVoicePedalTests.swift index 15ea966..7070ebe 100644 --- a/Tests/LyrebirdShoeGazeTests/AmpVoicePedalTests.swift +++ b/Tests/LyrebirdShoeGazeTests/AmpVoicePedalTests.swift @@ -285,6 +285,16 @@ struct AmpVoicePedalTests { } } + @Test func extremeCabValuesDoNotTrap() throws { + // A corrupted/hand-edited rig can restore any Double into `cab`. Neither the bypass check nor + // the voice lookup may trap `Int(_:)` — every value must resolve to a defined, finite render. + let extremes: [Double] = [.infinity, -.infinity, 1.0e20, -1.0e20, .nan, 999.0] + for cabValue: Double in extremes { + let out: [Float] = try render({ CaliforniaAmpPedal() }) { $0.cab = cabValue } + #expect(out.allSatisfy { $0.isFinite }, "cab=\(cabValue) produced non-finite output") + } + } + @Test func cabSelectorExposesNoneStop() throws { let stops: [PedalSelectorKnob.Stop] = CaliforniaAmpPedal().effectSelectors .first { $0.label == "Cab" }?.stops ?? []