feat(cabinet): mic placement — Position + Proximity (14b)

Phase 14b of cabinet mic modeling. Two live, continuous placement controls in
the CabinetPedal advanced pop-over:

- Position [0,1]: on-axis (0, bright) -> cone edge / off-axis (1, dark), a live
  RBJ high-shelf cut (0..-9 dB @ 3.5 kHz).
- Proximity [0,1]: distant (0, flat) -> close-mic'd (1), a live RBJ low-shelf
  boost (0..+6 dB @ 150 Hz) modelling the proximity effect.

Both are LIVE post-convolution shelves (not baked), so they are smooth knobs
with no rebuild-on-change, and each maps its knob to 0 dB at 0 -> a bit-exact
identity at the defaults (existing cab presets sound unchanged). Placed in
advancedKnobs (advancedValues), append-only, so old CabinetPedal presets don't
shift Mix/Level positions. The look-ahead limiter still bounds output.

Tests: Position/Proximity change output; neutral (0,0) is a bit-exact identity;
advanced knobs exposed; round-trip through state; placement extremes stay within
the ±1 ceiling. 664 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-04 09:16:22 -07:00
parent 96ab2a0586
commit f67a5370ff
2 changed files with 109 additions and 1 deletions
@@ -92,6 +92,58 @@ struct CabinetPedalTests {
#expect(restored.cabinet == 2.0 && restored.mic == 3.0, "cab/mic selection did not round-trip")
}
@Test func positionChangesOutput() throws {
// Position sweeps a live high-shelf cut (on-axis → cone edge), so it must change the output.
let onAxis: [Float] = try render { $0.position = 0.0 }
let edge: [Float] = try render { $0.position = 1.0 }
let skip: Int = 4096, window: Int = 4096
guard onAxis.count >= skip + window, edge.count >= skip + window else { return }
let ssd: Double = zip(onAxis[skip..<(skip + window)], edge[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 Position had no effect on output")
}
@Test func proximityChangesOutput() throws {
// Proximity sweeps a live low-shelf boost (distant → close), so it must change the output.
let distant: [Float] = try render { $0.proximity = 0.0 }
let close: [Float] = try render { $0.proximity = 1.0 }
let skip: Int = 4096, window: Int = 4096
guard distant.count >= skip + window, close.count >= skip + window else { return }
let ssd: Double = zip(distant[skip..<(skip + window)], close[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 Proximity had no effect on output")
}
@Test func placementDefaultsAreNeutral() throws {
// Position = 0 and Proximity = 0 map to 0 dB shelves (bit-exact identity), so setting them
// explicitly to the defaults must match the default render exactly — no placement coloration
// for cabs saved before placement existed.
let byDefault: [Float] = try render()
let explicit: [Float] = try render { $0.position = 0.0; $0.proximity = 0.0 }
let skip: Int = 4096, window: Int = 4096
guard byDefault.count >= skip + window, explicit.count >= skip + window else { return }
let ssd: Double = zip(byDefault[skip..<(skip + window)], explicit[skip..<(skip + window)]).reduce(0.0) { acc, pair in
let d: Double = Double(pair.0 - pair.1); return acc + d * d
}
#expect(ssd == 0, "neutral Position/Proximity is not a bit-exact identity")
}
@Test func advancedKnobsExposePlacement() throws {
let pedal: CabinetPedal = CabinetPedal()
#expect(pedal.advancedKnobs.map { $0.label } == ["Position", "Proximity"])
}
@Test func placementRoundTripsThroughState() throws {
let pedal: CabinetPedal = CabinetPedal()
pedal.position = 0.7
pedal.proximity = 0.4
let restored: CabinetPedal = CabinetPedal()
restored.applyState(pedal.captureState())
#expect(restored.position == 0.7 && restored.proximity == 0.4, "placement did not round-trip")
}
@Test func outputStaysWithinCeiling() throws {
// The tanh soft-limit + Clip(±1) bound the output so a decoupled amp → cabinet chain can't
// clip the DAC. No render may exceed ±1.
@@ -104,6 +156,11 @@ struct CabinetPedalTests {
#expect(peak <= 1.0 + ceilingEpsilon, "cab=\(cab) mic=\(micValue) peak \(peak) exceeds ±1")
}
}
// Placement extremes (max proximity bass lift) must still be caught by the limiter.
let placed: [Float] = try render { $0.position = 1.0; $0.proximity = 1.0 }
#expect(placed.allSatisfy { $0.isFinite })
let placedPeak: Double = placed.reduce(0.0) { Swift.max($0, abs(Double($1))) }
#expect(placedPeak <= 1.0 + ceilingEpsilon, "placement extremes peak \(placedPeak) exceeds ±1")
}
@Test func cabinetSelectorRebuildsOnChange() throws {