feat(cabinet): dual-mic blend with comb (14c)

Phase 14c — the classic two-mic technique. When "Mic B" (a second mic-voice
selector, default No Mic) is engaged, a parallel convolver (same cab voice,
mic B's IR) is delayed by up to 1.5 ms (Mic Offset) and summed with the
aligned primary at the Mic Blend balance — the time offset between the two
coherent copies produces comb filtering (e.g. a 57 + 121 blend).

- Mic B: rebuildsOnChange selector; No Mic (default) builds NO second
  convolver, so the single-mic path is bit-identical to before and costs one
  convolution. Mic Blend / Mic Offset are live smooth knobs (advanced pop-over,
  appended after Position/Proximity — append-only for advancedValues).
- Coherent (same-source) mics sum linearly: A*(1-blend) + Bdelayed*blend.
- The look-ahead limiter still bounds the summed output to ±1.

Tests: second mic changes output; with Mic B Off the blend/offset are inert
(single-mic path untouched); blend + comb offset both change output when
engaged; dual-mic round-trips through state; dual-mic stays within ±1. 669
tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-04 09:31:14 -07:00
parent 35ae16040a
commit d7eb0690ff
2 changed files with 132 additions and 9 deletions
@@ -62,6 +62,17 @@ public final class CabinetPedal: Pedal {
/// low-end boost). A live low-shelf boost, so it is a smooth knob (no rebake); `0` is a bit-exact
/// 0 dB identity. Surfaced in the advanced pop-over.
@UIParam public var proximity: Double = 0.0
/// Second microphone voicing as an index into ``MicVoice/allCases`` (`0` = No Mic → single mic,
/// the default). When engaged, a **second** convolver runs in parallel and blends with the first
/// (the classic two-mic technique). `rebuildsOnChange` — toggling it adds/removes the convolver.
@UIParam public var micB: Double = 0.0
/// **Mic Blend** in `[0, 1]` between mic A (`0`) and mic B (`1`); `0.5` = equal. Only active when
/// ``micB`` ≠ No Mic. A live blend, so it is a smooth knob. Surfaced in the advanced pop-over.
@UIParam public var micBlend: Double = 0.5
/// **Mic Offset** in `[0, 1]`: the relative time offset of mic B, `0` = aligned, `1` = the maximum
/// spacing. A short live delay on mic B; summing it with the aligned mic A produces the comb
/// filtering of two spaced mics. Only active when ``micB`` ≠ No Mic. Surfaced in the pop-over.
@UIParam public var micOffset: Double = 0.0
// MARK: - Constants
@@ -91,8 +102,11 @@ public final class CabinetPedal: Pedal {
private let proximityMaxBoostDb: Double = 6.0
/// Shelf slope for the position / proximity live shelves (gentle, like the amp shelves).
private let placementShelfSlope: Double = 0.7
/// `[0, 1]` range for the Position / Proximity pop-over knobs.
/// `[0, 1]` range for the Position / Proximity / Mic Blend / Mic Offset pop-over knobs.
private static let placementRange: ClosedRange<Double> = 0.0 ... 1.0
/// Maximum mic-B time offset (seconds) at `micOffset = 1` — a couple of mic diameters of spacing.
/// Sets both the delay-line size and the comb range (first notch ≈ `1 / (2·offset)` Hz).
private let maxMicOffsetSeconds: Double = 0.0015
/// Selector stops, one per ``CabinetVoice`` in `allCases` order (value == index).
private static let voiceStops: [PedalSelectorKnob.Stop] = CabinetVoice.allCases
@@ -135,16 +149,22 @@ public final class CabinetPedal: Pedal {
label: "Cab", node: $cabinet, stops: CabinetPedal.voiceStops, rebuildsOnChange: true),
PedalSelectorKnob(
label: "Mic", node: $mic, stops: CabinetPedal.micStops, rebuildsOnChange: true),
PedalSelectorKnob(
label: "Mic B", node: $micB, stops: CabinetPedal.micStops, rebuildsOnChange: true),
]
}
/// Mic-placement deep-cut controls, tucked behind the pedal card's advanced pop-over: **Position**
/// (on-axis ↔ cone edge) and **Proximity** (distance / bass lift). Live shelves (not baked), so
/// they are smooth knobs; neither is a topology control. Persisted positionally in `advancedValues`.
/// Mic-placement + dual-mic deep-cut controls, tucked behind the pedal card's advanced pop-over:
/// **Position** (on-axis ↔ cone edge), **Proximity** (distance / bass lift), and — when a second
/// mic is engaged — **Mic Blend** (A/B) and **Mic Offset** (comb spacing). All live (not baked),
/// so they are smooth knobs; none is a topology control. Persisted positionally in
/// `advancedValues` (append-only order).
public override var advancedKnobs: [PedalKnob] {
[
PedalKnob(label: "Position", node: $position, range: CabinetPedal.placementRange),
PedalKnob(label: "Proximity", node: $proximity, range: CabinetPedal.placementRange),
PedalKnob(label: "Mic Blend", node: $micBlend, range: CabinetPedal.placementRange),
PedalKnob(label: "Mic Offset", node: $micOffset, range: CabinetPedal.placementRange),
]
}
@@ -179,7 +199,8 @@ public final class CabinetPedal: Pedal {
ir: CabinetIRFactory.makeIR(voice: voice, mic: micVoice, sampleRate: sr),
mix: convolutionMix
)
let placed: any ValidGeneratorInput = applyPlacement(convolved)
let mixed: any ValidGeneratorInput = blendSecondMic(dry: dry, primary: convolved, voice: voice, sr: sr)
let placed: any ValidGeneratorInput = applyPlacement(mixed)
return LookAheadLimiter(
in: placed,
maxAmplitude: outputCeiling,
@@ -195,6 +216,40 @@ public final class CabinetPedal: Pedal {
/// shelf gain in dB with `0` → `0` dB, so at the default (`0, 0`) each shelf is a bit-exact
/// identity and the cabinet sounds exactly as it did before placement existed.
///
/// Blends a second microphone into the primary convolution when ``micB`` ≠ No Mic — the classic
/// two-mic technique. A parallel convolver (same cab voice, mic B's IR) is delayed by up to
/// ``maxMicOffsetSeconds`` (``micOffset``) and summed with the aligned primary at the ``micBlend``
/// balance; the time offset between the two coherent copies produces comb filtering. When ``micB``
/// is No Mic (the default) the primary is returned unchanged — no second convolver is built, so
/// the single-mic path costs exactly one convolution and is bit-identical to before this feature.
///
/// - Parameters:
/// - dry: The dry input (fed to the second convolver).
/// - primary: The primary (mic A) convolution output.
/// - voice: The cabinet voice (shared by both mics).
/// - sr: Engine sample rate.
/// - Returns: The single- or dual-mic blended signal.
private func blendSecondMic(
dry: any ValidGeneratorInput,
primary: any ValidGeneratorInput,
voice: CabinetVoice,
sr: Double
) -> any ValidGeneratorInput {
let micBVoice: MicVoice = MicVoice.voice(atSelectorValue: micB)
guard micBVoice != .off else { return primary }
let secondary: ConvolutionReverb.Audio = ConvolutionReverb.Audio(
input: dry,
ir: CabinetIRFactory.makeIR(voice: voice, mic: micBVoice, sampleRate: sr),
mix: convolutionMix
)
let delaySeconds: LinLin.Audio = LinLin.Audio(
$micOffset, inLo: 0.0, inHi: 1.0, outLo: 0.0, outHi: maxMicOffsetSeconds)
let delayedSecondary: DelayLine = DelayLine(
input: secondary, maxDelay: maxMicOffsetSeconds, delay: delaySeconds, sampleRate: sr)
// Coherent (same-source) mics sum linearly: A·(1−blend) + Bdelayed·blend.
return primary * (1.0 - $micBlend) + delayedSecondary * $micBlend
}
/// - Parameter signal: The cab-convolved signal.
/// - Returns: The placement-shaped signal.
private func applyPlacement(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput {