56 lines
2.4 KiB
Swift
56 lines
2.4 KiB
Swift
// AmplitudeFollowerParameterRampingTests.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Testing
|
|
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
|
|
|
@MainActor
|
|
@Suite("AmplitudeFollower parameter ramping")
|
|
struct AmplitudeFollowerParameterRampingTests {
|
|
|
|
@Test func attackTimeGeneratorInputIsRead() throws {
|
|
// Verify that wiring a ParameterNode to attackTime does not crash and produces output.
|
|
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
|
try engine.start()
|
|
defer { engine.stop() }
|
|
|
|
let attackNode: ParameterNode = ParameterNode(0.01)
|
|
let releaseNode: ParameterNode = ParameterNode(0.1)
|
|
let signal: OscSin.Audio = OscSin.Audio(freq: 440.0)
|
|
let follower: AmplitudeFollower.Audio = AmplitudeFollower.Audio(in: signal, attackTime: attackNode,
|
|
releaseTime: releaseNode)
|
|
|
|
let g: SynthGraph = makeSynthGraph(engine: engine)
|
|
let out: [[Double]] = follower.calculatedSamples(graph: g, count: 64)
|
|
#expect(out.count == 1, "AmplitudeFollower should produce 1 channel")
|
|
let hasEnergy: Bool = (out.first ?? []).prefix(64).contains { $0 > 0 }
|
|
#expect(hasEnergy, "AmplitudeFollower with sine input should produce non-zero output")
|
|
}
|
|
|
|
@Test func controlAttackTimeGeneratorInputIsRead() throws {
|
|
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
|
try engine.start()
|
|
defer { engine.stop() }
|
|
|
|
let attackNode: ParameterNode = ParameterNode(0.01)
|
|
let signal: OscSin.Audio = OscSin.Audio(freq: 440.0)
|
|
let follower: AmplitudeFollower.Control = AmplitudeFollower.Control(in: signal, attackTime: attackNode)
|
|
|
|
// Warm up one block to prime the follower.
|
|
let g1: SynthGraph = makeSynthGraph(engine: engine)
|
|
_ = follower.calculatedSamples(graph: g1, count: 64)
|
|
advanceBlock(engine)
|
|
|
|
// Change attack time via the ParameterNode and verify no crash/invalid output.
|
|
attackNode.value = 0.5
|
|
let g2: SynthGraph = makeSynthGraph(engine: engine)
|
|
let out2: [[Double]] = follower.calculatedSamples(graph: g2, count: 64)
|
|
let samples: [Double] = Array((out2.first ?? []).prefix(64))
|
|
#expect(samples.allSatisfy { $0.isFinite },
|
|
"AmplitudeFollower.Control output must remain finite after attackTime change")
|
|
}
|
|
}
|