1de14fd879
Phase 11. Promote Sag from Modern High-Gain to a shared AmpVoicePedal capability and add a Bias control, both surfaced in a new pedal-card pop-over rather than on the amp face. - AmpVoicePedal gains `sag` [0,1] (AmplitudeFollower gain-droop, clamped [0.15,1] to prevent phase inversion) and `bias` [0,1] mapped to the power-amp TriodeStage grid bias ([-0.25,0.25], neutral 0.5 → 0.0 so existing voices are unchanged at defaults). Both applied in preCabinetCore; new `applySag(_:)` + `powerAmpBiasInput` helpers. - Modern High-Gain drops its bespoke sag (now inherited); keeps sag=0.3 default. Sag moves off its face into the pop-over. - Pedal gains an `advancedKnobs` surface; PedalView draws a gear button (top-right) presenting them in a popover, reusing the existing pattern. - Advanced knobs round-trip through PedalState (new `advancedValues`, backward-compatible decode) and are MIDI-CC-mappable (appended last). De-branding (review nits): "Vox" removed from the Chime family's user-visible summaries + docs; "Fullerton Princeton" renamed to display "Fullerton Ivy League". Palette horizontal picker second row now shows Routing before the Amp Model group. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
125 lines
6.0 KiB
Swift
125 lines
6.0 KiB
Swift
// ModernHighGainAmpPedalTests.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("ModernHighGainAmpPedal")
|
|
struct ModernHighGainAmpPedalTests {
|
|
|
|
private let sampleRate: Double = 48000.0
|
|
|
|
private func render(configure: (ModernHighGainAmpPedal) -> 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: ModernHighGainAmpPedal = ModernHighGainAmpPedal(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 buildsNonSilentFiniteWithinCeiling() throws {
|
|
let hot: [Float] = try render { (p: ModernHighGainAmpPedal) in
|
|
p.gain = 30.0; p.bass = 1.0; p.treble = 1.0; p.master = 1.0; p.channel = 1.0
|
|
p.drive = 30.0; p.sag = 1.0; p.tight = 1.0
|
|
}
|
|
#expect(hasNonSilentOutput(hot) && hot.allSatisfy { $0.isFinite })
|
|
let peak: Double = hot.reduce(0.0) { Swift.max($0, abs(Double($1))) }
|
|
#expect(peak <= 1.0 + 1.0e-4, "Modern High-Gain exceeds the ±1 ceiling: \(peak)")
|
|
}
|
|
|
|
@Test func sagChangesOutput() throws {
|
|
let stiff: [Float] = try render { $0.gain = 20.0; $0.channel = 1.0; $0.sag = 0.0 }
|
|
let saggy: [Float] = try render { $0.gain = 20.0; $0.channel = 1.0; $0.sag = 1.0 }
|
|
#expect(windowedSSD(stiff, saggy) > 0, "Sag had no effect")
|
|
}
|
|
|
|
@Test func sagAttenuatesWithoutPhaseInversion() throws {
|
|
// With Presence/Depth maxed the shelf boosts push the sag envelope above 1; the sag gain
|
|
// must stay positive (attenuation), never go negative (phase inversion). Assert the sag'd
|
|
// output correlates positively with the stiff one (not an inverted copy).
|
|
let cfg: (ModernHighGainAmpPedal) -> Void = { (p: ModernHighGainAmpPedal) in
|
|
p.gain = 20.0; p.channel = 1.0; p.presence = 1.0; p.depth = 1.0
|
|
}
|
|
let stiff: [Float] = try render { cfg($0); $0.sag = 0.0 }
|
|
let saggy: [Float] = try render { cfg($0); $0.sag = 1.0 }
|
|
let skip: Int = 4096, window: Int = 4096
|
|
guard stiff.count >= skip + window, saggy.count >= skip + window else {
|
|
Issue.record("render too short"); return
|
|
}
|
|
// Unnormalized dot product — its sign is what matters: negative ⇒ phase-inverted copy.
|
|
let dotProduct: Double = zip(stiff[skip..<(skip + window)], saggy[skip..<(skip + window)])
|
|
.reduce(0.0) { acc, pair in acc + Double(pair.0) * Double(pair.1) }
|
|
#expect(dotProduct > 0, "sag phase-inverted the signal (dot product \(dotProduct) < 0)")
|
|
}
|
|
|
|
@Test func tightSwitchChangesOutput() throws {
|
|
let loose: [Float] = try render { $0.tight = 0.0 }
|
|
let tight: [Float] = try render { $0.tight = 1.0 }
|
|
#expect(windowedSSD(loose, tight) > 0, "Tight switch had no effect")
|
|
}
|
|
|
|
@Test func channelSwitchInherited() 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? = ModernHighGainAmpPedal().effectSwitches.first { $0.label == "Channel" }
|
|
#expect(channel?.rebuildsOnChange == true)
|
|
}
|
|
|
|
@Test func exposesControlSurface() throws {
|
|
let pedal: ModernHighGainAmpPedal = ModernHighGainAmpPedal()
|
|
// Sag now lives in the shared advanced pop-over (with Bias), not on the pedal face.
|
|
#expect(pedal.effectKnobs.map { $0.label }
|
|
== ["Gain", "Bass", "Mid", "Treble", "Presence", "Depth", "Master", "Drive"])
|
|
#expect(pedal.advancedKnobs.map { $0.label } == ["Sag", "Bias"])
|
|
#expect(pedal.effectSwitches.map { $0.label } == ["Channel", "Tight"])
|
|
#expect(pedal.widthUnits == 4)
|
|
#expect(pedal.toneStackModel == .mesa)
|
|
#expect(pedal.sag == 0.3, "Modern High-Gain keeps rectifier sag on by default")
|
|
}
|
|
|
|
@Test func controlsRoundTripThroughState() throws {
|
|
let pedal: ModernHighGainAmpPedal = ModernHighGainAmpPedal()
|
|
pedal.sag = 0.8; pedal.tight = 1.0; pedal.channel = 1.0
|
|
pedal.drive = 20.0; pedal.master = 0.7; pedal.cab = 2.0
|
|
let restored: ModernHighGainAmpPedal = ModernHighGainAmpPedal()
|
|
restored.applyState(pedal.captureState())
|
|
#expect(restored.sag == 0.8 && restored.tight == 1.0 && restored.channel == 1.0)
|
|
#expect(restored.drive == 20.0 && restored.master == 0.7 && restored.cab == 2.0)
|
|
}
|
|
|
|
@Test func registeredInBuiltInRegistry() throws {
|
|
#expect(PedalRegistry.makePedal(type: "Modern High-Gain") is ModernHighGainAmpPedal)
|
|
}
|
|
}
|