Files
ShoeGaze/Tests/LyrebirdShoeGazeTests/FullertonDriveAmpPedalTests.swift
T
josh f9ddd6b160 feat(amp): Gain/Drive become a 1–11 dial with a musical taper
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>
2026-08-04 10:42:35 -07:00

129 lines
5.5 KiB
Swift

// FullertonDriveAmpPedalTests.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("FullertonDriveAmpPedal")
struct FullertonDriveAmpPedalTests {
private let sampleRate: Double = 48000.0
private func render(configure: (FullertonDriveAmpPedal) -> 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: FullertonDriveAmpPedal = FullertonDriveAmpPedal(
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(hasNonSilentOutput(samples), "Fullerton Drive produced silence")
#expect(samples.allSatisfy { $0.isFinite }, "Fullerton Drive produced non-finite output")
}
@Test func channelSwitchChangesOutput() throws {
// The value is read at build time (rebuildsOnChange); configure runs before build, so the
// Drive channel cascades its extra stage.
let clean: [Float] = try render { $0.channel = 0.0 }
let drive: [Float] = try render { $0.channel = 1.0; $0.drive = 9.0 }
#expect(hasNonSilentOutput(clean) && hasNonSilentOutput(drive))
#expect(windowedSSD(clean, drive) > 0, "channel switch had no effect")
}
@Test func driveKnobChangesDriveChannel() throws {
let low: [Float] = try render { $0.channel = 1.0; $0.drive = 2.0 }
let high: [Float] = try render { $0.channel = 1.0; $0.drive = 10.5 }
#expect(windowedSSD(low, high) > 0, "Drive knob had no effect on the drive channel")
}
@Test func reverbAndBrightChangeOutput() 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 had no effect")
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 channelSwitchRebuildsOnChange() throws {
let pedal: FullertonDriveAmpPedal = FullertonDriveAmpPedal()
let channel: PedalSwitch? = pedal.effectSwitches.first { $0.label == "Channel" }
#expect(channel?.rebuildsOnChange == true, "Channel switch should rebuild on change")
}
@Test func outputStaysWithinCeilingOnDriveChannel() throws {
let ceilingEpsilon: Double = 1.0e-4
let hot: [Float] = try render { (pedal: FullertonDriveAmpPedal) in
pedal.gain = 11.0
pedal.bass = 1.0
pedal.treble = 1.0
pedal.reverb = 1.0
pedal.bright = 1.0
pedal.channel = 1.0
pedal.drive = 11.0
}
let peak: Double = hot.reduce(0.0) { Swift.max($0, abs(Double($1))) }
#expect(peak <= 1.0 + ceilingEpsilon, "peak \(peak) exceeds the ±1 ceiling on the drive channel")
#expect(peak > 0.3, "unexpectedly quiet: \(peak)")
}
@Test func exposesControlSurface() throws {
let pedal: FullertonDriveAmpPedal = FullertonDriveAmpPedal()
#expect(pedal.effectKnobs.map { $0.label } == ["Gain", "Bass", "Mid", "Treble", "Reverb", "Drive"])
#expect(pedal.effectSwitches.map { $0.label } == ["Bright", "Channel"])
#expect(pedal.effectSelectors.map { $0.label } == ["Cab"])
#expect(pedal.widthUnits == 3)
#expect(pedal.toneStackModel == .fender)
}
@Test func controlsRoundTripThroughState() throws {
let pedal: FullertonDriveAmpPedal = FullertonDriveAmpPedal()
pedal.reverb = 0.6
pedal.drive = 8.3
pedal.bright = 1.0
pedal.channel = 1.0
pedal.cab = 2.0
let restored: FullertonDriveAmpPedal = FullertonDriveAmpPedal()
restored.applyState(pedal.captureState())
#expect(restored.reverb == 0.6 && restored.drive == 8.3)
#expect(restored.bright == 1.0 && restored.channel == 1.0 && restored.cab == 2.0)
}
@Test func registeredInBuiltInRegistry() throws {
#expect(PedalRegistry.makePedal(type: "Fullerton Drive") is FullertonDriveAmpPedal)
}
}