75b99a547b
New "Sustain Fuzz": a mid-scooped, high-sustain fuzz distinct from the single-stage Fuzz. Two cascaded soft-clip (softClipNormalized) stages compress and stack harmonics for smooth violin-like sustain; a fixed midrange scoop (RBJPeakingEQ cut at 750 Hz) hollows the mids; a tone low-pass sets the top end. Sustain/Tone/Scoop knobs. Composed in effect(), no new RT generator. Registered in PedalType/PedalRegistry, enclosure colour, palette order. Tests cover build+non-silent, each knob changing output, knob listing, preset round-trip. Adds two factory rigs: Comfortably Numb Lead and Doom Riff Wall. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
101 lines
3.8 KiB
Swift
101 lines
3.8 KiB
Swift
// SustainFuzzPedalTests.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("SustainFuzzPedal")
|
|
struct SustainFuzzPedalTests {
|
|
|
|
/// Renders the test loop through a sustain-fuzz configured by `configure`, returning stereo samples.
|
|
private func render(configure: (SustainFuzzPedal) -> Void) throws -> [Float] {
|
|
let renderDuration: Double = 0.2
|
|
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: renderDuration)
|
|
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: SustainFuzzPedal = SustainFuzzPedal(inputBus: srcBus.index, outputBus: dstBus.index)
|
|
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)
|
|
}
|
|
|
|
/// Sum of squared differences over a mid-render window, guarding on length.
|
|
private func windowSSD(_ a: [Float], _ b: [Float]) -> Double {
|
|
let skip: Int = 1024
|
|
let window: Int = 2048
|
|
guard a.count >= skip + window, b.count >= skip + window else { return 0 }
|
|
let aw: ArraySlice<Float> = a[skip..<(skip + window)]
|
|
let bw: ArraySlice<Float> = b[skip..<(skip + window)]
|
|
return zip(aw, bw).reduce(0.0) { acc, pair in
|
|
let d: Double = Double(pair.0 - pair.1)
|
|
return acc + d * d
|
|
}
|
|
}
|
|
|
|
@Test func buildsAndProducesNonSilentOutput() throws {
|
|
let samples: [Float] = try render { _ in }
|
|
#expect(!samples.isEmpty)
|
|
#expect(hasNonSilentOutput(samples), "SustainFuzzPedal produced silence")
|
|
}
|
|
|
|
@Test func sustainChangesOutput() throws {
|
|
let low: [Float] = try render { $0.sustain = 2.0 }
|
|
let high: [Float] = try render { $0.sustain = 25.0 }
|
|
#expect(hasNonSilentOutput(low))
|
|
#expect(hasNonSilentOutput(high))
|
|
#expect(windowSSD(low, high) > 0, "sustain did not change output")
|
|
}
|
|
|
|
@Test func toneChangesOutput() throws {
|
|
let dark: [Float] = try render { $0.tone = 900.0 }
|
|
let bright: [Float] = try render { $0.tone = 5500.0 }
|
|
#expect(windowSSD(dark, bright) > 0, "tone did not change output")
|
|
}
|
|
|
|
@Test func scoopChangesOutput() throws {
|
|
let flat: [Float] = try render { $0.scoop = 0.0 }
|
|
let scooped: [Float] = try render { $0.scoop = 16.0 }
|
|
#expect(windowSSD(flat, scooped) > 0, "scoop did not change output")
|
|
}
|
|
|
|
@Test func exposesSustainToneScoopKnobs() {
|
|
let pedal: SustainFuzzPedal = SustainFuzzPedal()
|
|
#expect(pedal.effectKnobs.map { $0.label } == ["Sustain", "Tone", "Scoop"])
|
|
}
|
|
|
|
@Test func stateRoundTripsThroughPreset() {
|
|
let pedal: SustainFuzzPedal = SustainFuzzPedal()
|
|
pedal.sustain = 18.0
|
|
pedal.tone = 3200.0
|
|
pedal.scoop = 12.0
|
|
|
|
let state: PedalState = pedal.captureState()
|
|
let restored: SustainFuzzPedal = SustainFuzzPedal()
|
|
restored.applyState(state)
|
|
|
|
#expect(restored.sustain == 18.0)
|
|
#expect(restored.tone == 3200.0)
|
|
#expect(restored.scoop == 12.0)
|
|
}
|
|
}
|