feat(cabinet): mic voicing (14a) + cabinet output soft-limit

Phase 14a of cabinet mic modeling.

- MicVoice (No Mic / Dynamic / Ribbon / Condenser): broad-strokes synthesized
  mic curves (our own MIT content, not captures) as CabIRStage biquad specs
  (presence bump, low/high shelving) that CabinetIRFactory appends to the cab
  cascade before baking — folded into the SAME single convolution IR, so mic
  choice costs nothing at render time. MicVoice.off appends nothing → the IR
  is byte-identical to the raw cab voice (backward compatible).
- CabinetIRFactory.makeIR gains a `mic:` param (default .off) + RBJ low/high
  shelf offline biquads.
- CabinetPedal: Mic selector (rebuildsOnChange, append-only 2nd selector so
  old presets still load with mic defaulting to off) + a tanh soft-limit →
  Clip(±1) output stage, so a decoupled amp → cabinet chain can't clip the
  DAC (a speaker cab is analog; clean signals pass at ~unit gain).
- Help acknowledgment notes the mic voicings are synthesized, not captures.

Tests: No-Mic IR byte-identical to raw cab; dynamic lifts presence, ribbon
darkens top, condenser adds air (peak-normalization-invariant tilt ratios);
mic changes output, round-trips; output stays within ±1 across cab×mic. 659
tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-04 08:55:11 -07:00
parent a2fcd59e1b
commit 7f1856e8e5
7 changed files with 333 additions and 17 deletions
@@ -45,6 +45,9 @@ public final class CabinetPedal: Pedal {
/// stops via the ``cabinet`` selector; read at board-build time by `effect(_:)`, which
/// instantiates only that voice's convolver (the selector is `rebuildsOnChange`).
@UIParam public var cabinet: Double = 0.0
/// Selected microphone voicing as an index into ``MicVoice/allCases`` (`0` = No Mic). Baked into
/// the same IR as the cab voice, so it costs nothing extra at render time. `rebuildsOnChange`.
@UIParam public var mic: Double = 0.0
// MARK: - Constants
@@ -54,6 +57,18 @@ public final class CabinetPedal: Pedal {
/// Convolution is taken fully wet here; the `Pedal` base class provides the user wet/dry mix.
private let convolutionMix: Double = 1.0
/// Output soft-limit drive. `1.0` gives unit small-signal gain (clean signals pass untouched)
/// with a `tanh` asymptote at ±1 — a speaker cab is analog and does not digital-clip, so peaks
/// (convolution can overshoot ±1) soft-compress rather than hard-clip.
private let softLimitDrive: Double = 1.0
/// Symmetric output stage — a pure `tanh` limiter, no even-harmonic colour.
private let softLimitBias: Double = 0.0
/// 2× is enough: the cab low-pass already band-limits the signal feeding this stage.
private let softLimitOversample: Int = 2
/// Absolute digital ceiling for the hard safety clamp catching the sub-percent overshoot the
/// `tanh`'s DC-blocker / halfband filters can leave just above ±1.
private let outputCeiling: Double = 1.0
/// Selector stops, one per ``CabinetVoice`` in `allCases` order (value == index).
private static let voiceStops: [PedalSelectorKnob.Stop] = CabinetVoice.allCases
.enumerated()
@@ -61,6 +76,13 @@ public final class CabinetPedal: Pedal {
PedalSelectorKnob.Stop(title: voice.displayName, value: Double(index))
}
/// Selector stops, one per ``MicVoice`` in `allCases` order (value == index).
private static let micStops: [PedalSelectorKnob.Stop] = MicVoice.allCases
.enumerated()
.map { (index: Int, mic: MicVoice) in
PedalSelectorKnob.Stop(title: mic.displayName, value: Double(index))
}
// MARK: - Init
/// Creates a cabinet pedal.
@@ -86,28 +108,42 @@ public final class CabinetPedal: Pedal {
[
PedalSelectorKnob(
label: "Cab", node: $cabinet, stops: CabinetPedal.voiceStops, rebuildsOnChange: true),
PedalSelectorKnob(
label: "Mic", node: $mic, stops: CabinetPedal.micStops, rebuildsOnChange: true),
]
}
// MARK: - Effect
/// Convolves the dry signal against the single selected cabinet IR.
/// Convolves the dry signal against the single selected cabinet + mic IR, then soft-limits.
///
/// 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()`.
/// Only the voice/mic named by the live selectors is baked, so exactly one partitioned-FFT
/// convolver runs; the mic colour is folded into that same IR at no extra render cost. Changing
/// either selector triggers a board rebuild (both are `rebuildsOnChange`). Synthesizing the short
/// IR happens off the RT thread in `build()`.
///
/// The closing `TriodeStage(bias: 0)` → `Clip(±1)` is a symmetric `tanh` soft-limit + hard
/// ceiling: a speaker cab is analog and can't digital-clip, and the convolution can push peaks
/// past ±1, so peaks soft-compress toward ±1 while clean signals (well below ±1) pass at ~unit
/// gain. This keeps a decoupled amp → cabinet chain from clipping the DAC.
///
/// - Parameter dry: Dry mono input signal.
/// - Returns: The cabinet-convolved mono output.
/// - Returns: The cabinet-convolved, mic-voiced, soft-limited mono output.
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
let sr: Double = sampleRate
let voice: CabinetVoice = CabinetVoice.voice(atSelectorValue: cabinet)
return ConvolutionReverb.Audio(
let micVoice: MicVoice = MicVoice.voice(atSelectorValue: mic)
let convolved: ConvolutionReverb.Audio = ConvolutionReverb.Audio(
input: dry,
ir: CabinetIRFactory.makeIR(voice: voice, sampleRate: sr),
ir: CabinetIRFactory.makeIR(voice: voice, mic: micVoice, sampleRate: sr),
mix: convolutionMix
)
let softLimited: TriodeStage = TriodeStage(
input: convolved,
drive: softLimitDrive,
bias: softLimitBias,
oversample: softLimitOversample
)
return Clip.Audio(softLimited, lo: -outputCeiling, hi: outputCeiling)
}
}