57 lines
2.1 KiB
Swift
57 lines
2.1 KiB
Swift
// LinCongSteppedControlTests.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Foundation
|
|
import Testing
|
|
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
|
|
|
// MARK: - LinCongSteppedControlTests
|
|
|
|
@MainActor
|
|
@Suite("LinCongStepped.Control")
|
|
struct LinCongSteppedControlTests {
|
|
|
|
let engine: SynthesisEngine
|
|
let sr: Double = 44100
|
|
|
|
init() throws {
|
|
engine = makeTestEngine(blockSize: 64, sampleRate: 44100)
|
|
try engine.start()
|
|
}
|
|
|
|
@Test func freqZeroRampsToPrimedValue() {
|
|
let lc: LinCongStepped.Control = LinCongStepped.Control(freq: 0.0)
|
|
let g: SynthGraph = makeSynthGraph(engine: engine)
|
|
let s: [[Double]] = lc.calculatedSamples(graph: g, count: engine.blockSize)
|
|
#expect(abs(s[0][engine.blockSize - 1] - 0.273) < 1e-12)
|
|
}
|
|
|
|
@Test func finiteBoundedOutput() {
|
|
let lc: LinCongStepped.Control = LinCongStepped.Control(freq: 200.0)
|
|
let samples: [Double] = collectBlocks(lc, engine: engine, blocks: 40)
|
|
#expect(samples.allSatisfy { $0.isFinite })
|
|
#expect(samples.allSatisfy { $0 >= 0.0 && $0 < 1.0 })
|
|
}
|
|
|
|
@Test func twoInstancesProduceIdenticalOutput() throws {
|
|
let a1: LinCongStepped.Control = LinCongStepped.Control(freq: 500.0)
|
|
let s1: [Double] = collectBlocks(a1, engine: engine, blocks: 20)
|
|
let engine2: SynthesisEngine = makeTestEngine(blockSize: 64, sampleRate: sr)
|
|
try engine2.start()
|
|
let a2: LinCongStepped.Control = LinCongStepped.Control(freq: 500.0)
|
|
let s2: [Double] = collectBlocks(a2, engine: engine2, blocks: 20)
|
|
#expect(s1 == s2)
|
|
}
|
|
|
|
@Test func participatesInFanOutCache() {
|
|
let lc: LinCongStepped.Control = LinCongStepped.Control(freq: 500.0)
|
|
let g: SynthGraph = makeSynthGraph(engine: engine)
|
|
let r1: [[Double]] = lc.calculatedSamples(graph: g, count: engine.blockSize)
|
|
let r2: [[Double]] = lc.calculatedSamples(graph: g, count: engine.blockSize)
|
|
#expect(r1[0].prefix(engine.blockSize).elementsEqual(r2[0].prefix(engine.blockSize)))
|
|
}
|
|
}
|