4a5d4009f6
First amp-modeling increment (ShoeGaze 2.0, plan S1). No Lyrebird change — reuses ConvolutionReverb + LyrebirdBuffer. - CabinetPedal: builds one ConvolutionReverb per built-in voice at build() time and picks the active one with a `Select` driven by the persisted `cabinet` selector — live cab switching that round-trips through the rig save format. - CabinetVoice + CabinetIRFactory: three built-in voicings synthesized in code (impulse through an RBJ biquad cascade — HP, true 4th-order Butterworth LP, body + presence peaks), so the bundled cab set is our own MIT content (no third-party IR licensing). Filter centre frequencies are Nyquist-clamped. - Registered in PedalRegistry / PedalType / PedalCategory (.filter) / palette; README pedal count + catalog updated. User-supplied captured .wav cab IRs are a planned follow-up (needs a persisted file-path field PedalState doesn't yet carry). Tests: IR is finite, peak-normalized, mono; rolls off lows and highs; voices differ; selector exposed; selection changes output and round-trips through PedalState; pedal builds, non-silent, resolves from the registry. Suite 486. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
113 lines
4.3 KiB
Swift
113 lines
4.3 KiB
Swift
// CabinetPedal.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import LyrebirdSynth
|
|
import LyrebirdUI
|
|
|
|
/// Speaker-cabinet simulation via impulse-response convolution.
|
|
///
|
|
/// Convolves the input against a cabinet impulse response using Lyrebird's partitioned FFT
|
|
/// convolver (`ConvolutionReverb`). One convolver per built-in ``CabinetVoice`` is built at
|
|
/// `build()` time (each voicing's IR is synthesized in code — our own MIT content, see
|
|
/// ``CabinetIRFactory``); a `Select` driven by the ``cabinet`` knob picks the active one, so
|
|
/// switching cabs is live and round-trips through the rig save format like every other pedal.
|
|
///
|
|
/// Signal path (inside `effect(_:)`):
|
|
/// ```
|
|
/// dry → [ConvolutionReverb(ir: voice0), …] → Select(which: cabinet) → mono out
|
|
/// ```
|
|
///
|
|
/// The wet/dry mix and bypass are handled by the `Pedal` base class.
|
|
///
|
|
/// > Note: Loading a user-supplied captured `.wav` cab IR is a planned follow-up (it needs a
|
|
/// > persisted file-path field the current `PedalState` doesn't carry); this first version ships
|
|
/// > the built-in voicings only.
|
|
///
|
|
/// ## Parameters
|
|
///
|
|
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
|
///
|
|
/// - `cabinet`: Selects the built-in cabinet voicing (stepped selector over ``CabinetVoice``).
|
|
public final class CabinetPedal: Pedal {
|
|
|
|
/// One-line description shown in the picker and info panel.
|
|
public override var summary: String {
|
|
"Speaker-cabinet impulse-response convolution with selectable built-in voicings."
|
|
}
|
|
|
|
// MARK: - Parameters
|
|
|
|
/// Selected cabinet voicing as an index into ``CabinetVoice/allCases``. Snaps to integer
|
|
/// stops via the ``cabinet`` selector; read live by the `Select` in `effect(_:)`.
|
|
@UIParam public var cabinet: Double = 0.0
|
|
|
|
// MARK: - Constants
|
|
|
|
/// Default wet/dry blend — fully wet; the cabinet sits in-line.
|
|
private static let defaultMix: Double = 1.0
|
|
|
|
/// Convolution is taken fully wet here; the `Pedal` base class provides the user wet/dry mix.
|
|
private let convolutionMix: Double = 1.0
|
|
|
|
/// Selector stops, one per ``CabinetVoice`` in `allCases` order (value == index).
|
|
private static let voiceStops: [PedalSelectorKnob.Stop] = CabinetVoice.allCases
|
|
.enumerated()
|
|
.map { (index: Int, voice: CabinetVoice) in
|
|
PedalSelectorKnob.Stop(title: voice.displayName, value: Double(index))
|
|
}
|
|
|
|
// MARK: - Init
|
|
|
|
/// Creates a cabinet pedal.
|
|
///
|
|
/// - Parameters:
|
|
/// - inputBus: Audio bus index to read the dry input from. Defaults to `0`.
|
|
/// - outputBus: Audio bus index to write the processed output to. Defaults to `0`.
|
|
public init(
|
|
inputBus: Int = 0,
|
|
outputBus: Int = 0
|
|
) {
|
|
super.init(
|
|
name: "Cabinet",
|
|
inputBus: inputBus,
|
|
outputBus: outputBus,
|
|
initialMix: CabinetPedal.defaultMix
|
|
)
|
|
}
|
|
|
|
// MARK: - UI
|
|
|
|
public override var effectSelectors: [PedalSelectorKnob] {
|
|
[
|
|
PedalSelectorKnob(label: "Cab", node: $cabinet, stops: CabinetPedal.voiceStops),
|
|
]
|
|
}
|
|
|
|
// MARK: - Effect
|
|
|
|
/// Convolves the dry signal against every built-in cabinet IR and selects the active one.
|
|
///
|
|
/// All voices' convolvers are built at `build()` time; `Select` picks per the live `cabinet`
|
|
/// index each block. Every convolver keeps running (SC `Select` semantics), so their internal
|
|
/// state stays in sync across a switch — but the output changes on the switch sample, so a
|
|
/// hard cab change can click; cabs are normally set-and-forget, and a smooth crossfade is a
|
|
/// possible later refinement. Synthesizing the short IRs happens off the RT thread in `build()`.
|
|
///
|
|
/// - Parameter dry: Dry mono input signal.
|
|
/// - Returns: The cabinet-convolved mono output.
|
|
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
|
let sr: Double = sampleRate
|
|
let convolvers: [any ValidGeneratorInput] = CabinetVoice.allCases.map { (voice: CabinetVoice) in
|
|
ConvolutionReverb.Audio(
|
|
input: dry,
|
|
ir: CabinetIRFactory.makeIR(voice: voice, sampleRate: sr),
|
|
mix: convolutionMix
|
|
)
|
|
}
|
|
return Select.Audio(which: $cabinet, inputs: convolvers)
|
|
}
|
|
}
|