292261a088
Follow-up cleanup now that card width is content-derived. Redefine widthUnits as the card's base width in knob columns (1 = 3-wide, 2 = 4-wide) — both the knob-grid column count and the card's minimum width — with selector/switch rows able to push wider. Values above 2 no longer do anything. - Delete the now-misleading widthUnits 3/4 overrides on 11 amps; they inherit AmpVoicePedal's 2 (all full-surface amps → the same tight 4-wide card). - Remove Mutant's redundant override (2 knobs + 2 switches → 3-wide either way). - Cabinet: keep widthUnits 2 so it's 4-wide like the amps — its Cab/Mic/Mic B selector captions (voice names) need the room to stay readable (per request). - Looper keeps widthUnits 3 (the one pedal still using the flat multiple for its bespoke timeline/knobs/transport layout). - Refresh the widthUnits docs (base + AmpVoicePedal + Cabinet); update the amp tests' widthUnits assertions (3/4 → 2; Looper stays 3). 675 tests pass; no visual change to the amps, Cabinet now matches their width. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
210 lines
9.3 KiB
Swift
210 lines
9.3 KiB
Swift
// JazzCleanAmpPedalTests.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("JazzCleanAmpPedal")
|
|
struct JazzCleanAmpPedalTests {
|
|
|
|
private let sampleRate: Double = 48000.0
|
|
|
|
/// Renders the amp as a stereo widener, returning the separated (left, right) channels — the
|
|
/// pedal's `outputBusRight` is wired to a second bus and a split master routes both to the
|
|
/// hardware L/R so `readStereoCAF` can capture them independently.
|
|
private func renderStereo(configure: (JazzCleanAmpPedal) -> Void = { _ in }) throws
|
|
-> (left: [Float], right: [Float]) {
|
|
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
|
duration: 0.3, sampleRate: sampleRate, numAudioBuses: 64)
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
|
|
let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
|
let dstL: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
|
let dstR: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
|
defer {
|
|
engine.busAllocator.releaseAudioBus(srcBus)
|
|
engine.busAllocator.releaseAudioBus(dstL)
|
|
engine.busAllocator.releaseAudioBus(dstR)
|
|
}
|
|
|
|
let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
|
|
let pedal: JazzCleanAmpPedal = JazzCleanAmpPedal(inputBus: srcBus.index, outputBus: dstL.index)
|
|
pedal.outputBusRight = dstR.index
|
|
pedal.sampleRate = sampleRate
|
|
configure(pedal)
|
|
let master: JazzStereoSplitMaster = JazzStereoSplitMaster(left: dstL.index, right: dstR.index)
|
|
try engine.add(source)
|
|
try engine.add(pedal, position: NodePosition.after(source))
|
|
try engine.add(master, position: NodePosition.after(pedal))
|
|
try engine.start()
|
|
|
|
let interleaved: [Float] = readStereoCAF(url: url, sampleRate: sampleRate)
|
|
var left: [Float] = []
|
|
var right: [Float] = []
|
|
left.reserveCapacity(interleaved.count / 2)
|
|
right.reserveCapacity(interleaved.count / 2)
|
|
for frame: Int in 0..<(interleaved.count / 2) {
|
|
left.append(interleaved[2 * frame])
|
|
right.append(interleaved[2 * frame + 1])
|
|
}
|
|
return (left, right)
|
|
}
|
|
|
|
private func windowedSSD(_ a: [Float], _ b: [Float], skip: Int = 2048, window: Int = 2048) -> Double {
|
|
guard a.count >= skip + window, b.count >= skip + window else { return 0.0 }
|
|
return zip(a[skip..<(skip + window)], b[skip..<(skip + window)]).reduce(0.0) { acc, pair in
|
|
let d: Double = Double(pair.0 - pair.1); return acc + d * d
|
|
}
|
|
}
|
|
|
|
private func peak(_ samples: [Float]) -> Double {
|
|
samples.reduce(0.0) { Swift.max($0, abs(Double($1))) }
|
|
}
|
|
|
|
@Test func buildsNonSilentFiniteOutput() throws {
|
|
let (left, right): ([Float], [Float]) = try renderStereo()
|
|
#expect(hasNonSilentOutput(left), "Jazz Clean left channel was silent")
|
|
#expect(hasNonSilentOutput(right), "Jazz Clean right channel was silent")
|
|
#expect(left.allSatisfy { $0.isFinite } && right.allSatisfy { $0.isFinite },
|
|
"Jazz Clean produced non-finite output")
|
|
}
|
|
|
|
@Test func chorusEngagedWidensToStereo() throws {
|
|
// Engaged: the two chorus taps differ → genuine stereo width.
|
|
let (left, right): ([Float], [Float]) = try renderStereo { $0.chorusEnabled = 1.0 }
|
|
#expect(windowedSSD(left, right) > 0, "engaged chorus should make L and R differ")
|
|
}
|
|
|
|
@Test func chorusBypassedCollapsesToMono() throws {
|
|
// Bypassed: mix 0 → both taps are the dry core → L == R (bit-identical).
|
|
let (left, right): ([Float], [Float]) = try renderStereo { $0.chorusEnabled = 0.0 }
|
|
#expect(hasNonSilentOutput(left))
|
|
#expect(windowedSSD(left, right) == 0.0, "bypassed chorus should collapse to mono (L == R)")
|
|
}
|
|
|
|
@Test func chorusFootswitchChangesOutput() throws {
|
|
let on: [Float] = try renderStereo { $0.chorusEnabled = 1.0; $0.chorusRate = 3.0 }.left
|
|
let off: [Float] = try renderStereo { $0.chorusEnabled = 0.0; $0.chorusRate = 3.0 }.left
|
|
#expect(windowedSSD(on, off) > 0, "chorus footswitch had no effect")
|
|
// With the chorus off, the Rate knob is irrelevant (mix 0 → dry) — two off-renders match.
|
|
let offSlow: [Float] = try renderStereo { $0.chorusEnabled = 0.0; $0.chorusRate = 0.2 }.left
|
|
let offFast: [Float] = try renderStereo { $0.chorusEnabled = 0.0; $0.chorusRate = 5.0 }.left
|
|
#expect(windowedSSD(offSlow, offFast) == 0.0, "chorus off should ignore rate (dry pass-through)")
|
|
}
|
|
|
|
@Test func chorusRateChangesOutput() throws {
|
|
let slow: [Float] = try renderStereo { $0.chorusRate = 0.2 }.left
|
|
let fast: [Float] = try renderStereo { $0.chorusRate = 5.0 }.left
|
|
#expect(windowedSSD(slow, fast) > 0, "chorus rate had no effect")
|
|
}
|
|
|
|
@Test func chorusDepthChangesOutput() throws {
|
|
let shallow: [Float] = try renderStereo { $0.chorusDepth = 0.001 }.left
|
|
let deep: [Float] = try renderStereo { $0.chorusDepth = 0.014 }.left
|
|
#expect(windowedSSD(shallow, deep) > 0, "chorus depth had no effect")
|
|
}
|
|
|
|
@Test func reverbMixChangesOutput() throws {
|
|
let dry: [Float] = try renderStereo { $0.reverb = 0.0 }.left
|
|
let wet: [Float] = try renderStereo { $0.reverb = 0.9 }.left
|
|
#expect(windowedSSD(dry, wet) > 0, "reverb mix had no effect")
|
|
}
|
|
|
|
@Test func brightSwitchChangesOutput() throws {
|
|
let flat: [Float] = try renderStereo { $0.bright = 0.0 }.left
|
|
let bright: [Float] = try renderStereo { $0.bright = 1.0 }.left
|
|
#expect(windowedSSD(flat, bright) > 0, "bright switch had no effect")
|
|
}
|
|
|
|
@Test func distortionChannelChangesOutput() throws {
|
|
// Channel is read at build time (rebuildsOnChange); configure runs before build, so the
|
|
// Distortion channel cascades its extra gain stage.
|
|
let clean: [Float] = try renderStereo { $0.channel = 0.0 }.left
|
|
let dist: [Float] = try renderStereo { $0.channel = 1.0; $0.drive = 9.5 }.left
|
|
#expect(windowedSSD(clean, dist) > 0, "distortion channel had no effect")
|
|
let channel: PedalSwitch? = JazzCleanAmpPedal().effectSwitches.first { $0.label == "Channel" }
|
|
#expect(channel?.rebuildsOnChange == true, "Channel switch should rebuild on change")
|
|
}
|
|
|
|
@Test func bothChannelsStayWithinCeilingWithFXEngaged() throws {
|
|
let ceilingEpsilon: Double = 1.0e-4
|
|
let (left, right): ([Float], [Float]) = try renderStereo { (pedal: JazzCleanAmpPedal) in
|
|
pedal.gain = 11.0
|
|
pedal.bass = 1.0
|
|
pedal.treble = 1.0
|
|
pedal.reverb = 1.0
|
|
pedal.bright = 1.0
|
|
pedal.chorusDepth = 0.015
|
|
}
|
|
#expect(peak(left) <= 1.0 + ceilingEpsilon, "left peak \(peak(left)) exceeds the ±1 ceiling")
|
|
#expect(peak(right) <= 1.0 + ceilingEpsilon, "right peak \(peak(right)) exceeds the ±1 ceiling")
|
|
#expect(peak(left) > 0.3 && peak(right) > 0.3, "unexpectedly quiet at max gain")
|
|
}
|
|
|
|
@Test func exposesFullControlSurface() throws {
|
|
let pedal: JazzCleanAmpPedal = JazzCleanAmpPedal()
|
|
#expect(pedal.effectKnobs.map { $0.label }
|
|
== ["Gain", "Bass", "Mid", "Treble", "Reverb", "Rate", "Depth", "Drive"])
|
|
#expect(pedal.effectSwitches.map { $0.label } == ["Bright", "Chorus", "Channel"])
|
|
#expect(pedal.effectSelectors.map { $0.label } == ["Cab"])
|
|
#expect(pedal.effectSelectors.first?.rebuildsOnChange == true)
|
|
#expect(pedal.widthUnits == 2)
|
|
#expect(pedal.showsMixControl == false)
|
|
#expect(pedal.channelKind == .widener, "Jazz Clean should be a stereo widener")
|
|
#expect(pedal.toneStackModel == .fender)
|
|
}
|
|
|
|
@Test func controlsRoundTripThroughState() throws {
|
|
let pedal: JazzCleanAmpPedal = JazzCleanAmpPedal()
|
|
pedal.gain = 6.0
|
|
pedal.reverb = 0.5
|
|
pedal.chorusRate = 2.0
|
|
pedal.chorusDepth = 0.008
|
|
pedal.bright = 1.0
|
|
pedal.chorusEnabled = 0.0
|
|
pedal.channel = 1.0
|
|
pedal.drive = 11.0
|
|
pedal.cab = 3.0
|
|
let restored: JazzCleanAmpPedal = JazzCleanAmpPedal()
|
|
restored.applyState(pedal.captureState())
|
|
#expect(restored.gain == 6.0)
|
|
#expect(restored.reverb == 0.5)
|
|
#expect(restored.chorusRate == 2.0)
|
|
#expect(restored.chorusDepth == 0.008)
|
|
#expect(restored.bright == 1.0)
|
|
#expect(restored.chorusEnabled == 0.0)
|
|
#expect(restored.channel == 1.0 && restored.drive == 11.0)
|
|
#expect(restored.cab == 3.0)
|
|
}
|
|
|
|
@Test func registeredInBuiltInRegistry() throws {
|
|
#expect(PedalRegistry.makePedal(type: "Jazz Clean") is JazzCleanAmpPedal)
|
|
}
|
|
}
|
|
|
|
/// Routes two mono board buses to hardware left (0) and right (1) so the widener's channels can be
|
|
/// captured separately by `readStereoCAF`.
|
|
@MainActor
|
|
private final class JazzStereoSplitMaster: SynthesizerBase {
|
|
private let left: Int
|
|
private let right: Int
|
|
|
|
init(left: Int, right: Int) {
|
|
self.left = left
|
|
self.right = right
|
|
super.init()
|
|
}
|
|
|
|
override func build() {
|
|
output(bus: 0, source: input(bus: left))
|
|
output(bus: 1, source: input(bus: right))
|
|
}
|
|
}
|