diff --git a/Sources/LyrebirdShoeGaze/Pedals/TunedVerbPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/TunedVerbPedal.swift index 569a448..44b6556 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/TunedVerbPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/TunedVerbPedal.swift @@ -196,9 +196,18 @@ public final class TunedVerbPedal: Pedal { stages: [.dual(map, sideChain: sideChain)] ) + // Gate the wash by the Capture latch. Until a moment is captured there is no filter template, + // so the reverb must be fed silence rather than the live pass-through — otherwise an + // uncaptured TunedVerb pours the dry signal straight into the tail. `captured` is `0` until the + // footswitch fires and is reset to `0` on every rebuild and on engine stop (`resetForRebuild` + // / `releaseHold`), so a fresh app launch or an engine restart comes up silent with no stale + // capture. The analysis side-chain inside `masked` keeps tracking while gated, so pressing + // Capture still freezes the current-moment spectrum. + let gatedIntoVerb: any ValidGeneratorInput = masked * $captured + // A large room for a cavernous tail; `time` sets the T60, `damp` the brightness. let reverb: GVerb.Audio = GVerb.Audio( - source: masked, + source: gatedIntoVerb, roomSize: roomSize, reverbTime: $time, damping: $damp, diff --git a/Tests/LyrebirdShoeGazeTests/TunedVerbPedalTests.swift b/Tests/LyrebirdShoeGazeTests/TunedVerbPedalTests.swift index 8b89d04..fa4ae1b 100644 --- a/Tests/LyrebirdShoeGazeTests/TunedVerbPedalTests.swift +++ b/Tests/LyrebirdShoeGazeTests/TunedVerbPedalTests.swift @@ -188,47 +188,87 @@ struct TunedVerbPedalTests { } @Test func panShiftsTheLeftLeg() throws { - // Fully wet, the output follows the panned wash. Hard left fills the left leg; hard right - // nearly empties it. (Tests exercise the left output leg; the right is board-wired live.) - let hardLeft: [Float] = try render(duration: 0.6) { pedal in pedal.mix = 1.0; pedal.pan = -1.0 } - let hardRight: [Float] = try render(duration: 0.6) { pedal in pedal.mix = 1.0; pedal.pan = 1.0 } - let leftRMS: Double = rms(hardLeft, loFrame: 0, hiFrame: hardLeft.count) - let rightRMS: Double = rms(hardRight, loFrame: 0, hiFrame: hardRight.count) + // Fully wet, the output follows the panned wash — but the wash only exists after a capture, so + // capture early, then measure. Hard left fills the left leg; hard right nearly empties it. + // (`stepRender` returns the left output bus; the right is board-wired live.) + let blockSize: Int = 512 + let totalFrames: Int = Int(0.8 * sampleRate) + let captureFrame: Int = Int(0.1 * sampleRate) + let windowLo: Int = Int(0.4 * sampleRate) + + func leftLeg(pan: Double) throws -> [Float] { + var captured: Bool = false + return try stepRender(totalFrames: totalFrames, blockSize: blockSize) { pedal in + pedal.mix = 1.0; pedal.pan = pan; pedal.time = 2.0 + } onFrame: { frame, _, pedal in + if frame >= captureFrame, !captured { pedal.toggleCapture(); captured = true } + } + } + + let hardLeft: [Float] = try leftLeg(pan: -1.0) + let hardRight: [Float] = try leftLeg(pan: 1.0) + let leftRMS: Double = rms(hardLeft, loFrame: windowLo, hiFrame: hardLeft.count) + let rightRMS: Double = rms(hardRight, loFrame: windowLo, hiFrame: hardRight.count) #expect(leftRMS > rightRMS * 3.0, "panning hard left should fill the left leg far more than hard right: L \(leftRMS) vs R \(rightRMS)") } - @Test func captureLocksTheFilterSoAChangedInputIsShapedDifferently() throws { - // Capture the filter on tone A, then morph the input to tone B. A locked filter (shaped by A) - // masks B differently than a filter that keeps tracking the live input — so the two renders - // diverge once the input has changed. + @Test func wetIsSilentUntilCaptureThenAudible() throws { + // Core contract: with no captured moment there is no filter template, so a fully-wet TunedVerb + // must output silence — not the live pass-through poured into the reverb. After the Capture + // footswitch fires, the wash appears. Fully wet (mix 1.0) so the only output is the gated wash. + let blockSize: Int = 512 + let totalFrames: Int = Int(1.4 * sampleRate) + let captureFrame: Int = Int(0.5 * sampleRate) + + var captured: Bool = false + let out: [Float] = try stepRender(totalFrames: totalFrames, blockSize: blockSize) { pedal in + pedal.mix = 1.0; pedal.time = 1.0 + } onFrame: { frame, _, pedal in + if frame >= captureFrame, !captured { pedal.toggleCapture(); captured = true } + } + + // Before capture: fully-wet output must be silent (reverb fed zero). + let preRMS: Double = rms(out, loFrame: 0, hiFrame: captureFrame - blockSize) + // Well after capture (give the reverb time to build): audible. + let postRMS: Double = rms(out, loFrame: captureFrame + Int(0.4 * sampleRate), hiFrame: out.count) + #expect(preRMS < 1.0e-6, "an uncaptured fully-wet TunedVerb must be silent, got \(preRMS)") + #expect(postRMS > 1.0e-4, "after Capture the wash must be audible, got \(postRMS)") + } + + @Test func captureLocksTheFilterSoAChangedInputIsShapedDifferently() throws { + // Which moment you capture determines the filter. Capture on tone A then morph to B (the wash + // on B is shaped by A's spectrum) versus morph to B first then capture on B (shaped by B's own + // spectrum). Both are audible — the wash exists only after a capture — but the two locked + // templates mask the ongoing tone-B input differently, so the renders diverge. let blockSize: Int = 512 let totalFrames: Int = Int(1.4 * sampleRate) - let captureFrame: Int = Int(0.4 * sampleRate) - let morphFrame: Int = Int(0.6 * sampleRate) let windowLo: Int = Int(0.95 * sampleRate) let windowHi: Int = Int(1.35 * sampleRate) - var captured: Bool = false - let locked: [Float] = try stepRender(totalFrames: totalFrames, blockSize: blockSize) { pedal in + // Locked on tone A, then morphed to B. + var capturedA: Bool = false + let lockedOnA: [Float] = try stepRender(totalFrames: totalFrames, blockSize: blockSize) { pedal in pedal.mix = 1.0; pedal.time = 3.0 } onFrame: { frame, source, pedal in - if frame >= captureFrame, !captured { pedal.toggleCapture(); captured = true } - if frame >= morphFrame { source.morph = 1.0 } // switch to tone B + if frame >= Int(0.4 * sampleRate), !capturedA { pedal.toggleCapture(); capturedA = true } + if frame >= Int(0.6 * sampleRate) { source.morph = 1.0 } // switch to tone B after capture } - let tracking: [Float] = try stepRender(totalFrames: totalFrames, blockSize: blockSize) { pedal in + // Morphed to B first, then locked on B. + var capturedB: Bool = false + let lockedOnB: [Float] = try stepRender(totalFrames: totalFrames, blockSize: blockSize) { pedal in pedal.mix = 1.0; pedal.time = 3.0 - } onFrame: { frame, source, _ in - // Never capture; morph at the same frame. - if frame >= morphFrame { source.morph = 1.0 } + } onFrame: { frame, source, pedal in + if frame >= Int(0.2 * sampleRate) { source.morph = 1.0 } // switch to tone B first + if frame >= Int(0.4 * sampleRate), !capturedB { pedal.toggleCapture(); capturedB = true } } - let signal: Double = rms(tracking, loFrame: windowLo, hiFrame: windowHi) - let diff: Double = rmsDiff(locked, tracking, loFrame: windowLo, hiFrame: windowHi) - #expect(signal > 1.0e-4, "control render should be audible on tone B, got \(signal)") + let signal: Double = rms(lockedOnB, loFrame: windowLo, hiFrame: windowHi) + let diff: Double = rmsDiff(lockedOnA, lockedOnB, loFrame: windowLo, hiFrame: windowHi) + #expect(signal > 1.0e-4, "a captured render should be audible on tone B, got \(signal)") #expect(diff > signal * 0.25, - "a captured filter should shape the changed input differently: diff \(diff) vs signal \(signal)") + "locking a different moment should shape the input differently: diff \(diff) vs signal \(signal)") } // MARK: - Bypass