feat(pedals): Cabinet IR pedal (S1) with synthesized cab voices

First amp-modeling increment (ShoeGaze 2.0, plan S1). No Lyrebird change —
reuses ConvolutionReverb + LyrebirdBuffer.

- CabinetPedal: builds one ConvolutionReverb per built-in voice at build() time
  and picks the active one with a `Select` driven by the persisted `cabinet`
  selector — live cab switching that round-trips through the rig save format.
- CabinetVoice + CabinetIRFactory: three built-in voicings synthesized in code
  (impulse through an RBJ biquad cascade — HP, true 4th-order Butterworth LP,
  body + presence peaks), so the bundled cab set is our own MIT content (no
  third-party IR licensing). Filter centre frequencies are Nyquist-clamped.
- Registered in PedalRegistry / PedalType / PedalCategory (.filter) / palette;
  README pedal count + catalog updated.

User-supplied captured .wav cab IRs are a planned follow-up (needs a persisted
file-path field PedalState doesn't yet carry).

Tests: IR is finite, peak-normalized, mono; rolls off lows and highs; voices
differ; selector exposed; selection changes output and round-trips through
PedalState; pedal builds, non-silent, resolves from the registry. Suite 486.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-01 16:56:08 -07:00
parent 791fbd1b2c
commit 4a5d4009f6
11 changed files with 514 additions and 3 deletions
@@ -0,0 +1,85 @@
// CabinetPedalTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
import Foundation
import LyrebirdSynth
import LyrebirdUI
@testable import LyrebirdShoeGaze
@MainActor
@Suite("CabinetPedal")
struct CabinetPedalTests {
private func render(configure: (CabinetPedal) -> Void = { _ in }) throws -> [Float] {
let sampleRate: Double = 48000.0
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 dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
defer {
engine.busAllocator.releaseAudioBus(srcBus)
engine.busAllocator.releaseAudioBus(dstBus)
}
let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
let pedal: CabinetPedal = CabinetPedal(inputBus: srcBus.index, outputBus: dstBus.index)
pedal.sampleRate = sampleRate
configure(pedal)
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index)
try engine.add(source)
try engine.add(pedal, position: NodePosition.after(source))
try engine.add(master, position: NodePosition.after(pedal))
try engine.start()
return readStereoCAF(url: url, sampleRate: sampleRate)
}
@Test func buildsAndProducesNonSilentOutput() throws {
let samples: [Float] = try render()
#expect(!samples.isEmpty)
#expect(hasNonSilentOutput(samples), "CabinetPedal produced silence")
}
@Test func cabinetSelectionChangesOutput() throws {
// Index 0 = American 1×12, index 2 = Vintage Dark — different voicings, different output.
let american: [Float] = try render { $0.cabinet = 0.0 }
let dark: [Float] = try render { $0.cabinet = 2.0 }
#expect(hasNonSilentOutput(american) && hasNonSilentOutput(dark))
let skip: Int = 4096
let window: Int = 4096
guard american.count >= skip + window, dark.count >= skip + window else { return }
let ssd: Double = zip(american[skip..<(skip + window)], dark[skip..<(skip + window)]).reduce(0.0) { acc, pair in
let d: Double = Double(pair.0 - pair.1); return acc + d * d
}
#expect(ssd > 0, "cabinet selection had no effect on output")
}
@Test func exposesCabinetSelector() 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 })
}
@Test func cabinetSelectionRoundTripsThroughState() throws {
// The selector value must survive capture/apply (preset round-trip).
let pedal: CabinetPedal = CabinetPedal()
pedal.cabinet = 2.0
let state: PedalState = pedal.captureState()
let restored: CabinetPedal = CabinetPedal()
restored.applyState(state)
#expect(restored.cabinet == 2.0, "cabinet selection did not round-trip through PedalState")
}
@Test func registeredInBuiltInRegistry() throws {
let pedal: Pedal? = PedalRegistry.makePedal(type: "Cabinet")
#expect(pedal is CabinetPedal)
}
}