Files
ShoeGaze/Tests/LyrebirdShoeGazeTests/FeedbackDelayPedalTests.swift
T
josh c28e7cac90 Add four pedals: Mu-Tron, Auto-Wah, Feedback Delay, Multi-Tap Delay
Two envelope filters and two delays, registered in PedalRegistry and
showcased on demo Board 3.

- Mu-Tron: wraps the MuTronIII generator; three parallel LP/BP/HP
  instances switched live by a Select on the mode knob so filter state
  stays warmed across mode changes. Knobs: Mode, Sensitivity, Resonance.
- Auto-Wah: explicit amplitude-tracking chain — AmplitudeFollower scaled
  by sensitivity, clamped, mapped through LinExp to a swept SVF bandpass.
  Knobs: Sensitivity, Resonance, Range.
- Feedback Delay: DelayLineFeedback (cubic) into an RBJ lowpass for a
  darker, tape-style multi-repeat echo. Knobs: Time, Feedback, Tone.
- Multi-Tap Delay: three non-feedback DelayLine taps summed, per-tap
  volume folded into each tap's mul. Six knobs in two rows of three.

Bumps the Lyrebird dependency to 1.2.0 for the MuTronIII/SVF generators.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 15:07:34 -07:00

106 lines
4.3 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// FeedbackDelayPedalTests.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("FeedbackDelayPedal")
struct FeedbackDelayPedalTests {
@Test func buildsAndProducesNonSilentOutput() throws {
let renderDuration: Double = 0.3
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: FeedbackDelayPedal = FeedbackDelayPedal(
inputBus: srcBus.index,
outputBus: dstBus.index
)
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()
let samples: [Float] = readStereoCAF(url: url)
#expect(!samples.isEmpty)
#expect(hasNonSilentOutput(samples), "FeedbackDelayPedal produced silence")
}
@Test func feedbackChangesOutput() throws {
// Render well past the first echo (time = 0.3 s) so regenerated repeats differ.
let renderDuration: Double = 0.8
let numAudioBuses: Int = 64
func renderWithFeedback(_ feedbackValue: Double) throws -> [Float] {
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: 1)
defer {
engine.busAllocator.releaseAudioBus(srcBus)
engine.busAllocator.releaseAudioBus(dstBus)
}
let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
let pedal: FeedbackDelayPedal = FeedbackDelayPedal(
inputBus: srcBus.index,
outputBus: dstBus.index
)
pedal.feedback = feedbackValue
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)
}
let shortFeedback: [Float] = try renderWithFeedback(0.2)
let longFeedback: [Float] = try renderWithFeedback(6.0)
#expect(hasNonSilentOutput(shortFeedback), "short-feedback render was silent")
#expect(hasNonSilentOutput(longFeedback), "long-feedback render was silent")
// Start the window after the second repeat (~0.6 s × 44100 × 2 channels).
let skipSamples: Int = 53000
let windowSize: Int = 2048
guard shortFeedback.count >= skipSamples + windowSize,
longFeedback.count >= skipSamples + windowSize else { return }
let shortWindow: [Float] = Array(shortFeedback[skipSamples..<(skipSamples + windowSize)])
let longWindow: [Float] = Array(longFeedback[skipSamples..<(skipSamples + windowSize)])
let ssd: Double = zip(shortWindow, longWindow).reduce(0.0) { acc, pair in
let diff: Double = Double(pair.0 - pair.1)
return acc + diff * diff
}
#expect(ssd > 0, "short and long feedback produced identical output")
}
@Test func exposesTimeFeedbackAndToneKnobs() throws {
let pedal: FeedbackDelayPedal = FeedbackDelayPedal()
let labels: [String] = pedal.effectKnobs.map { $0.label }
#expect(labels == ["Time", "Feedback", "Tone"])
}
}