965633de34
New "Vibe" pedal: a photocell-style vibe built as four staggered all-pass stages swept by one shared sine LFO (unequal centre frequencies give the uneven, vocal throb that distinguishes a vibe from a phaser). Speed and Intensity knobs, Chorus/Vibrato mode switch (chorus blends dry+swept, vibrato passes swept only). Composed from RBJAllPass in effect(), mirroring PhaserPedal — no new RT generator. Registered in PedalType/PedalRegistry, enclosure colour, and palette order. Tests cover build+non-silent, each control measurably changing output, the knob/switch listing, and preset round-trip. Adds the Psychedelic Vibe Lead factory rig (Fuzz -> Vibe -> Delay -> Plate). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
105 lines
3.9 KiB
Swift
105 lines
3.9 KiB
Swift
// VibePedalTests.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("VibePedal")
|
|
struct VibePedalTests {
|
|
|
|
/// Renders the test loop through a vibe pedal configured by `configure`, returning stereo samples.
|
|
private func render(configure: (VibePedal) -> 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: VibePedal = VibePedal(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), "VibePedal produced silence")
|
|
}
|
|
|
|
@Test func speedChangesOutput() throws {
|
|
let slow: [Float] = try render { $0.speed = 1.0 }
|
|
let fast: [Float] = try render { $0.speed = 8.0 }
|
|
#expect(hasNonSilentOutput(slow))
|
|
#expect(hasNonSilentOutput(fast))
|
|
#expect(windowSSD(slow, fast) > 0, "vibe speed did not change output")
|
|
}
|
|
|
|
@Test func intensityChangesOutput() throws {
|
|
let shallow: [Float] = try render { $0.intensity = 0.1 }
|
|
let deep: [Float] = try render { $0.intensity = 0.7 }
|
|
#expect(windowSSD(shallow, deep) > 0, "vibe intensity did not change output")
|
|
}
|
|
|
|
@Test func modeChangesOutput() throws {
|
|
let chorus: [Float] = try render { $0.mode = 0.0 }
|
|
let vibrato: [Float] = try render { $0.mode = 1.0 }
|
|
#expect(hasNonSilentOutput(chorus))
|
|
#expect(hasNonSilentOutput(vibrato))
|
|
#expect(windowSSD(chorus, vibrato) > 0, "chorus and vibrato modes produced identical output")
|
|
}
|
|
|
|
@Test func exposesSpeedIntensityKnobsAndModeSwitch() {
|
|
let pedal: VibePedal = VibePedal()
|
|
#expect(pedal.effectKnobs.map { $0.label } == ["Speed", "Intensity"])
|
|
#expect(pedal.effectSwitches.map { $0.label } == ["Mode"])
|
|
#expect(pedal.effectSwitches.first?.options.map { $0.title } == ["Chorus", "Vibrato"])
|
|
}
|
|
|
|
@Test func stateRoundTripsThroughPreset() {
|
|
let pedal: VibePedal = VibePedal()
|
|
pedal.speed = 6.5
|
|
pedal.intensity = 0.42
|
|
pedal.mode = 1.0
|
|
|
|
let state: PedalState = pedal.captureState()
|
|
let restored: VibePedal = VibePedal()
|
|
restored.applyState(state)
|
|
|
|
#expect(restored.speed == 6.5)
|
|
#expect(restored.intensity == 0.42)
|
|
#expect(restored.mode == 1.0)
|
|
}
|
|
}
|