fix(tunedverb): silence the wash until a moment is captured

An uncaptured TunedVerb has no filter template, so it must output silence —
but the live cross-map was pouring the dry pass-through straight into the
reverb, so every TunedVerb hummed on startup (and looked like a stale
capture surviving a restart). Gate the reverb input by the Capture latch:
`masked * $captured` feeds the reverb zero until the footswitch fires.

Because `captured` is 0 by default, reset to 0 on every graph rebuild
(resetForRebuild) and on engine stop (engineDidStop -> releaseHold), the
same gate also guarantees a fresh app launch or engine restart comes up
silent with no carried-over capture. The analysis side-chain keeps tracking
while gated, so pressing Capture still freezes the current-moment spectrum.

FreezVerb is unaffected: its Freeze holds a working reverb's tail, so it
should produce sound before freezing.

Tests: new wetIsSilentUntilCaptureThenAudible; panShiftsTheLeftLeg and
captureLocksTheFilter... updated to the new contract (capture before
measuring the wash). 856 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 14:02:47 -08:00
parent 24ac361c48
commit 4cae1e6fd0
2 changed files with 74 additions and 25 deletions
@@ -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,
@@ -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