Files
ShoeGaze/Tests/LyrebirdShoeGazeTests/ChimeTopBoostAmpPedalTests.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

143 lines
6.1 KiB
Swift

// ChimeTopBoostAmpPedalTests.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("ChimeTopBoostAmpPedal")
struct ChimeTopBoostAmpPedalTests {
private let sampleRate: Double = 48000.0
private func render(configure: (ChimeTopBoostAmpPedal) -> 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: ChimeTopBoostAmpPedal = ChimeTopBoostAmpPedal(
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), "Chime Top Boost produced silence")
#expect(samples.allSatisfy { $0.isFinite }, "Chime Top Boost produced non-finite output")
}
@Test func cutChangesOutput() throws {
let open: [Float] = try render { $0.cut = 0.0 }
let dark: [Float] = try render { $0.cut = 1.0 }
#expect(windowedSSD(open, dark) > 0, "Cut had no effect")
}
@Test func tremoloIntensityChangesOutput() throws {
let off: [Float] = try render { $0.intensity = 0.0 }
let on: [Float] = try render { $0.intensity = 1.0; $0.speed = 6.0 }
#expect(windowedSSD(off, on) > 0, "tremolo intensity had no effect")
}
@Test func tremoloSpeedChangesOutput() throws {
let slow: [Float] = try render { $0.intensity = 1.0; $0.speed = 1.0 }
let fast: [Float] = try render { $0.intensity = 1.0; $0.speed = 10.0 }
#expect(windowedSSD(slow, fast) > 0, "tremolo speed had no effect")
}
@Test func brilliantSwitchChangesOutput() throws {
let flat: [Float] = try render { $0.brilliant = 0.0 }
let bright: [Float] = try render { $0.brilliant = 1.0 }
#expect(windowedSSD(flat, bright) > 0, "brilliant switch had no effect")
}
@Test func tremoloFootswitchBypassesToIdentity() throws {
// Footswitch off with Intensity up must equal no tremolo (Intensity 0), and differ from on.
// The differing `speed` is harmless: with depth gated to 0 the LFO is a constant 1.0.
let bypassed: [Float] = try render { $0.intensity = 1.0; $0.speed = 6.0; $0.tremoloEnabled = 0.0 }
let noTremolo: [Float] = try render { $0.intensity = 0.0 }
#expect(windowedSSD(bypassed, noTremolo) == 0.0, "tremolo footswitch off should be identity")
let engaged: [Float] = try render { $0.intensity = 1.0; $0.speed = 6.0; $0.tremoloEnabled = 1.0 }
#expect(windowedSSD(bypassed, engaged) > 0, "tremolo footswitch had no effect")
}
@Test func outputStaysWithinCeilingWithFXEngaged() throws {
let ceilingEpsilon: Double = 1.0e-4
let hot: [Float] = try render { (pedal: ChimeTopBoostAmpPedal) in
pedal.gain = 11.0
pedal.bass = 1.0
pedal.treble = 1.0
pedal.brilliant = 1.0
pedal.intensity = 1.0
pedal.speed = 6.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")
#expect(peak > 0.3, "unexpectedly quiet at max gain: \(peak)")
}
@Test func exposesFullControlSurface() throws {
let pedal: ChimeTopBoostAmpPedal = ChimeTopBoostAmpPedal()
#expect(pedal.effectKnobs.map { $0.label }
== ["Gain", "Bass", "Mid", "Treble", "Cut", "Speed", "Intensity"])
#expect(pedal.effectSwitches.map { $0.label } == ["Brilliant", "Tremolo"])
#expect(pedal.effectSelectors.map { $0.label } == ["Cab"])
#expect(pedal.effectSelectors.first?.rebuildsOnChange == true)
#expect(pedal.widthUnits == 3)
#expect(pedal.showsMixControl == false)
#expect(pedal.toneStackModel == .vox)
}
@Test func controlsRoundTripThroughState() throws {
let pedal: ChimeTopBoostAmpPedal = ChimeTopBoostAmpPedal()
pedal.gain = 7.0
pedal.cut = 0.6
pedal.speed = 9.0
pedal.intensity = 0.5
pedal.brilliant = 1.0
pedal.tremoloEnabled = 0.0
pedal.cab = 2.0
let restored: ChimeTopBoostAmpPedal = ChimeTopBoostAmpPedal()
restored.applyState(pedal.captureState())
#expect(restored.gain == 7.0)
#expect(restored.cut == 0.6)
#expect(restored.speed == 9.0)
#expect(restored.intensity == 0.5)
#expect(restored.brilliant == 1.0)
#expect(restored.tremoloEnabled == 0.0)
#expect(restored.cab == 2.0)
}
@Test func registeredInBuiltInRegistry() throws {
#expect(PedalRegistry.makePedal(type: "Chime Top Boost") is ChimeTopBoostAmpPedal)
}
}