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>
66 lines
2.6 KiB
Swift
66 lines
2.6 KiB
Swift
// TestLoopTap.swift
|
||
// Lyrebird
|
||
//
|
||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||
// SPDX-License-Identifier: MIT
|
||
|
||
import LyrebirdSynth
|
||
import LyrebirdUI
|
||
|
||
/// Internal synthesizer that copies the shared global test-loop bus to a board head bus.
|
||
///
|
||
/// In `.testLoop` mode every board reads the **same** global ``TestLoopSource`` (so all boards
|
||
/// stay phase-locked instead of each running an independently-phased arpeggio). A `TestLoopTap`
|
||
/// per board reads the global test bus at `inputBusIndex` and writes it to the board's head bus
|
||
/// at `outputBusIndex`, so the first pedal still reads from a board-owned bus.
|
||
///
|
||
/// Added `.after(_:)` the global source so it evaluates once the source has written the test bus
|
||
/// for the current block.
|
||
///
|
||
/// - Note: Must be removed from the engine before the board's `teardown()` releases the head bus.
|
||
final class TestLoopTap: SynthesizerBase {
|
||
|
||
// MARK: - Parameters
|
||
|
||
/// Input mute — `0` = audible, `1` = muted. Driven across every board input node by
|
||
/// `ShoeGaze.setInputMuted(_:)`, which sets a newly-added node to the session's current mute
|
||
/// state. Defaults audible so direct users that don't drive the mute pass the signal through.
|
||
@UIParam var inputMute: Double = 0.0
|
||
|
||
/// The live `UIParamNode` backing `inputMute`, driven by `ShoeGaze.setInputMuted(_:)`.
|
||
var inputMuteNode: UIParamNode { $inputMute }
|
||
|
||
// MARK: - Routing
|
||
|
||
/// Index of the shared global test-loop bus to read from.
|
||
private let inputBusIndex: Int
|
||
|
||
/// Index of the board head bus to write to.
|
||
private let outputBusIndex: Int
|
||
|
||
// MARK: - Init
|
||
|
||
/// Creates a tap that copies `inputBusIndex` (the global test bus) to `outputBusIndex`
|
||
/// (a board head bus).
|
||
///
|
||
/// - Parameters:
|
||
/// - inputBusIndex: Shared global test-loop bus index to read from.
|
||
/// - outputBusIndex: Board head bus index to write to.
|
||
init(inputBusIndex: Int, outputBusIndex: Int) {
|
||
self.inputBusIndex = inputBusIndex
|
||
self.outputBusIndex = outputBusIndex
|
||
super.init()
|
||
}
|
||
|
||
// MARK: - Build
|
||
|
||
override func build() {
|
||
// Hard kill-switch gate: `1 − inputMute`, so mute 0 → gain 1 (audible), 1 → gain 0 (exactly
|
||
// silent). Unlagged on purpose — a lagged gate never settles to exactly zero on its first
|
||
// blocks and leaks a faint transient right when the mute is meant to keep things quiet; a
|
||
// kill-switch mute is expected to be abrupt anyway.
|
||
let muteGain: any ValidGeneratorInput = ($inputMute - 1.0) * -1.0
|
||
output(bus: outputBusIndex, source: input(bus: inputBusIndex) * muteGain)
|
||
}
|
||
}
|