53 lines
2.1 KiB
Swift
53 lines
2.1 KiB
Swift
// InputSource.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import LyrebirdSynth
|
|
|
|
/// Selects how the pedalboard's head bus is fed with audio.
|
|
///
|
|
/// - `.testLoop`: A synthesized test tone (`TestLoopSource`) writes to the head bus.
|
|
/// Suitable for testing the pedalboard with no hardware connected.
|
|
/// - `.liveInput(channel:)`: A hardware input channel feeds the head bus. `channel` is
|
|
/// the zero-based hardware input channel index (`0` = first input). It maps to engine
|
|
/// audio-bus index `numOutputChannels + channel` (hardware input buses follow the
|
|
/// output buses). Requires the engine to be created with `numInputChannels > channel`.
|
|
public enum InputSource {
|
|
/// Synthesized test signal — no hardware required.
|
|
case testLoop
|
|
/// Live hardware input from the given zero-based input channel. The engine must be
|
|
/// created with `numInputChannels > channel`.
|
|
case liveInput(channel: Int)
|
|
}
|
|
|
|
/// Validates a `.liveInput` channel against the engine and returns the engine audio-bus
|
|
/// index of that hardware input channel.
|
|
///
|
|
/// Hardware input buses occupy indices `numOutputChannels ..< (numOutputChannels +
|
|
/// numInputChannels)`, so input channel `channel` lives at `numOutputChannels + channel`.
|
|
///
|
|
/// - Parameters:
|
|
/// - channel: Zero-based hardware input channel index.
|
|
/// - engine: The engine whose bus layout is queried.
|
|
/// - Returns: The audio-bus index to read the requested input channel from.
|
|
/// - Throws:
|
|
/// - `ShoeGazeError.liveInputRequiresInputChannels` if the engine has no input channels.
|
|
/// - `ShoeGazeError.inputChannelOutOfRange` if `channel` is negative or `>= numInputChannels`.
|
|
internal func liveInputBusIndex(
|
|
channel: Int,
|
|
engine: SynthesisEngine
|
|
) throws -> Int {
|
|
guard engine.numInputChannels > 0 else {
|
|
throw ShoeGazeError.liveInputRequiresInputChannels
|
|
}
|
|
guard channel >= 0, channel < engine.numInputChannels else {
|
|
throw ShoeGazeError.inputChannelOutOfRange(
|
|
requested: channel,
|
|
available: engine.numInputChannels
|
|
)
|
|
}
|
|
return engine.numOutputChannels + channel
|
|
}
|