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:
@@ -110,4 +110,57 @@ struct CabinetIRFactoryTests {
|
||||
let names: [String] = CabinetVoice.allCases.map { $0.displayName }
|
||||
#expect(Set(names).count == names.count, "duplicate cabinet display names")
|
||||
}
|
||||
|
||||
// MARK: - Mic voicing
|
||||
|
||||
/// Ratio of the IR's magnitude at `hz` to a mid-band reference (800 Hz). Peak-normalization
|
||||
/// scales the whole IR, so it cancels in this ratio — letting a mic's *relative* boost/cut at a
|
||||
/// frequency be compared across IRs regardless of their independent normalization.
|
||||
private func tiltRatio(_ ir: LyrebirdBuffer, hz: Double) -> Double {
|
||||
let reference: Double = responseMagnitude(ir, hz: 800.0)
|
||||
guard reference > 0.0 else { return 0.0 }
|
||||
return responseMagnitude(ir, hz: hz) / reference
|
||||
}
|
||||
|
||||
@Test func noMicMatchesRawCabIR() {
|
||||
// MicVoice.off must append no stages, so the IR is byte-identical to the mic-less default —
|
||||
// the backward-compatible path for cabs saved before mic voicing existed.
|
||||
for voice: CabinetVoice in CabinetVoice.allCases {
|
||||
let raw: LyrebirdBuffer = CabinetIRFactory.makeIR(voice: voice, sampleRate: sampleRate)
|
||||
let offMic: LyrebirdBuffer = CabinetIRFactory.makeIR(voice: voice, mic: .off, sampleRate: sampleRate)
|
||||
#expect(raw.count == offMic.count)
|
||||
var identical: Bool = true
|
||||
for i: Int in 0..<raw.count where raw[i, 0] != offMic[i, 0] { identical = false; break }
|
||||
#expect(identical, "\(voice) No-Mic IR differs from the raw cab IR")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func dynamicMicLiftsPresence() {
|
||||
// The dynamic mic adds a presence bump at ~5.5 kHz → a higher 5.5 kHz-to-mid tilt than no mic.
|
||||
let off: LyrebirdBuffer = CabinetIRFactory.makeIR(voice: .americanCombo, mic: .off, sampleRate: sampleRate)
|
||||
let dynamic: LyrebirdBuffer = CabinetIRFactory.makeIR(voice: .americanCombo, mic: .dynamic, sampleRate: sampleRate)
|
||||
#expect(tiltRatio(dynamic, hz: 5500.0) > tiltRatio(off, hz: 5500.0),
|
||||
"dynamic mic did not lift the presence region")
|
||||
}
|
||||
|
||||
@Test func ribbonMicDarkensTop() {
|
||||
// The ribbon mic rolls the top off (−7 dB shelf @ 6.5 kHz) → a lower 8 kHz-to-mid tilt.
|
||||
let off: LyrebirdBuffer = CabinetIRFactory.makeIR(voice: .fullRange, mic: .off, sampleRate: sampleRate)
|
||||
let ribbon: LyrebirdBuffer = CabinetIRFactory.makeIR(voice: .fullRange, mic: .ribbon, sampleRate: sampleRate)
|
||||
#expect(tiltRatio(ribbon, hz: 8000.0) < tiltRatio(off, hz: 8000.0),
|
||||
"ribbon mic did not darken the top end")
|
||||
}
|
||||
|
||||
@Test func condenserMicAddsAir() {
|
||||
// The condenser mic lifts the extreme top (+3 dB shelf @ 11 kHz) → a higher 10 kHz-to-mid tilt.
|
||||
let off: LyrebirdBuffer = CabinetIRFactory.makeIR(voice: .fullRange, mic: .off, sampleRate: sampleRate)
|
||||
let condenser: LyrebirdBuffer = CabinetIRFactory.makeIR(voice: .fullRange, mic: .condenser, sampleRate: sampleRate)
|
||||
#expect(tiltRatio(condenser, hz: 10000.0) > tiltRatio(off, hz: 10000.0),
|
||||
"condenser mic did not add top-end air")
|
||||
}
|
||||
|
||||
@Test func micNamesAreUnique() {
|
||||
let names: [String] = MicVoice.allCases.map { $0.displayName }
|
||||
#expect(Set(names).count == names.count, "duplicate mic display names")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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