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:
@@ -59,13 +59,51 @@ struct CabinetPedalTests {
|
||||
#expect(ssd > 0, "cabinet selection had no effect on output")
|
||||
}
|
||||
|
||||
@Test func exposesCabinetSelector() throws {
|
||||
@Test func exposesCabinetAndMicSelectors() throws {
|
||||
let pedal: CabinetPedal = CabinetPedal()
|
||||
let labels: [String] = pedal.effectSelectors.map { $0.label }
|
||||
#expect(labels == ["Cab"])
|
||||
// One stop per voice, in allCases order.
|
||||
let stops: [String] = pedal.effectSelectors.first?.stops.map { $0.title } ?? []
|
||||
#expect(stops == CabinetVoice.allCases.map { $0.displayName })
|
||||
#expect(labels == ["Cab", "Mic"])
|
||||
// One Cab stop per voice, one Mic stop per mic voice, both 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 })
|
||||
}
|
||||
|
||||
@Test func micSelectionChangesOutput() throws {
|
||||
// Mic 0 = No Mic, mic 1 = Dynamic — different baked IRs, different output.
|
||||
let noMic: [Float] = try render { $0.mic = 0.0 }
|
||||
let dynamic: [Float] = try render { $0.mic = 1.0 }
|
||||
#expect(hasNonSilentOutput(noMic) && hasNonSilentOutput(dynamic))
|
||||
let skip: Int = 4096, window: Int = 4096
|
||||
guard noMic.count >= skip + window, dynamic.count >= skip + window else { return }
|
||||
let ssd: Double = zip(noMic[skip..<(skip + window)], dynamic[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 selection had no effect on output")
|
||||
}
|
||||
|
||||
@Test func micSelectionRoundTripsThroughState() throws {
|
||||
let pedal: CabinetPedal = CabinetPedal()
|
||||
pedal.cabinet = 2.0
|
||||
pedal.mic = 3.0
|
||||
let restored: CabinetPedal = CabinetPedal()
|
||||
restored.applyState(pedal.captureState())
|
||||
#expect(restored.cabinet == 2.0 && restored.mic == 3.0, "cab/mic selection 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.
|
||||
let ceilingEpsilon: Double = 1.0e-4
|
||||
for cab: Double in [0.0, 2.0, 6.0] {
|
||||
for micValue: Double in [0.0, 1.0, 2.0, 3.0] {
|
||||
let out: [Float] = try render { $0.cabinet = cab; $0.mic = micValue }
|
||||
#expect(out.allSatisfy { $0.isFinite })
|
||||
let peak: Double = out.reduce(0.0) { Swift.max($0, abs(Double($1))) }
|
||||
#expect(peak <= 1.0 + ceilingEpsilon, "cab=\(cab) mic=\(micValue) peak \(peak) exceeds ±1")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test func cabinetSelectorRebuildsOnChange() throws {
|
||||
|
||||
Reference in New Issue
Block a user