f9ddd6b160
Every amp's Gain (and the boutique/drive-channel Drive) is now a 1–11 dial — yes, it goes to eleven — instead of the raw 1–30 tube-drive number. - New AmpVoicePedal.taperedDrive(_:) maps the 1–11 dial to the 1–30 tube drive through an exponential LinExp taper, so 1 is nearly clean, 11 is full saturation, and the useful grind spreads across the dial (fine at the bottom, steep at the top) rather than bunching near the low end. - Wired into the base preampStage and every override that feeds a drive: Boutique / Fullerton Drive / Jazz Clean / British Dual (Drive channel), Anaheim (SS preamp), British Master (cascaded stage). - gainRange / driveRange → 1...11; every amp's default gain/drive reconverted from drive-space to the equivalent dial value (dial = 1 + 10·ln(drive)/ln(30)), so each amp's shipped voicing is preserved. - No preset migration (nothing shipped — per product owner); all knob work stays within ShoeGaze (no core Lyrebird change). - Tests updated to the 1–11 scale; added range + exponential-taper assertions. 671 tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
106 lines
4.7 KiB
Swift
106 lines
4.7 KiB
Swift
// CaliHiGainAmpPedalTests.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("CaliHiGainAmpPedal")
|
|
struct CaliHiGainAmpPedalTests {
|
|
|
|
private let sampleRate: Double = 48000.0
|
|
|
|
private func render(configure: (CaliHiGainAmpPedal) -> 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: CaliHiGainAmpPedal = CaliHiGainAmpPedal(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 s: [Float] = try render()
|
|
#expect(hasNonSilentOutput(s) && s.allSatisfy { $0.isFinite })
|
|
}
|
|
|
|
@Test func graphicEQBandsChangeOutput() throws {
|
|
// Each band moves the tone: sweep the mid-scoop band and an outer band.
|
|
let midCut: [Float] = try render { $0.eq750 = -12.0 }
|
|
let midBoost: [Float] = try render { $0.eq750 = 12.0 }
|
|
#expect(windowedSSD(midCut, midBoost) > 0, "750 Hz band had no effect")
|
|
let trebleFlat: [Float] = try render { $0.eq6600 = 0.0 }
|
|
let trebleBoost: [Float] = try render { $0.eq6600 = 12.0 }
|
|
#expect(windowedSSD(trebleFlat, trebleBoost) > 0, "6.6 kHz band had no effect")
|
|
}
|
|
|
|
@Test func inheritedChannelAndMasterWork() throws {
|
|
let clean: [Float] = try render { $0.channel = 0.0 }
|
|
let lead: [Float] = try render { $0.channel = 1.0 }
|
|
#expect(windowedSSD(clean, lead) > 0, "channel switch had no effect")
|
|
let channel: PedalSwitch? = CaliHiGainAmpPedal().effectSwitches.first { $0.label == "Channel" }
|
|
#expect(channel?.rebuildsOnChange == true)
|
|
}
|
|
|
|
@Test func staysWithinCeilingWithEQAndGainMaxed() throws {
|
|
let hot: [Float] = try render { (p: CaliHiGainAmpPedal) in
|
|
p.gain = 11.0; p.bass = 1.0; p.treble = 1.0; p.master = 1.0; p.channel = 1.0; p.drive = 11.0
|
|
p.eq80 = 12.0; p.eq240 = 12.0; p.eq750 = 12.0; p.eq2200 = 12.0; p.eq6600 = 12.0
|
|
}
|
|
let peak: Double = hot.reduce(0.0) { Swift.max($0, abs(Double($1))) }
|
|
#expect(peak <= 1.0 + 1.0e-4, "Cali Hi-Gain exceeds the ±1 ceiling with EQ + gain maxed: \(peak)")
|
|
}
|
|
|
|
@Test func exposesControlSurface() throws {
|
|
let pedal: CaliHiGainAmpPedal = CaliHiGainAmpPedal()
|
|
#expect(pedal.effectKnobs.map { $0.label }
|
|
== ["Gain", "Bass", "Mid", "Treble", "Presence", "Depth", "Master", "Drive"])
|
|
#expect(pedal.effectSliders.map { $0.label } == ["80", "240", "750", "2.2k", "6.6k"])
|
|
#expect(pedal.effectSwitches.map { $0.label } == ["Channel"])
|
|
#expect(pedal.widthUnits == 4)
|
|
#expect(pedal.toneStackModel == .mesa)
|
|
}
|
|
|
|
@Test func controlsRoundTripThroughState() throws {
|
|
let pedal: CaliHiGainAmpPedal = CaliHiGainAmpPedal()
|
|
pedal.eq80 = 4.0; pedal.eq750 = -8.0; pedal.eq6600 = 6.0
|
|
pedal.channel = 1.0; pedal.master = 0.7; pedal.cab = 2.0
|
|
let restored: CaliHiGainAmpPedal = CaliHiGainAmpPedal()
|
|
restored.applyState(pedal.captureState())
|
|
#expect(restored.eq80 == 4.0 && restored.eq750 == -8.0 && restored.eq6600 == 6.0)
|
|
#expect(restored.channel == 1.0 && restored.master == 0.7 && restored.cab == 2.0)
|
|
}
|
|
|
|
@Test func registeredInBuiltInRegistry() throws {
|
|
#expect(PedalRegistry.makePedal(type: "Cali Hi-Gain") is CaliHiGainAmpPedal)
|
|
}
|
|
}
|