Files
ShoeGaze/Tests/LyrebirdShoeGazeTests/PedalBoardTests.swift
T
2026-06-21 12:25:18 -07:00

55 lines
2.0 KiB
Swift

// PedalBoardTests.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("PedalBoard")
struct PedalBoardTests {
@Test func twoPedalBoardRendersNonSilent() throws {
// Verify that a two-pedal chain produces non-silent output and that the second
// pedal receives the first pedal's output (the chain is wired correctly).
let renderDuration: Double = 0.2
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
duration: renderDuration,
numAudioBuses: 64
)
defer { try? FileManager.default.removeItem(at: url) }
let board: PedalBoard = try PedalBoard(engine: engine)
// Add the test loop source writing to the board head bus.
let source: TestLoopSource = TestLoopSource(targetBus: board.headBus.index)
try engine.add(source)
// Add two pedals to the chain.
// Pass `after: source` for the first pedal so it evaluates after the source in the
// node tree (source writes headBus → overdrive reads it → reverb reads overdrive out).
let overdrive: OverdrivePedal = OverdrivePedal()
let reverb: ReverbPedal = ReverbPedal()
try board.add(overdrive, after: source)
try board.add(reverb)
// Verify that the board tracks both pedals.
#expect(board.pedals.count == 2)
// A master to route the board output to hardware output.
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: board.outputBus.index)
try engine.add(master, position: NodePosition.after(reverb))
try engine.start()
let samples: [Float] = readStereoCAF(url: url)
#expect(!samples.isEmpty, "Two-pedal board produced no samples")
#expect(hasNonSilentOutput(samples), "Two-pedal board produced silence")
}
}