102715ded1
First stereo (widener) amp, modeling the JC-style ultra-clean combo whose signature is a lush stereo chorus fed to two power amps / speakers. Refactor AmpVoicePedal.effect() into two reusable, behavior-preserving pieces: - preCabinetCore(_:) — inputShaping → preamp → tone → onboardEffects → power → shapeVoice (mono) - cabinetAndLimit(_:) — selected cab convolver → tanh soft-limit → Clip(±1) (per channel) effect() = cabinetAndLimit(preCabinetCore(dry)); the four existing amps are unchanged (verified by their suites). JazzCleanAmpPedal (widener, .fender): mono core (with spring reverb + bright) → Chorus (mono → stereo split) → per-channel cabinetAndLimit. Controls: Gain/Bass/Mid/Treble + Reverb/Rate/Depth knobs, Bright + Chorus switches, Cab selector; widthUnits 3; defaults to the Full-Range cab for a hi-fi voice. The Chorus footswitch gates the wet mix to 0 (dry pass-through, Rate/Depth kept). Registered across registry/type/category/palette/enclosure; Help acknowledgment lists its tone stack. 10 tests (chorus rate/depth, reverb, bright, footswitch bit-exact bypass, ceiling with FX, stereo/control-surface config, round-trip, registry). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
147 lines
6.4 KiB
Swift
147 lines
6.4 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 left channel through a bare engine. As with the other widener-pedal suites, the
|
|
/// right channel needs a board stereo region, so this exercises the mono core → chorus.left →
|
|
/// cabinet path; the control-surface / stereo config is asserted directly below.
|
|
private func render(configure: (JazzCleanAmpPedal) -> Void = { _ in }) throws -> [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 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: JazzCleanAmpPedal = JazzCleanAmpPedal(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)
|
|
}
|
|
|
|
private func windowedSSD(_ a: [Float], _ b: [Float], skip: Int = 4096, window: Int = 4096) -> 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
|
|
}
|
|
}
|
|
|
|
@Test func buildsNonSilentFiniteOutput() throws {
|
|
let samples: [Float] = try render()
|
|
#expect(!samples.isEmpty)
|
|
#expect(hasNonSilentOutput(samples), "Jazz Clean produced silence")
|
|
#expect(samples.allSatisfy { $0.isFinite }, "Jazz Clean produced non-finite output")
|
|
}
|
|
|
|
@Test func chorusRateChangesOutput() throws {
|
|
let slow: [Float] = try render { $0.chorusRate = 0.2 }
|
|
let fast: [Float] = try render { $0.chorusRate = 5.0 }
|
|
#expect(windowedSSD(slow, fast) > 0, "chorus rate had no effect")
|
|
}
|
|
|
|
@Test func chorusDepthChangesOutput() throws {
|
|
let shallow: [Float] = try render { $0.chorusDepth = 0.05 }
|
|
let deep: [Float] = try render { $0.chorusDepth = 0.9 }
|
|
#expect(windowedSSD(shallow, deep) > 0, "chorus depth had no effect")
|
|
}
|
|
|
|
@Test func reverbMixChangesOutput() throws {
|
|
let dry: [Float] = try render { $0.reverb = 0.0 }
|
|
let wet: [Float] = try render { $0.reverb = 0.9 }
|
|
#expect(windowedSSD(dry, wet) > 0, "reverb mix had no effect")
|
|
}
|
|
|
|
@Test func brightSwitchChangesOutput() throws {
|
|
let flat: [Float] = try render { $0.bright = 0.0 }
|
|
let bright: [Float] = try render { $0.bright = 1.0 }
|
|
#expect(windowedSSD(flat, bright) > 0, "bright switch had no effect")
|
|
}
|
|
|
|
@Test func chorusFootswitchBypasses() throws {
|
|
// Off must differ from on; and with the chorus off the Rate knob is irrelevant (mix 0 →
|
|
// dry), so two off-renders at different rates are bit-identical.
|
|
let on: [Float] = try render { $0.chorusEnabled = 1.0; $0.chorusRate = 3.0 }
|
|
let off: [Float] = try render { $0.chorusEnabled = 0.0; $0.chorusRate = 3.0 }
|
|
#expect(windowedSSD(on, off) > 0, "chorus footswitch had no effect")
|
|
let offSlow: [Float] = try render { $0.chorusEnabled = 0.0; $0.chorusRate = 0.2 }
|
|
let offFast: [Float] = try render { $0.chorusEnabled = 0.0; $0.chorusRate = 5.0 }
|
|
#expect(windowedSSD(offSlow, offFast) == 0.0, "chorus off should ignore rate (dry pass-through)")
|
|
}
|
|
|
|
@Test func outputStaysWithinCeilingWithFXEngaged() throws {
|
|
let ceilingEpsilon: Double = 1.0e-4
|
|
let hot: [Float] = try render { (pedal: JazzCleanAmpPedal) in
|
|
pedal.gain = 30.0
|
|
pedal.bass = 1.0
|
|
pedal.treble = 1.0
|
|
pedal.reverb = 1.0
|
|
pedal.bright = 1.0
|
|
pedal.chorusDepth = 0.9
|
|
}
|
|
let peak: Double = hot.reduce(0.0) { Swift.max($0, abs(Double($1))) }
|
|
#expect(peak <= 1.0 + ceilingEpsilon, "peak \(peak) exceeds the ±1 ceiling")
|
|
#expect(peak > 0.3, "unexpectedly quiet at max gain: \(peak)")
|
|
}
|
|
|
|
@Test func exposesFullControlSurface() throws {
|
|
let pedal: JazzCleanAmpPedal = JazzCleanAmpPedal()
|
|
#expect(pedal.effectKnobs.map { $0.label }
|
|
== ["Gain", "Bass", "Mid", "Treble", "Reverb", "Rate", "Depth"])
|
|
#expect(pedal.effectSwitches.map { $0.label } == ["Bright", "Chorus"])
|
|
#expect(pedal.effectSelectors.map { $0.label } == ["Cab"])
|
|
#expect(pedal.effectSelectors.first?.rebuildsOnChange == true)
|
|
#expect(pedal.widthUnits == 3)
|
|
#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.4
|
|
pedal.bright = 1.0
|
|
pedal.chorusEnabled = 0.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.4)
|
|
#expect(restored.bright == 1.0)
|
|
#expect(restored.chorusEnabled == 0.0)
|
|
#expect(restored.cab == 3.0)
|
|
}
|
|
|
|
@Test func registeredInBuiltInRegistry() throws {
|
|
#expect(PedalRegistry.makePedal(type: "Jazz Clean") is JazzCleanAmpPedal)
|
|
}
|
|
}
|