49 lines
1.8 KiB
Swift
49 lines
1.8 KiB
Swift
// DSLBuiltinTests.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Testing
|
|
import LyrebirdSynth
|
|
import LyrebirdGraphDSL
|
|
|
|
@MainActor
|
|
@Suite("DSLBuiltin")
|
|
struct DSLBuiltinTests {
|
|
|
|
/// A `DSLBuiltin` wrapping `OscSin` — the exact shape the code-gen tool will
|
|
/// emit — constructs a real generator that renders audio through the engine.
|
|
/// Locks the registry contract that the parser/builder will consume.
|
|
@Test func builtinConstructsAndRendersGenerator() throws {
|
|
let builtin: DSLBuiltin = DSLBuiltin(
|
|
name: "OscSin",
|
|
rate: .audio,
|
|
parameters: [
|
|
DSLParameter(label: "freq", hasDefault: false),
|
|
DSLParameter(label: "mul", hasDefault: true),
|
|
DSLParameter(label: "add", hasDefault: true),
|
|
],
|
|
make: { args in
|
|
OscSin.Audio(
|
|
freq: try DSLArgument.input(args["freq"], "OscSin", "freq"),
|
|
mul: try DSLArgument.input(args["mul"] ?? .signal(1.0), "OscSin", "mul"),
|
|
add: try DSLArgument.input(args["add"] ?? .signal(0.0), "OscSin", "add")
|
|
)
|
|
}
|
|
)
|
|
|
|
#expect(builtin.name == "OscSin")
|
|
#expect(builtin.parameters.first == DSLParameter(label: "freq", hasDefault: false))
|
|
|
|
let graph: any ValidGeneratorInput = try builtin.make(["freq": sig(440.0), "mul": sig(0.1)])
|
|
|
|
let engine: SynthesisEngine = makeDSLTestEngine()
|
|
try engine.start()
|
|
try engine.add(ClosureSynthesizer { graph })
|
|
engine.processBlock(inputSamples: [])
|
|
let anyNonZero: Bool = (0..<engine.blockSize).contains { engine.audioBuses[0][$0] != 0.0 }
|
|
#expect(anyNonZero)
|
|
}
|
|
}
|