b29c8848ef
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>
155 lines
5.9 KiB
Swift
155 lines
5.9 KiB
Swift
// InputMuteTests.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Testing
|
|
import Foundation
|
|
import LyrebirdSynth
|
|
import LyrebirdUI
|
|
@testable import LyrebirdShoeGaze
|
|
|
|
/// Tests for the input mute — the hard gate on the signal feeding every board, distinct from the
|
|
/// rig-output mute.
|
|
@MainActor
|
|
@Suite("InputMute")
|
|
struct InputMuteTests {
|
|
|
|
/// 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)
|
|
|
|
try withExtendedLifetime(sg) {
|
|
let board: PedalBoard = try sg.addBoard()
|
|
try board.add(VolumePedal())
|
|
try sg.finalizeBoard(board)
|
|
|
|
#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 })
|
|
}
|
|
}
|
|
|
|
/// `setInputMuted(false)` un-mutes every input node and clears the flag; re-muting restores it.
|
|
@Test func setInputMutedDrivesAllNodes() 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)
|
|
|
|
sg.setInputMuted(false)
|
|
#expect(!sg.inputMuted)
|
|
let audible: Double = 0.0
|
|
#expect(sg.inputMuteNodeValues.allSatisfy { $0 == audible })
|
|
|
|
sg.toggleInputMuted()
|
|
#expect(sg.inputMuted)
|
|
let muted: Double = 1.0
|
|
#expect(sg.inputMuteNodeValues.allSatisfy { $0 == muted })
|
|
}
|
|
}
|
|
|
|
/// A board added while the input is un-muted comes up audible — the current mute state is
|
|
/// applied to newly-wired input nodes, not just the ones present when the toggle flipped.
|
|
@Test func newBoardAdoptsCurrentMuteState() 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 first: PedalBoard = try sg.addBoard()
|
|
try first.add(VolumePedal())
|
|
try sg.finalizeBoard(first)
|
|
|
|
sg.setInputMuted(false)
|
|
|
|
let second: PedalBoard = try sg.addBoard()
|
|
try second.add(VolumePedal())
|
|
try sg.finalizeBoard(second)
|
|
|
|
let audible: Double = 0.0
|
|
#expect(sg.inputMuteNodeValues.count == 2)
|
|
#expect(sg.inputMuteNodeValues.allSatisfy { $0 == audible })
|
|
}
|
|
}
|
|
|
|
/// 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,
|
|
numOutputChannels: 2,
|
|
numInputChannels: 1,
|
|
numAudioBuses: 256
|
|
)
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
let sg: ShoeGaze = ShoeGaze(engine: engine, inputSource: .liveInput(channel: 0))
|
|
|
|
try withExtendedLifetime(sg) {
|
|
let board: PedalBoard = try sg.addBoard()
|
|
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.inputMuteNodeValues == [muted])
|
|
}
|
|
}
|
|
}
|