perf(cab): instantiate only the selected cabinet convolver
The cab selector was a Select over one ConvolutionReverb per CabinetVoice, and Select evaluates every input each block — so all 8 voices' partitioned-FFT convolvers ran continuously (7/8 discarded), per CabinetPedal and per amp voice. Build only the selected voice's convolver. The cab selector is now rebuildsOnChange: committing a new stop asks the host to rebuild the board (same mechanism the Neural Amp model loader uses), which re-enters effect() with the new voice. One convolver runs instead of N; cost moves to a brief rebuild on cab switch (cabs are set-and-forget). - PedalSelectorKnob: add rebuildsOnChange flag. - PedalSelectorKnobView: fire onCommit on drag-end when the stop changed. - PedalView: wire onCommit → pedalRebuildAction for rebuildsOnChange selectors. - CabinetVoice.voice(atSelectorValue:): rounded/clamped index → voice. - CabinetPedal + AmpVoicePedal: single ConvolutionReverb for the selected voice. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -10,14 +10,15 @@ 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.
|
||||
/// convolver (`ConvolutionReverb`). A single convolver is built at `build()` time for the voice the
|
||||
/// ``cabinet`` selector currently names (each voicing's IR is synthesized in code — our own MIT
|
||||
/// content, see ``CabinetIRFactory``). Changing the selector asks the host to rebuild the board so
|
||||
/// only the selected voice's convolver ever runs — one partitioned-FFT convolver, not one per
|
||||
/// voice. The selection round-trips through the rig save format like every other pedal.
|
||||
///
|
||||
/// Signal path (inside `effect(_:)`):
|
||||
/// ```
|
||||
/// dry → [ConvolutionReverb(ir: voice0), …] → Select(which: cabinet) → mono out
|
||||
/// dry → ConvolutionReverb(ir: selectedVoice) → mono out
|
||||
/// ```
|
||||
///
|
||||
/// The wet/dry mix and bypass are handled by the `Pedal` base class.
|
||||
@@ -82,31 +83,30 @@ public final class CabinetPedal: Pedal {
|
||||
|
||||
public override var effectSelectors: [PedalSelectorKnob] {
|
||||
[
|
||||
PedalSelectorKnob(label: "Cab", node: $cabinet, stops: CabinetPedal.voiceStops),
|
||||
PedalSelectorKnob(
|
||||
label: "Cab", node: $cabinet, stops: CabinetPedal.voiceStops, rebuildsOnChange: true),
|
||||
]
|
||||
}
|
||||
|
||||
// MARK: - Effect
|
||||
|
||||
/// Convolves the dry signal against every built-in cabinet IR and selects the active one.
|
||||
/// Convolves the dry signal against the single selected cabinet IR.
|
||||
///
|
||||
/// 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()`.
|
||||
/// Only the voice named by the live `cabinet` selector is instantiated, so exactly one
|
||||
/// partitioned-FFT convolver runs. Changing the selector triggers a board rebuild (the selector
|
||||
/// is `rebuildsOnChange`), which re-enters `effect(_:)` with the new voice — so switching cabs
|
||||
/// costs a brief rebuild rather than running every voice at once. Synthesizing the short IR
|
||||
/// 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)
|
||||
let voice: CabinetVoice = CabinetVoice.voice(atSelectorValue: cabinet)
|
||||
return ConvolutionReverb.Audio(
|
||||
input: dry,
|
||||
ir: CabinetIRFactory.makeIR(voice: voice, sampleRate: sr),
|
||||
mix: convolutionMix
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user