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