Review fix: exact-silence input mute (hard kill-switch gate)

External review found the lagged mute gate leaks a faint transient (~-54 dB) on
its first blocks: Lag seeds its state at 0, so gating on a lagged value never
starts at exactly zero on a rig that comes up muted — the moment the mute is
meant to keep things quiet. Measured directly via an NRT render.

- Gate the input with a hard, un-lagged kill switch `(inputMute - 1) * -1` in
  both HardwareInputPassThrough and TestLoopTap. A muted node is then exactly
  silent from the first sample; a kill-switch mute is expected to be abrupt.
  Drop the now-unused muteLagTime constant.
- Flip the library default to `inputMuted = false` (audible). Muting is the app's
  Start-time policy (EngineConfigView already re-asserts muted on user Start), so
  headless/offline library use isn't forced silent and render tests that route the
  test-loop through a board no longer depend on a leak to see signal. The pulsing
  glow now also starts at engine Start rather than before it.
- Tests: add render-level mutedInputRendersSilent (exact silence) and
  unmutedInputRendersSignal; update the default-state and MIDI-latch expectations;
  drop the StereoRouting un-mutes that the leak had made necessary.
- Plan doc: correct the mute default / gate description and the UserDefaults note.

463 tests pass; both app targets build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-11 16:03:50 -07:00
parent be0e3d118b
commit b29c8848ef
7 changed files with 89 additions and 48 deletions
@@ -16,9 +16,9 @@ import LyrebirdUI
@Suite("InputMute")
struct InputMuteTests {
/// A fresh session defaults to input-muted, and every board's input writer comes up muted so a
/// just-started engine is silent until the player un-mutes.
@Test func defaultsMutedAndDrivesInputNodes() throws {
/// A fresh session defaults audible at the library level (the app mutes on engine Start), and
/// muting drives every board's input writer to the silent gain.
@Test func defaultsAudibleThenMuteDrivesInputNodes() 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)
@@ -28,10 +28,14 @@ struct InputMuteTests {
try board.add(VolumePedal())
try sg.finalizeBoard(board)
#expect(sg.inputMuted)
#expect(!sg.inputMuted)
let audible: Double = 0.0
#expect(sg.inputMuteNodeValues.allSatisfy { $0 == audible })
#expect(!sg.inputMuteNodeValues.isEmpty)
sg.setInputMuted(true)
let muted: Double = 1.0
#expect(sg.inputMuteNodeValues.allSatisfy { $0 == muted })
#expect(!sg.inputMuteNodeValues.isEmpty)
}
}
@@ -82,7 +86,47 @@ struct InputMuteTests {
}
}
/// The live-input pass-through path is driven identically to the test-loop tap path.
/// A muted input renders **exactly** silent through a full render — the kill-switch gate reaches
/// zero with no residual. A lagged gate leaked a faint transient on its first blocks; the hard
/// gate does not.
@Test func mutedInputRendersSilent() throws {
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.25, numAudioBuses: 256)
defer { try? FileManager.default.removeItem(at: url) }
let sg: ShoeGaze = ShoeGaze(engine: engine) // input defaults muted
try withExtendedLifetime(sg) {
let board: PedalBoard = try sg.addBoard()
try board.add(VolumePedal())
try sg.finalizeBoard(board)
sg.setInputMuted(true)
try engine.start()
let samples: [Float] = readStereoCAF(url: url)
#expect(!hasNonSilentOutput(samples),
"a muted input must render silent — the kill-switch gate leaves no residual")
}
}
/// 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)
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)
sg.setInputMuted(false)
try engine.start()
let samples: [Float] = readStereoCAF(url: url)
#expect(hasNonSilentOutput(samples),
"an un-muted input must pass the test-loop signal through")
}
}
/// The live-input pass-through path is driven by `setInputMuted` identically to the test-loop tap.
@Test func liveInputPassThroughIsMuted() throws {
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
duration: 0.05,
@@ -98,8 +142,12 @@ struct InputMuteTests {
try board.add(VolumePedal())
try sg.finalizeBoard(board)
let audible: Double = 0.0
#expect(!sg.inputMuted)
#expect(sg.inputMuteNodeValues == [audible])
sg.setInputMuted(true)
let muted: Double = 1.0
#expect(sg.inputMuted)
#expect(sg.inputMuteNodeValues == [muted])
}
}