// Trig1AudioTests.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth @MainActor @Suite("Trig1.Audio") struct Trig1AudioTests { let engine: SynthesisEngine var graph: SynthGraph { makeSynthGraph(engine: engine) } let blockSize: Int = 64 init() throws { engine = makeTestEngine(blockSize: 64, sampleRate: 44100) try engine.start() } @Test func rateIsAudio() { let gen: Trig1.Audio = Trig1.Audio(input: 0.0, dur: 0.1) #expect(gen.rate == .audio) } /// Constant-zero input produces no rising edge; output stays at 0. @Test func noTriggerOutputsZero() { let gen: Trig1.Audio = Trig1.Audio(input: 0.0, dur: 0.1) let out: [Double] = gen.calculatedSamples(graph: graph, count: blockSize)[0] for i: Int in 0.. 0 (no falling edge) produces only one pulse. @Test func sustainedTrigProducesOnePulse() { let durSamples: Int = 8 let dur: Double = Double(durSamples) / 44100.0 // Input stays at 0.5 from sample 10 onwards (no falling edge → no second pulse). let input: Closure = Closure { _, i in i >= 10 ? 0.5 : 0.0 } let gen: Trig1.Audio = Trig1.Audio(input: input, dur: dur) let out: [Double] = gen.calculatedSamples(graph: graph, count: blockSize)[0] // Pulse samples: 10..(10+durSamples-1) = 1.0. for i: Int in 10..<(10 + durSamples) { #expect(abs(out[i] - 1.0) < 1e-12, "pulse sample \(i) expected 1.0 got \(out[i])") } // After pulse: 0 (trig still high but no new edge — no re-fire). for i: Int in (10 + durSamples)..