e36074e9d3
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>
190 lines
7.8 KiB
Swift
190 lines
7.8 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")
|
|
}
|
|
}
|
|
|
|
/// 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)
|
|
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])
|
|
}
|
|
}
|
|
}
|