79 lines
3.0 KiB
Swift
79 lines
3.0 KiB
Swift
// TremoloPedalTests.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("TremoloPedal")
|
|
struct TremoloPedalTests {
|
|
|
|
@Test func buildsAndProducesNonSilentOutput() throws {
|
|
let renderDuration: Double = 0.2
|
|
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: TremoloPedal = TremoloPedal(
|
|
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), "TremoloPedal produced silence")
|
|
}
|
|
|
|
@Test func depthZeroPassesSignalUnmodified() throws {
|
|
// With depth = 0 the LFO multiplier is 1.0 — output should match a pedal
|
|
// whose mix is also 1.0 but with no tremolo (depth = 0 means no modulation).
|
|
// We verify the render is non-silent (signal passes through) without
|
|
// checking exact sample equality across different engine instances.
|
|
let renderDuration: Double = 0.1
|
|
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: TremoloPedal = TremoloPedal(
|
|
inputBus: srcBus.index,
|
|
outputBus: dstBus.index
|
|
)
|
|
pedal.depth = 0.0
|
|
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(hasNonSilentOutput(samples), "TremoloPedal depth=0 produced silence — signal was muted")
|
|
}
|
|
}
|