Add Rotary (Leslie) pedal
Stereo rotary-speaker emulation: per-channel Doppler-swept delay (FM) plus correlated amplitude throb (AM) from one rotor LFO, left/right rotors in anti-phase for a rotating stereo image. Two-speed Chorale/Tremolo switch with an Accel knob that ramps the rotor rate via a Lag for authentic spin-up/spin-down. Depth scales both AM and FM. Runs as a .widener. Registered (PedalType + registry + enclosure color + palette slot) with build/non-silent, speed-change, control-surface, preset round-trip, and registry tests. Suite 232. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
// RotaryPedalTests.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("RotaryPedal")
|
||||
struct RotaryPedalTests {
|
||||
|
||||
private func render(
|
||||
configure: (RotaryPedal) -> Void
|
||||
) throws -> [Float] {
|
||||
let renderDuration: Double = 0.3
|
||||
let numAudioBuses: Int = 64
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
||||
duration: renderDuration,
|
||||
numAudioBuses: numAudioBuses
|
||||
)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||
let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 2)
|
||||
defer {
|
||||
engine.busAllocator.releaseAudioBus(srcBus)
|
||||
engine.busAllocator.releaseAudioBus(dstBus)
|
||||
}
|
||||
|
||||
let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
|
||||
let pedal: RotaryPedal = RotaryPedal(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)
|
||||
}
|
||||
|
||||
private func windowedSSD(_ a: [Float], _ b: [Float]) -> Double {
|
||||
let skipSamples: Int = 4096
|
||||
let windowSize: Int = 4096
|
||||
guard a.count >= skipSamples + windowSize,
|
||||
b.count >= skipSamples + windowSize else { return 0.0 }
|
||||
let aWindow: ArraySlice<Float> = a[skipSamples..<(skipSamples + windowSize)]
|
||||
let bWindow: ArraySlice<Float> = b[skipSamples..<(skipSamples + windowSize)]
|
||||
return zip(aWindow, bWindow).reduce(0.0) { acc, pair in
|
||||
let diff: Double = Double(pair.0 - pair.1)
|
||||
return acc + diff * diff
|
||||
}
|
||||
}
|
||||
|
||||
@Test func buildsAndProducesNonSilentOutput() throws {
|
||||
let samples: [Float] = try render { _ in }
|
||||
#expect(!samples.isEmpty)
|
||||
#expect(hasNonSilentOutput(samples), "rotary output was silent")
|
||||
}
|
||||
|
||||
@Test func speedChangesOutput() throws {
|
||||
let chorale: [Float] = try render { pedal in pedal.speed = 0.0; pedal.accel = 0.05 }
|
||||
let tremolo: [Float] = try render { pedal in pedal.speed = 1.0; pedal.accel = 0.05 }
|
||||
#expect(hasNonSilentOutput(tremolo), "fast rotary was silent")
|
||||
#expect(windowedSSD(chorale, tremolo) > 0, "changing speed did not change the output")
|
||||
}
|
||||
|
||||
@Test func exposesDepthAccelKnobsAndSpeedSwitch() throws {
|
||||
let pedal: RotaryPedal = RotaryPedal()
|
||||
#expect(pedal.effectKnobs.map { $0.label } == ["Depth", "Accel"])
|
||||
#expect(pedal.effectSwitches.map { $0.label } == ["Speed"])
|
||||
#expect(pedal.effectSwitches.first?.options.map { $0.title } == ["Chorale", "Tremolo"])
|
||||
}
|
||||
|
||||
@Test func presetRoundTripPreservesSpeed() throws {
|
||||
let pedal: RotaryPedal = RotaryPedal()
|
||||
pedal.speed = 1.0
|
||||
pedal.depth = 0.4
|
||||
let state: PedalState = pedal.captureState()
|
||||
|
||||
let restored: RotaryPedal = RotaryPedal()
|
||||
restored.applyState(state)
|
||||
#expect(restored.speed == 1.0)
|
||||
#expect(restored.depth == 0.4)
|
||||
}
|
||||
|
||||
@Test func registeredInBuiltInRegistry() throws {
|
||||
let pedal: Pedal? = PedalRegistry.makePedal(type: "Rotary")
|
||||
#expect(pedal is RotaryPedal)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user