add scope for debugging

This commit is contained in:
2026-06-22 21:07:13 -07:00
parent c6f567535b
commit ed27ab166c
8 changed files with 156 additions and 1 deletions
@@ -53,5 +53,56 @@ extension ShoeGaze {
}
try rebuildAllBoards(from: snapshot)
// The tapped bus indices depend on the channel layout (input buses follow the output
// buses), so rebuild the scope tap for the new configuration.
installScopeTap()
}
/// Default samples-per-frame captured by the scope tap.
public static let defaultScopeBufferSize: Int = 2_048
/// (Re)builds the ``scopeTap`` over the current hardware input + output buses and assigns it
/// to the engine, so the debug scope view can visualise both the live input signal and the
/// board output.
///
/// Lane order is **inputs first** (`In 0`, `In 1`, …) then **outputs** (`Out L`, `Out R`, …),
/// so the input waveform sits at the top of the scope. Must be called while the engine is
/// stopped — `SynthesisEngine` caches its scope tap at `start()`. Rebuilt automatically by
/// ``reconfigureEngine(sampleRate:inputChannels:outputChannels:)`` and at init.
///
/// - Parameter bufferSize: Samples per channel per display frame. Defaults to 2048.
public func installScopeTap(bufferSize: Int = ShoeGaze.defaultScopeBufferSize) {
let numOut: Int = engine.numOutputChannels
let numIn: Int = engine.numInputChannels
var buses: [Int] = []
for ch: Int in 0..<numIn { buses.append(numOut + ch) } // hardware inputs (top lanes)
for ch: Int in 0..<numOut { buses.append(ch) } // outputs (lower lanes)
guard !buses.isEmpty else {
engine.scopeTap = nil
scopeTap = nil
return
}
let capture: ScopeCapture = ScopeCapture(buses: buses, bufferSize: bufferSize)
engine.scopeTap = capture
scopeTap = capture
}
/// Human-readable label for a tapped audio-bus index under the current engine layout.
///
/// Output buses (`bus < numOutputChannels`) are `Out L` / `Out R` / `Out N`; the remaining
/// buses are hardware inputs `In 0`, `In 1`, … Used by the scope view to label each lane.
///
/// - Parameter bus: An audio-bus index, typically one of ``scopeTap``'s `buses`.
public func scopeLaneLabel(forBus bus: Int) -> String {
let numOut: Int = engine.numOutputChannels
guard bus >= numOut else {
let stereoNames: [String] = ["Out L", "Out R"]
return bus < stereoNames.count ? stereoNames[bus] : "Out \(bus)"
}
return "In \(bus - numOut)"
}
}