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,12 +62,14 @@ struct CabinetPedalTests {
@Test func exposesCabinetAndMicSelectors() throws {
let pedal: CabinetPedal = CabinetPedal()
let labels: [String] = pedal.effectSelectors.map { $0.label }
#expect(labels == ["Cab", "Mic"])
// One Cab stop per voice, one Mic stop per mic voice, both in allCases order.
#expect(labels == ["Cab", "Mic", "Mic B"])
// One Cab stop per voice, and one stop per mic voice for both Mic and Mic B, in allCases order.
let cabStops: [String] = pedal.effectSelectors.first { $0.label == "Cab" }?.stops.map { $0.title } ?? []
#expect(cabStops == CabinetVoice.allCases.map { $0.displayName })
let micStops: [String] = pedal.effectSelectors.first { $0.label == "Mic" }?.stops.map { $0.title } ?? []
#expect(micStops == MicVoice.allCases.map { $0.displayName })
let micBStops: [String] = pedal.effectSelectors.first { $0.label == "Mic B" }?.stops.map { $0.title } ?? []
#expect(micBStops == MicVoice.allCases.map { $0.displayName })
}
@Test func micSelectionChangesOutput() throws {
@@ -134,9 +136,75 @@ struct CabinetPedalTests {
#expect(ssd == 0, "explicit default placement did not match the default render")
}
@Test func advancedKnobsExposePlacement() throws {
@Test func advancedKnobsExposePlacementAndDualMic() throws {
let pedal: CabinetPedal = CabinetPedal()
#expect(pedal.advancedKnobs.map { $0.label } == ["Position", "Proximity"])
#expect(pedal.advancedKnobs.map { $0.label } == ["Position", "Proximity", "Mic Blend", "Mic Offset"])
}
// MARK: - Dual mic
@Test func secondMicChangesOutput() throws {
// Engaging Mic B (a second parallel convolver) must change the output vs the single mic.
let single: [Float] = try render { $0.micB = 0.0 }
let dual: [Float] = try render { $0.micB = 2.0 } // Ribbon as the second mic
let skip: Int = 4096, window: Int = 4096
#expect(single.count >= skip + window && dual.count >= skip + window, "render too short")
guard single.count >= skip + window, dual.count >= skip + window else { return }
let ssd: Double = zip(single[skip..<(skip + window)], dual[skip..<(skip + window)]).reduce(0.0) { acc, pair in
let d: Double = Double(pair.0 - pair.1); return acc + d * d
}
#expect(ssd > 0, "engaging Mic B had no effect")
}
@Test func micBOffMakesBlendAndOffsetInert() throws {
// With Mic B = No Mic, the second convolver is not built, so Mic Blend / Mic Offset must have
// no effect — proving the single-mic default path is untouched by the dual-mic controls.
let a: [Float] = try render { $0.micB = 0.0; $0.micBlend = 0.0; $0.micOffset = 0.0 }
let b: [Float] = try render { $0.micB = 0.0; $0.micBlend = 1.0; $0.micOffset = 1.0 }
let skip: Int = 4096, window: Int = 4096
#expect(a.count >= skip + window && b.count >= skip + window, "render too short")
guard a.count >= skip + window, b.count >= skip + window else { return }
let ssd: Double = zip(a[skip..<(skip + window)], b[skip..<(skip + window)]).reduce(0.0) { acc, pair in
let d: Double = Double(pair.0 - pair.1); return acc + d * d
}
#expect(ssd == 0, "Mic Blend/Offset changed output while Mic B was Off")
}
@Test func micBlendAndOffsetChangeOutputWhenEngaged() throws {
// With Mic B engaged, both the blend balance and the comb offset must change the output.
let blendA: [Float] = try render { $0.micB = 2.0; $0.micBlend = 0.0 }
let blendB: [Float] = try render { $0.micB = 2.0; $0.micBlend = 1.0 }
let offset0: [Float] = try render { $0.micB = 2.0; $0.micBlend = 0.5; $0.micOffset = 0.0 }
let offset1: [Float] = try render { $0.micB = 2.0; $0.micBlend = 0.5; $0.micOffset = 1.0 }
let skip: Int = 4096, window: Int = 4096
func ssd(_ x: [Float], _ y: [Float]) -> Double {
guard x.count >= skip + window, y.count >= skip + window else { return 0.0 }
return zip(x[skip..<(skip + window)], y[skip..<(skip + window)]).reduce(0.0) { acc, pair in
let d: Double = Double(pair.0 - pair.1); return acc + d * d
}
}
#expect(ssd(blendA, blendB) > 0, "Mic Blend had no effect when engaged")
#expect(ssd(offset0, offset1) > 0, "Mic Offset (comb) had no effect when engaged")
}
@Test func dualMicRoundTripsThroughState() throws {
let pedal: CabinetPedal = CabinetPedal()
pedal.micB = 3.0
pedal.micBlend = 0.3
pedal.micOffset = 0.6
let restored: CabinetPedal = CabinetPedal()
restored.applyState(pedal.captureState())
#expect(restored.micB == 3.0 && restored.micBlend == 0.3 && restored.micOffset == 0.6,
"dual-mic controls did not round-trip")
}
@Test func dualMicStaysWithinCeiling() throws {
// Two convolvers summed can exceed ±1 pre-limiter; the look-ahead limiter must still bound it.
let ceilingEpsilon: Double = 1.0e-4
let out: [Float] = try render { $0.micB = 1.0; $0.micBlend = 0.5; $0.micOffset = 0.5 }
#expect(out.allSatisfy { $0.isFinite })
let peak: Double = out.reduce(0.0) { Swift.max($0, abs(Double($1))) }
#expect(peak <= 1.0 + ceilingEpsilon, "dual-mic peak \(peak) exceeds ±1")
}
@Test func placementRoundTripsThroughState() throws {