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.7 KiB
Swift
66 lines
2.7 KiB
Swift
// HardwareInputPassThrough.swift
|
||
// Lyrebird
|
||
//
|
||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||
// SPDX-License-Identifier: MIT
|
||
|
||
import LyrebirdSynth
|
||
import LyrebirdUI
|
||
|
||
/// Internal synthesizer that copies one hardware input bus to a board head bus.
|
||
///
|
||
/// When `ShoeGaze` is configured with `.liveInput`, a `HardwareInputPassThrough` is
|
||
/// added to the engine before the first pedal. It reads the hardware input bus at
|
||
/// `inputBusIndex` and writes its samples to the board's head bus at `outputBusIndex`.
|
||
/// This ensures the first pedal reads from a user-space bus that the board controls,
|
||
/// rather than from the raw hardware input bus directly.
|
||
///
|
||
/// - Note: The synthesizer must be removed from the engine before the board's
|
||
/// `teardown()` releases the head bus back to the allocator.
|
||
final class HardwareInputPassThrough: SynthesizerBase {
|
||
|
||
// MARK: - Parameters
|
||
|
||
/// Input mute — `0` = audible, `1` = muted (a hard gate on the incoming signal, distinct from
|
||
/// the rig-output mute). 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 (e.g. `ChainRouter`) 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 hardware input bus to read from (typically `engine.numOutputChannels`).
|
||
private let inputBusIndex: Int
|
||
|
||
/// Index of the board head bus to write to.
|
||
private let outputBusIndex: Int
|
||
|
||
// MARK: - Init
|
||
|
||
/// Creates a pass-through that copies `inputBusIndex` to `outputBusIndex`.
|
||
///
|
||
/// - Parameters:
|
||
/// - inputBusIndex: Hardware input bus index to read from.
|
||
/// Typically `engine.numOutputChannels` for the first input channel.
|
||
/// - 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)
|
||
}
|
||
}
|