Review fix: prime input-mute ramp + mute before engine start

Two blocking findings from external review:

1. UIParamNode itself ramps from previousOutputValue (seeded at the compile-time
   default, advanced only by RT render — update() doesn't touch it) to the target
   over the first block. So a node told to start muted still ramped full-gain→0
   across block 0; the earlier "hard gate" only moved the leak from Lag to the
   param's own ramp. The mutedInputRendersSilent test passed by accident (the
   test-loop tone is quiet in that first block).
   Fix: prime previousOutputValue to the target. Race-free before a node is
   spliced into the graph (addBoard) and safe on a spliced node while the engine
   is stopped; a running engine keeps the ramp as a click-free live toggle. New
   setInputMuteGain(_:muted:seedRamp:) / primeInputMute helpers; setInputMuted
   seeds only when engine.isRunning == false.

2. EngineConfigView.startEngine called setInputMuted(true) AFTER engine.start(),
   so the engine came up unmuted for the first blocks. Moved it before start()
   (engine stopped there, so the gain is seeded with no ramp).

Also: correct the setInputMuted doc (abrupt kill-switch, not "smoothed").
Regression test stoppedMutePrimesNodesSoTheresNoStartRamp asserts the ramp start
equals the target (no pending ramp) after a stopped mute and for a board added
while muted. 464 tests pass; both app targets build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-11 21:34:46 -07:00
parent b29c8848ef
commit e36074e9d3
3 changed files with 80 additions and 10 deletions
@@ -107,6 +107,41 @@ struct InputMuteTests {
}
}
/// Muting while the engine is stopped **primes** every input node — its ramp start (`previous
/// OutputValue`) equals the muted target — so the next Start renders muted from block zero with no
/// audible→muted ramp. Guards against the `UIParamNode` one-block ramp leaking a fresh node's
/// prior (audible) value. A freshly-added board is primed the same way.
@Test func stoppedMutePrimesNodesSoTheresNoStartRamp() throws {
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.05, numAudioBuses: 256)
defer { try? FileManager.default.removeItem(at: url) }
let sg: ShoeGaze = ShoeGaze(engine: engine)
try withExtendedLifetime(sg) {
let board: PedalBoard = try sg.addBoard()
try board.add(VolumePedal())
try sg.finalizeBoard(board)
// Default audible: node value and ramp start both at 0 (no pending ramp).
let audible: Double = 0.0
#expect(sg.inputMuteNodeValues.allSatisfy { $0 == audible })
#expect(sg.inputMutePreviousValues.allSatisfy { $0 == audible })
// Mute while stopped: both the target and the ramp start move to 1 → no leak on Start.
sg.setInputMuted(true)
let muted: Double = 1.0
#expect(sg.inputMuteNodeValues.allSatisfy { $0 == muted })
#expect(sg.inputMutePreviousValues.allSatisfy { $0 == muted },
"a stopped-engine mute must prime the ramp start so the first render can't ramp")
// A board added while muted comes up primed muted too.
let second: PedalBoard = try sg.addBoard()
try second.add(VolumePedal())
try sg.finalizeBoard(second)
#expect(sg.inputMutePreviousValues.allSatisfy { $0 == muted })
#expect(sg.inputMuteNodeValues.count == 2)
}
}
/// Un-muting the input lets the test-loop signal through — the gate opens fully.
@Test func unmutedInputRendersSignal() throws {
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.25, numAudioBuses: 256)