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:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user