feat(amp): decouple cabinet — "None (direct)" stop + cabinet as separate block
Phase 12. Split AmpVoicePedal.cabinetAndLimit into cabinet(_:) (the ConvolutionReverb, or a straight pass) + outputLimit(_:) (tanh soft-limit → Clip(±1)). The output limit ALWAYS runs on the amp, so the per-amp ±1 guarantee survives cabinet removal. - Cab selector gains a "None (direct)" stop (value = CabinetVoice.allCases .count, appended last so existing preset cab indices stay stable). isCabinetBypassed skips the convolver at that stop. - With Cab = None the amp emits its limited, cab-less power-amp signal; the player drops the existing standalone Cabinet pedal (shared CabinetVoice / CabinetIRFactory, no DSP dup) after it as a real chain block. Default stays cab-on (backward compatible). Tests: None bypasses the convolver, None still limits to ±1 (limiter survived), the None stop is exposed, and an amp(None) → standalone Cabinet chain renders non-silent/finite. Note: a downstream cab can overshoot ±1 like any post-amp pedal — end-of-chain level is the board's stage, not the amp's. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -259,6 +259,73 @@ struct AmpVoicePedalTests {
|
||||
#expect(restored.sag == 0.7 && restored.bias == 0.2, "Sag/Bias did not round-trip through state")
|
||||
}
|
||||
|
||||
// MARK: - Cabinet decoupling
|
||||
|
||||
@Test func cabNoneBypassesConvolution() throws {
|
||||
for voice in voices {
|
||||
let withCab: [Float] = try render(voice.make) { $0.cab = 0.0 }
|
||||
let none: [Float] = try render(voice.make) { $0.cab = AmpVoicePedal.cabinetBypassValue }
|
||||
#expect(hasNonSilentOutput(none) && none.allSatisfy { $0.isFinite },
|
||||
"\(voice.name) None-cab output silent or non-finite")
|
||||
#expect(windowedSSD(withCab, none) > 0, "\(voice.name) None did not bypass the cabinet")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func cabNoneStillLimitsToCeiling() throws {
|
||||
// With the cabinet bypassed the output soft-limit must still run — the ±1 ceiling has to hold.
|
||||
let ceilingEpsilon: Double = 1.0e-4
|
||||
for voice in voices {
|
||||
let hot: [Float] = try render(voice.make) { (pedal: AmpVoicePedal) in
|
||||
pedal.gain = 30.0; pedal.bass = 1.0; pedal.treble = 1.0
|
||||
pedal.cab = AmpVoicePedal.cabinetBypassValue
|
||||
}
|
||||
let peak: Double = hot.reduce(0.0) { Swift.max($0, abs(Double($1))) }
|
||||
#expect(peak <= 1.0 + ceilingEpsilon,
|
||||
"\(voice.name) None-cab peak \(peak) exceeds ±1 (output limiter lost)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func cabSelectorExposesNoneStop() throws {
|
||||
let stops: [PedalSelectorKnob.Stop] = CaliforniaAmpPedal().effectSelectors
|
||||
.first { $0.label == "Cab" }?.stops ?? []
|
||||
#expect(stops.last?.title == "None (direct)", "Cab selector missing the None stop")
|
||||
#expect(stops.last?.value == AmpVoicePedal.cabinetBypassValue, "None stop has the wrong value")
|
||||
}
|
||||
|
||||
@Test func ampWithNoneCabIntoStandaloneCabinetWorks() throws {
|
||||
// Decoupled chain: amp (Cab = None) → standalone Cabinet pedal. The amp emits its limited,
|
||||
// cab-less signal; the separate Cabinet block does the speaker convolution downstream.
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
||||
duration: 0.2, sampleRate: sampleRate, numAudioBuses: 64)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||
let midBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||
let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||
defer {
|
||||
engine.busAllocator.releaseAudioBus(srcBus)
|
||||
engine.busAllocator.releaseAudioBus(midBus)
|
||||
engine.busAllocator.releaseAudioBus(dstBus)
|
||||
}
|
||||
let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
|
||||
let amp: CaliforniaAmpPedal = CaliforniaAmpPedal(inputBus: srcBus.index, outputBus: midBus.index)
|
||||
amp.sampleRate = sampleRate
|
||||
amp.cab = AmpVoicePedal.cabinetBypassValue
|
||||
let cabinet: CabinetPedal = CabinetPedal(inputBus: midBus.index, outputBus: dstBus.index)
|
||||
cabinet.sampleRate = sampleRate
|
||||
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index)
|
||||
try engine.add(source)
|
||||
try engine.add(amp, position: NodePosition.after(source))
|
||||
try engine.add(cabinet, position: NodePosition.after(amp))
|
||||
try engine.add(master, position: NodePosition.after(cabinet))
|
||||
try engine.start()
|
||||
let out: [Float] = readStereoCAF(url: url, sampleRate: sampleRate)
|
||||
#expect(hasNonSilentOutput(out) && out.allSatisfy { $0.isFinite }, "decoupled amp+cabinet silent/non-finite")
|
||||
// Note: the amp guarantees its OWN output ≤ ±1 (see `cabNoneStillLimitsToCeiling`), but a
|
||||
// downstream standalone Cabinet convolves that signal and — like any post-amp pedal — may
|
||||
// overshoot ±1. The board's final output stage, not the amp, owns end-of-chain level. So this
|
||||
// asserts the decoupled chain works (non-silent, finite), not a ±1 ceiling it never promised.
|
||||
}
|
||||
|
||||
// MARK: - Chrome / config
|
||||
|
||||
@Test func exposesControls() throws {
|
||||
|
||||
Reference in New Issue
Block a user