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:
@@ -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])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,18 +85,18 @@ struct MIDIControllerPCTests {
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
withExtendedLifetime(sg) {
|
||||
// A fresh session starts input-muted by default.
|
||||
#expect(sg.inputMuted == true, "input defaults muted")
|
||||
// A fresh library session starts audible (the app mutes on engine Start).
|
||||
#expect(sg.inputMuted == false, "input defaults audible at the library level")
|
||||
|
||||
controller.armSwitchLearn(.inputMute)
|
||||
controller.ingestForTesting(.programChange(channel: 0, program: 2)) // learn only
|
||||
#expect(sg.inputMuted == true, "learn must not toggle")
|
||||
#expect(sg.inputMuted == false, "learn must not toggle")
|
||||
|
||||
controller.ingestForTesting(.programChange(channel: 0, program: 2))
|
||||
#expect(sg.inputMuted == false, "first press un-mutes the input")
|
||||
#expect(sg.inputMuted == true, "first press mutes the input")
|
||||
#expect(sg.rigMuted == false, "input mute must not touch the rig-output mute")
|
||||
controller.ingestForTesting(.programChange(channel: 0, program: 2))
|
||||
#expect(sg.inputMuted == true, "second press re-mutes the input")
|
||||
#expect(sg.inputMuted == false, "second press un-mutes the input")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,6 @@ struct StereoRoutingTests {
|
||||
#expect(board.outputBusRight != nil, "Stereo board should have a right tail bus")
|
||||
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
shoeGaze.setInputMuted(false) // input defaults muted; un-mute so the test-loop signal renders
|
||||
try engine.start()
|
||||
|
||||
let samples: [Float] = readStereoCAF(url: url)
|
||||
@@ -104,7 +103,6 @@ struct StereoRoutingTests {
|
||||
#expect(delay.outputBusRight != nil, "Auto-stereoized pedal should have a right output bus")
|
||||
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
shoeGaze.setInputMuted(false) // input defaults muted; un-mute so the test-loop signal renders
|
||||
try engine.start()
|
||||
|
||||
let samples: [Float] = readStereoCAF(url: url)
|
||||
@@ -130,7 +128,6 @@ struct StereoRoutingTests {
|
||||
#expect(board.width == 2, "Stereo-native pedal should widen a mono board")
|
||||
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
shoeGaze.setInputMuted(false) // input defaults muted; un-mute so the test-loop signal renders
|
||||
try engine.start()
|
||||
|
||||
let samples: [Float] = readStereoCAF(url: url)
|
||||
@@ -159,7 +156,6 @@ struct StereoRoutingTests {
|
||||
|
||||
try board.add(ReverbPedal()) // mono pedal after merge, width-1
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
shoeGaze.setInputMuted(false) // input defaults muted; un-mute so the test-loop signal renders
|
||||
try engine.start()
|
||||
|
||||
let samples: [Float] = readStereoCAF(url: url)
|
||||
@@ -207,7 +203,6 @@ struct StereoRoutingTests {
|
||||
#expect(board.width == 2, "collectStereo should make the board stereo")
|
||||
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
shoeGaze.setInputMuted(false) // input defaults muted; un-mute so the test-loop signal renders
|
||||
try engine.start()
|
||||
|
||||
return deinterleave(readStereoCAF(url: url))
|
||||
@@ -297,7 +292,6 @@ struct StereoRoutingTests {
|
||||
#expect(board.outputBusRight == nil)
|
||||
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
shoeGaze.setInputMuted(false) // input defaults muted; un-mute so the test-loop signal renders
|
||||
try engine.start()
|
||||
|
||||
let samples: [Float] = readStereoCAF(url: url)
|
||||
|
||||
Reference in New Issue
Block a user