// DelayPedalTests.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("DelayPedal") struct DelayPedalTests { @Test func buildsAndProducesNonSilentOutput() throws { // Render for longer than the default delay time (0.25 s) so echoes appear in the output. // The base Pedal blends wet (delay output) with dry via `mix`. With the default mix = 1.0 // the output is fully wet, meaning the first 0.25 s of output from `effect()` is silence // (the delay line hasn't filled yet). Use mix = 0.5 so the dry signal bleeds through. let renderDuration: Double = 0.5 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: DelayPedal = DelayPedal(inputBus: srcBus.index, outputBus: dstBus.index) // Use mix = 0.5 so the dry signal is present from frame 0, making the // non-silence check reliable without needing to wait for the full delay. pedal.mix = 0.5 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), "DelayPedal produced silence") } }