1.0.0 release
This commit is contained in:
@@ -0,0 +1,311 @@
|
||||
// Gendy1Tests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
@Suite("Gendy1")
|
||||
struct Gendy1Tests {
|
||||
|
||||
// MARK: - Rate
|
||||
|
||||
@Test func rateIsAudio() {
|
||||
let gen: Gendy1.Audio = Gendy1.Audio()
|
||||
#expect(gen.rate == .audio)
|
||||
}
|
||||
|
||||
// MARK: - Output count
|
||||
|
||||
@Test func outputCountMatchesRequest() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy1.Audio = Gendy1.Audio(seed: 1)
|
||||
let out: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
#expect(Array(out[0].prefix(64)).count == 64)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Fan-out
|
||||
|
||||
@Test func fanOutReturnsCachedResult() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy1.Audio = Gendy1.Audio(seed: 2)
|
||||
let out1: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
let out2: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
#expect(Array(out1[0].prefix(64)) == Array(out2[0].prefix(64)))
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - State advances once per block
|
||||
|
||||
@Test func stateAdvancesOncePerBlock() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
var graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy1.Audio = Gendy1.Audio(seed: 3)
|
||||
let block1a: [Double] = Array(gen.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
// Second call in same segment: cache hit, no double advance.
|
||||
let block1b: [Double] = Array(gen.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
#expect(block1a == block1b)
|
||||
// Advance to next segment.
|
||||
advanceBlock(engine)
|
||||
graph = makeSynthGraph(engine: engine)
|
||||
let block2: [Double] = Array(gen.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
// Block 2 must differ from block 1 (state advanced, different interpolation position).
|
||||
#expect(block2 != block1a)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Output stays in [-1, 1] with mul=1
|
||||
|
||||
@Test func outputStaysInRange() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
var graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy1.Audio = Gendy1.Audio(seed: 4)
|
||||
for _ in 0..<20 {
|
||||
graph = makeSynthGraph(engine: engine)
|
||||
let out: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
for i: Int in 0..<64 {
|
||||
#expect(out[0][i] >= -1.0 && out[0][i] <= 1.0,
|
||||
"sample \(i) out of [-1,1]: \(out[0][i])")
|
||||
}
|
||||
advanceBlock(engine)
|
||||
}
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Non-silent output
|
||||
|
||||
@Test func producesNonSilentOutput() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy1.Audio = Gendy1.Audio(seed: 5)
|
||||
let out: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
let nonZero: Bool = out[0].prefix(64).contains { $0 != 0.0 }
|
||||
#expect(nonZero)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Deterministic output with fixed seed
|
||||
|
||||
@Test func deterministicOutputWithSeed() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen1: Gendy1.Audio = Gendy1.Audio(seed: 99)
|
||||
let gen2: Gendy1.Audio = Gendy1.Audio(seed: 99)
|
||||
let out1: [Double] = Array(gen1.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
let out2: [Double] = Array(gen2.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
#expect(out1 == out2)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Different seeds produce different output
|
||||
|
||||
@Test func differentSeedsProduceDifferentOutput() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen1: Gendy1.Audio = Gendy1.Audio(seed: 100)
|
||||
let gen2: Gendy1.Audio = Gendy1.Audio(seed: 200)
|
||||
let out1: [Double] = Array(gen1.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
let out2: [Double] = Array(gen2.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
#expect(out1 != out2)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - ampscale=0 produces very stable waveform
|
||||
|
||||
@Test func ampScaleZeroProducesStableWaveform() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
var graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
// With ampscale=0, amplitude breakpoints cannot drift.
|
||||
let gen: Gendy1.Audio = Gendy1.Audio(ampscale: 0.0, durscale: 0.0, seed: 7)
|
||||
// Run two blocks; since neither amplitude nor duration changes, waveform repeats.
|
||||
let block1: [Double] = Array(gen.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
advanceBlock(engine)
|
||||
graph = makeSynthGraph(engine: engine)
|
||||
let block2: [Double] = Array(gen.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
// With zero scale, the waveform pattern should be stable. Both blocks are in [-1,1].
|
||||
for sample: Double in block1 { #expect(sample >= -1.0 && sample <= 1.0) }
|
||||
for sample: Double in block2 { #expect(sample >= -1.0 && sample <= 1.0) }
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - mulAdd scales output
|
||||
|
||||
@Test func mulAddScalesOutput() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let genPlain: Gendy1.Audio = Gendy1.Audio(seed: 42)
|
||||
let genMulAdd: Gendy1.Audio = Gendy1.Audio(mul: 2.0, add: 1.0, seed: 42)
|
||||
let plain: [Double] = Array(genPlain.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
let scaled: [Double] = Array(genMulAdd.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
for i: Int in 0..<64 {
|
||||
let expected: Double = plain[i] * 2.0 + 1.0
|
||||
#expect(abs(scaled[i] - expected) < 1e-9, "sample \(i): expected \(expected), got \(scaled[i])")
|
||||
}
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Integration
|
||||
|
||||
@Test func integrationRunsWithoutCrash() throws {
|
||||
final class Gendy1Synth: SynthesizerBase {
|
||||
override func build() {
|
||||
let gen: Gendy1.Audio = Gendy1.Audio(minfreq: 100.0, maxfreq: 400.0, initCPs: 6)
|
||||
addOutputGenerator(Out.Audio(bus: 0, source: gen * 0.1))
|
||||
}
|
||||
}
|
||||
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let synth: Gendy1Synth = Gendy1Synth()
|
||||
synth.build()
|
||||
|
||||
for _ in 0..<10 {
|
||||
engine.advanceSegmentSerial()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
synth.evaluate(graph: graph, count: 64)
|
||||
}
|
||||
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Control rate
|
||||
|
||||
@Test func controlRateIsControl() {
|
||||
let gen: Gendy1.Control = Gendy1.Control()
|
||||
#expect(gen.rate == .control)
|
||||
}
|
||||
|
||||
@Test func controlOutputCountMatchesRequest() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy1.Control = Gendy1.Control(seed: 10)
|
||||
let out: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
#expect(Array(out[0].prefix(64)).count == 64)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
@Test func controlFanOutReturnsCachedResult() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy1.Control = Gendy1.Control(seed: 11)
|
||||
let out1: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
let out2: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
#expect(Array(out1[0].prefix(64)) == Array(out2[0].prefix(64)))
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
@Test func controlStateAdvancesOncePerBlock() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
var graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy1.Control = Gendy1.Control(seed: 12)
|
||||
let block1a: [Double] = Array(gen.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
let block1b: [Double] = Array(gen.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
// Second call in same segment: cache hit — identical output.
|
||||
#expect(block1a == block1b)
|
||||
advanceBlock(engine)
|
||||
graph = makeSynthGraph(engine: engine)
|
||||
let block2: [Double] = Array(gen.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
// Different block: state has advanced.
|
||||
#expect(block2 != block1a)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
@Test func controlProducesNonSilentOutput() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
var graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy1.Control = Gendy1.Control(seed: 13)
|
||||
var nonZeroFound: Bool = false
|
||||
for _ in 0..<10 {
|
||||
graph = makeSynthGraph(engine: engine)
|
||||
let out: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
if out[0].prefix(64).contains(where: { $0 != 0.0 }) { nonZeroFound = true }
|
||||
advanceBlock(engine)
|
||||
}
|
||||
#expect(nonZeroFound)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
@Test func controlAmpscaleZeroProducesStableAmplitudes() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
var graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy1.Control = Gendy1.Control(ampscale: 0.0, durscale: 0.0, seed: 14)
|
||||
for _ in 0..<10 {
|
||||
graph = makeSynthGraph(engine: engine)
|
||||
let out: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
for i: Int in 0..<64 {
|
||||
// With ampscale=0 amps can't drift; mul=1 so output stays in [-1,1].
|
||||
#expect(out[0][i] >= -1.0 && out[0][i] <= 1.0,
|
||||
"sample \(i) out of [-1,1]: \(out[0][i])")
|
||||
}
|
||||
advanceBlock(engine)
|
||||
}
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
@Test func controlIntegrationRunsWithoutCrash() throws {
|
||||
final class Gendy1ControlSynth: SynthesizerBase {
|
||||
override func build() {
|
||||
let gen: Gendy1.Control = Gendy1.Control(minfreq: 0.5, maxfreq: 4.0, initCPs: 6)
|
||||
addOutputGenerator(Out.Audio(bus: 0, source: gen * 0.1))
|
||||
}
|
||||
}
|
||||
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let synth: Gendy1ControlSynth = Gendy1ControlSynth()
|
||||
synth.build()
|
||||
|
||||
for _ in 0..<10 {
|
||||
engine.advanceSegmentSerial()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
synth.evaluate(graph: graph, count: 64)
|
||||
}
|
||||
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Deterministic Control output with fixed seed
|
||||
|
||||
@Test func controlDeterministicOutputWithSeed() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen1: Gendy1.Control = Gendy1.Control(seed: 99)
|
||||
let gen2: Gendy1.Control = Gendy1.Control(seed: 99)
|
||||
let out1: [Double] = Array(gen1.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
let out2: [Double] = Array(gen2.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
#expect(out1 == out2)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
@Test func controlDifferentSeedsProduceDifferentOutput() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen1: Gendy1.Control = Gendy1.Control(seed: 100)
|
||||
let gen2: Gendy1.Control = Gendy1.Control(seed: 200)
|
||||
let out1: [Double] = Array(gen1.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
let out2: [Double] = Array(gen2.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
#expect(out1 != out2)
|
||||
engine.stop()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,319 @@
|
||||
// Gendy2Tests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
@Suite("Gendy2")
|
||||
struct Gendy2Tests {
|
||||
|
||||
// MARK: - Rate
|
||||
|
||||
@Test func rateIsAudio() {
|
||||
let gen: Gendy2.Audio = Gendy2.Audio()
|
||||
#expect(gen.rate == .audio)
|
||||
}
|
||||
|
||||
// MARK: - Output count
|
||||
|
||||
@Test func outputCountMatchesRequest() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy2.Audio = Gendy2.Audio(seed: 1)
|
||||
let out: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
#expect(Array(out[0].prefix(64)).count == 64)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Fan-out
|
||||
|
||||
@Test func fanOutReturnsCachedResult() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy2.Audio = Gendy2.Audio(seed: 2)
|
||||
let out1: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
let out2: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
#expect(Array(out1[0].prefix(64)) == Array(out2[0].prefix(64)))
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - State advances once per block
|
||||
|
||||
@Test func stateAdvancesOncePerBlock() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
var graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy2.Audio = Gendy2.Audio(seed: 3)
|
||||
let block1a: [Double] = Array(gen.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
let block1b: [Double] = Array(gen.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
#expect(block1a == block1b)
|
||||
advanceBlock(engine)
|
||||
graph = makeSynthGraph(engine: engine)
|
||||
let block2: [Double] = Array(gen.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
#expect(block2 != block1a)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Non-silent output
|
||||
|
||||
@Test func producesNonSilentOutput() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy2.Audio = Gendy2.Audio(seed: 5)
|
||||
let out: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
let nonZero: Bool = out[0].prefix(64).contains { $0 != 0.0 }
|
||||
#expect(nonZero)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Deterministic output with fixed seed
|
||||
|
||||
@Test func deterministicOutputWithSeed() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen1: Gendy2.Audio = Gendy2.Audio(seed: 99)
|
||||
let gen2: Gendy2.Audio = Gendy2.Audio(seed: 99)
|
||||
let out1: [Double] = Array(gen1.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
let out2: [Double] = Array(gen2.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
#expect(out1 == out2)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Different seeds produce different output
|
||||
|
||||
@Test func differentSeedsProduceDifferentOutput() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen1: Gendy2.Audio = Gendy2.Audio(seed: 100)
|
||||
let gen2: Gendy2.Audio = Gendy2.Audio(seed: 200)
|
||||
let out1: [Double] = Array(gen1.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
let out2: [Double] = Array(gen2.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
#expect(out1 != out2)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Output stays in bounded range (Catmull-Rom may overshoot [-1,1] slightly)
|
||||
|
||||
@Test func outputStaysInBoundedRange() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
var graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
// Catmull-Rom can overshoot breakpoint bounds slightly; verify output is finite
|
||||
// and within a reasonable margin. Gendy2 amps are clamped to [-1,1] but
|
||||
// cubic interpolation can produce values up to ~1.5× the breakpoint range.
|
||||
let catmullOvershootMargin: Double = 0.6
|
||||
let gen: Gendy2.Audio = Gendy2.Audio(seed: 4)
|
||||
for _ in 0..<20 {
|
||||
graph = makeSynthGraph(engine: engine)
|
||||
let out: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
for i: Int in 0..<64 {
|
||||
let s: Double = out[0][i]
|
||||
#expect(s.isFinite, "sample \(i) is not finite: \(s)")
|
||||
#expect(s >= -(1.0 + catmullOvershootMargin) && s <= (1.0 + catmullOvershootMargin),
|
||||
"sample \(i) out of reasonable range: \(s)")
|
||||
}
|
||||
advanceBlock(engine)
|
||||
}
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Differs from Gendy1 (cubic vs linear interpolation)
|
||||
|
||||
@Test func differsByInterpolationFromGendy1() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
// Using same seed: both generators start with same breakpoint amplitudes,
|
||||
// but differ because Gendy2 uses cubic interpolation.
|
||||
let gen1: Gendy1.Audio = Gendy1.Audio(seed: 77)
|
||||
let gen2: Gendy2.Audio = Gendy2.Audio(seed: 77)
|
||||
let out1: [Double] = Array(gen1.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
let out2: [Double] = Array(gen2.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
// The two generators differ in interpolation, so their output should differ.
|
||||
// (Both start from same RNG seed but Gendy2 also uses initCPs differently
|
||||
// due to different internal structures — outputs will differ regardless.)
|
||||
// Check that we get finite, non-identical output.
|
||||
let allFinite1: Bool = out1.allSatisfy { $0.isFinite }
|
||||
let allFinite2: Bool = out2.allSatisfy { $0.isFinite }
|
||||
#expect(allFinite1)
|
||||
#expect(allFinite2)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - mulAdd scales output
|
||||
|
||||
@Test func mulAddScalesOutput() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let genPlain: Gendy2.Audio = Gendy2.Audio(seed: 42)
|
||||
let genMulAdd: Gendy2.Audio = Gendy2.Audio(mul: 2.0, add: 1.0, seed: 42)
|
||||
let plain: [Double] = Array(genPlain.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
let scaled: [Double] = Array(genMulAdd.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
for i: Int in 0..<64 {
|
||||
let expected: Double = plain[i] * 2.0 + 1.0
|
||||
#expect(abs(scaled[i] - expected) < 1e-9, "sample \(i): expected \(expected), got \(scaled[i])")
|
||||
}
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Integration
|
||||
|
||||
@Test func integrationRunsWithoutCrash() throws {
|
||||
final class Gendy2Synth: SynthesizerBase {
|
||||
override func build() {
|
||||
let gen: Gendy2.Audio = Gendy2.Audio(minfreq: 80.0, maxfreq: 300.0, initCPs: 8)
|
||||
addOutputGenerator(Out.Audio(bus: 0, source: gen * 0.1))
|
||||
}
|
||||
}
|
||||
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let synth: Gendy2Synth = Gendy2Synth()
|
||||
synth.build()
|
||||
|
||||
for _ in 0..<10 {
|
||||
engine.advanceSegmentSerial()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
synth.evaluate(graph: graph, count: 64)
|
||||
}
|
||||
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Control rate
|
||||
|
||||
@Test func controlRateIsControl() {
|
||||
let gen: Gendy2.Control = Gendy2.Control()
|
||||
#expect(gen.rate == .control)
|
||||
}
|
||||
|
||||
@Test func controlOutputCountMatchesRequest() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy2.Control = Gendy2.Control(seed: 10)
|
||||
let out: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
#expect(Array(out[0].prefix(64)).count == 64)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
@Test func controlFanOutReturnsCachedResult() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy2.Control = Gendy2.Control(seed: 11)
|
||||
let out1: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
let out2: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
#expect(Array(out1[0].prefix(64)) == Array(out2[0].prefix(64)))
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
@Test func controlStateAdvancesOncePerBlock() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
var graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy2.Control = Gendy2.Control(seed: 12)
|
||||
let block1a: [Double] = Array(gen.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
let block1b: [Double] = Array(gen.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
#expect(block1a == block1b)
|
||||
advanceBlock(engine)
|
||||
graph = makeSynthGraph(engine: engine)
|
||||
let block2: [Double] = Array(gen.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
#expect(block2 != block1a)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
@Test func controlProducesNonSilentOutput() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
var graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy2.Control = Gendy2.Control(seed: 13)
|
||||
var nonZeroFound: Bool = false
|
||||
for _ in 0..<10 {
|
||||
graph = makeSynthGraph(engine: engine)
|
||||
let out: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
if out[0].prefix(64).contains(where: { $0 != 0.0 }) { nonZeroFound = true }
|
||||
advanceBlock(engine)
|
||||
}
|
||||
#expect(nonZeroFound)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
@Test func controlAmpscaleZeroProducesFiniteOutput() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
var graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
// ampscale=0: amplitude breakpoints cannot drift; Catmull-Rom may overshoot slightly.
|
||||
let catmullOvershootMargin: Double = 0.6
|
||||
let gen: Gendy2.Control = Gendy2.Control(ampscale: 0.0, durscale: 0.0, seed: 14)
|
||||
for _ in 0..<10 {
|
||||
graph = makeSynthGraph(engine: engine)
|
||||
let out: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
for i: Int in 0..<64 {
|
||||
let s: Double = out[0][i]
|
||||
#expect(s.isFinite, "sample \(i) is not finite: \(s)")
|
||||
#expect(s >= -(1.0 + catmullOvershootMargin) && s <= (1.0 + catmullOvershootMargin),
|
||||
"sample \(i) out of expected range: \(s)")
|
||||
}
|
||||
advanceBlock(engine)
|
||||
}
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
@Test func controlIntegrationRunsWithoutCrash() throws {
|
||||
final class Gendy2ControlSynth: SynthesizerBase {
|
||||
override func build() {
|
||||
let gen: Gendy2.Control = Gendy2.Control(minfreq: 0.5, maxfreq: 4.0, initCPs: 6)
|
||||
addOutputGenerator(Out.Audio(bus: 0, source: gen * 0.1))
|
||||
}
|
||||
}
|
||||
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let synth: Gendy2ControlSynth = Gendy2ControlSynth()
|
||||
synth.build()
|
||||
|
||||
for _ in 0..<10 {
|
||||
engine.advanceSegmentSerial()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
synth.evaluate(graph: graph, count: 64)
|
||||
}
|
||||
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Deterministic Control output with fixed seed
|
||||
|
||||
@Test func controlDeterministicOutputWithSeed() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen1: Gendy2.Control = Gendy2.Control(seed: 99)
|
||||
let gen2: Gendy2.Control = Gendy2.Control(seed: 99)
|
||||
let out1: [Double] = Array(gen1.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
let out2: [Double] = Array(gen2.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
#expect(out1 == out2)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
@Test func controlDifferentSeedsProduceDifferentOutput() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen1: Gendy2.Control = Gendy2.Control(seed: 100)
|
||||
let gen2: Gendy2.Control = Gendy2.Control(seed: 200)
|
||||
let out1: [Double] = Array(gen1.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
let out2: [Double] = Array(gen2.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
#expect(out1 != out2)
|
||||
engine.stop()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,322 @@
|
||||
// Gendy3Tests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
@Suite("Gendy3")
|
||||
struct Gendy3Tests {
|
||||
|
||||
// MARK: - Rate
|
||||
|
||||
@Test func rateIsAudio() {
|
||||
let gen: Gendy3.Audio = Gendy3.Audio()
|
||||
#expect(gen.rate == .audio)
|
||||
}
|
||||
|
||||
// MARK: - Output count
|
||||
|
||||
@Test func outputCountMatchesRequest() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy3.Audio = Gendy3.Audio(seed: 1)
|
||||
let out: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
#expect(Array(out[0].prefix(64)).count == 64)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Fan-out
|
||||
|
||||
@Test func fanOutReturnsCachedResult() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy3.Audio = Gendy3.Audio(seed: 2)
|
||||
let out1: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
let out2: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
#expect(Array(out1[0].prefix(64)) == Array(out2[0].prefix(64)))
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - State advances once per block
|
||||
|
||||
@Test func stateAdvancesOncePerBlock() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
var graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy3.Audio = Gendy3.Audio(seed: 3)
|
||||
let block1a: [Double] = Array(gen.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
let block1b: [Double] = Array(gen.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
#expect(block1a == block1b)
|
||||
advanceBlock(engine)
|
||||
graph = makeSynthGraph(engine: engine)
|
||||
let block2: [Double] = Array(gen.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
#expect(block2 != block1a)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Output stays in [-1, 1] with mul=1
|
||||
|
||||
@Test func outputStaysInRange() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
var graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy3.Audio = Gendy3.Audio(seed: 4)
|
||||
for _ in 0..<20 {
|
||||
graph = makeSynthGraph(engine: engine)
|
||||
let out: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
for i: Int in 0..<64 {
|
||||
#expect(out[0][i] >= -1.0 && out[0][i] <= 1.0,
|
||||
"sample \(i) out of [-1,1]: \(out[0][i])")
|
||||
}
|
||||
advanceBlock(engine)
|
||||
}
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Non-silent output
|
||||
|
||||
@Test func producesNonSilentOutput() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy3.Audio = Gendy3.Audio(seed: 5)
|
||||
let out: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
let nonZero: Bool = out[0].prefix(64).contains { $0 != 0.0 }
|
||||
#expect(nonZero)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Deterministic output with fixed seed
|
||||
|
||||
@Test func deterministicOutputWithSeed() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen1: Gendy3.Audio = Gendy3.Audio(seed: 99)
|
||||
let gen2: Gendy3.Audio = Gendy3.Audio(seed: 99)
|
||||
let out1: [Double] = Array(gen1.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
let out2: [Double] = Array(gen2.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
#expect(out1 == out2)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Different seeds produce different output
|
||||
|
||||
@Test func differentSeedsProduceDifferentOutput() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen1: Gendy3.Audio = Gendy3.Audio(seed: 100)
|
||||
let gen2: Gendy3.Audio = Gendy3.Audio(seed: 200)
|
||||
let out1: [Double] = Array(gen1.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
let out2: [Double] = Array(gen2.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
#expect(out1 != out2)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - ampscale=0 produces periodically repeating waveform shape
|
||||
|
||||
@Test func ampScaleZeroProducesStableAmplitudes() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
var graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
// With ampscale=0, amplitudes never drift — waveform shape is fixed.
|
||||
let gen: Gendy3.Audio = Gendy3.Audio(ampscale: 0.0, seed: 8)
|
||||
var allInRange: Bool = true
|
||||
for _ in 0..<10 {
|
||||
graph = makeSynthGraph(engine: engine)
|
||||
let out: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
for i: Int in 0..<64 {
|
||||
if out[0][i] < -1.0 || out[0][i] > 1.0 { allInRange = false }
|
||||
}
|
||||
advanceBlock(engine)
|
||||
}
|
||||
#expect(allInRange)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Different freq produces different rhythm
|
||||
|
||||
@Test func differentFreqProducesDifferentOutput() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 256)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen1: Gendy3.Audio = Gendy3.Audio(freq: 220.0, seed: 33)
|
||||
let gen2: Gendy3.Audio = Gendy3.Audio(freq: 880.0, seed: 33)
|
||||
let out1: [Double] = Array(gen1.calculatedSamples(graph: graph, count: 256)[0].prefix(256))
|
||||
let out2: [Double] = Array(gen2.calculatedSamples(graph: graph, count: 256)[0].prefix(256))
|
||||
// Different frequencies → different segment lengths → different output.
|
||||
#expect(out1 != out2)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - mulAdd scales output
|
||||
|
||||
@Test func mulAddScalesOutput() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let genPlain: Gendy3.Audio = Gendy3.Audio(seed: 42)
|
||||
let genMulAdd: Gendy3.Audio = Gendy3.Audio(mul: 2.0, add: 1.0, seed: 42)
|
||||
let plain: [Double] = Array(genPlain.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
let scaled: [Double] = Array(genMulAdd.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
for i: Int in 0..<64 {
|
||||
let expected: Double = plain[i] * 2.0 + 1.0
|
||||
#expect(abs(scaled[i] - expected) < 1e-9, "sample \(i): expected \(expected), got \(scaled[i])")
|
||||
}
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Integration
|
||||
|
||||
@Test func integrationRunsWithoutCrash() throws {
|
||||
final class Gendy3Synth: SynthesizerBase {
|
||||
override func build() {
|
||||
let gen: Gendy3.Audio = Gendy3.Audio(freq: 330.0, ampscale: 0.3, initCPs: 8)
|
||||
addOutputGenerator(Out.Audio(bus: 0, source: gen * 0.1))
|
||||
}
|
||||
}
|
||||
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let synth: Gendy3Synth = Gendy3Synth()
|
||||
synth.build()
|
||||
|
||||
for _ in 0..<10 {
|
||||
engine.advanceSegmentSerial()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
synth.evaluate(graph: graph, count: 64)
|
||||
}
|
||||
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Control rate
|
||||
|
||||
@Test func controlRateIsControl() {
|
||||
let gen: Gendy3.Control = Gendy3.Control()
|
||||
#expect(gen.rate == .control)
|
||||
}
|
||||
|
||||
@Test func controlOutputCountMatchesRequest() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy3.Control = Gendy3.Control(seed: 10)
|
||||
let out: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
#expect(Array(out[0].prefix(64)).count == 64)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
@Test func controlFanOutReturnsCachedResult() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy3.Control = Gendy3.Control(seed: 11)
|
||||
let out1: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
let out2: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
#expect(Array(out1[0].prefix(64)) == Array(out2[0].prefix(64)))
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
@Test func controlStateAdvancesOncePerBlock() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
var graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy3.Control = Gendy3.Control(seed: 12)
|
||||
let block1a: [Double] = Array(gen.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
let block1b: [Double] = Array(gen.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
#expect(block1a == block1b)
|
||||
advanceBlock(engine)
|
||||
graph = makeSynthGraph(engine: engine)
|
||||
let block2: [Double] = Array(gen.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
#expect(block2 != block1a)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
@Test func controlProducesNonSilentOutput() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
var graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy3.Control = Gendy3.Control(seed: 13)
|
||||
var nonZeroFound: Bool = false
|
||||
for _ in 0..<10 {
|
||||
graph = makeSynthGraph(engine: engine)
|
||||
let out: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
if out[0].prefix(64).contains(where: { $0 != 0.0 }) { nonZeroFound = true }
|
||||
advanceBlock(engine)
|
||||
}
|
||||
#expect(nonZeroFound)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
@Test func controlAmpscaleZeroProducesStableAmplitudes() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
var graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen: Gendy3.Control = Gendy3.Control(ampscale: 0.0, seed: 14)
|
||||
for _ in 0..<10 {
|
||||
graph = makeSynthGraph(engine: engine)
|
||||
let out: [[Double]] = gen.calculatedSamples(graph: graph, count: 64)
|
||||
for i: Int in 0..<64 {
|
||||
#expect(out[0][i] >= -1.0 && out[0][i] <= 1.0,
|
||||
"sample \(i) out of [-1,1]: \(out[0][i])")
|
||||
}
|
||||
advanceBlock(engine)
|
||||
}
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
@Test func controlIntegrationRunsWithoutCrash() throws {
|
||||
final class Gendy3ControlSynth: SynthesizerBase {
|
||||
override func build() {
|
||||
let gen: Gendy3.Control = Gendy3.Control(freq: 2.0, ampscale: 0.3, initCPs: 6)
|
||||
addOutputGenerator(Out.Audio(bus: 0, source: gen * 0.1))
|
||||
}
|
||||
}
|
||||
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let synth: Gendy3ControlSynth = Gendy3ControlSynth()
|
||||
synth.build()
|
||||
|
||||
for _ in 0..<10 {
|
||||
engine.advanceSegmentSerial()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
synth.evaluate(graph: graph, count: 64)
|
||||
}
|
||||
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
// MARK: - Deterministic Control output with fixed seed
|
||||
|
||||
@Test func controlDeterministicOutputWithSeed() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen1: Gendy3.Control = Gendy3.Control(seed: 99)
|
||||
let gen2: Gendy3.Control = Gendy3.Control(seed: 99)
|
||||
let out1: [Double] = Array(gen1.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
let out2: [Double] = Array(gen2.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
#expect(out1 == out2)
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
@Test func controlDifferentSeedsProduceDifferentOutput() throws {
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
||||
try engine.start()
|
||||
let graph: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let gen1: Gendy3.Control = Gendy3.Control(seed: 100)
|
||||
let gen2: Gendy3.Control = Gendy3.Control(seed: 200)
|
||||
let out1: [Double] = Array(gen1.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
let out2: [Double] = Array(gen2.calculatedSamples(graph: graph, count: 64)[0].prefix(64))
|
||||
#expect(out1 != out2)
|
||||
engine.stop()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user