Files

40 lines
1.2 KiB
Swift

// DbAmpTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
import Foundation
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
@MainActor
@Suite("DbAmp")
struct DbAmpTests {
let engine: SynthesisEngine = makeTestEngine(blockSize: 8)
var graph: SynthGraph { makeSynthGraph(engine: engine) }
init() throws { try engine.start() }
@Test func zeroDbReachesUnityGain() {
let s: [[Double]] = DbAmp.Control(ConstantAudioGen(0.0)).calculatedSamples(graph: graph, count: 8)
#expect(abs(s[0][7] - 1.0) < 1e-10)
}
@Test func minusTwentyDbReachesOneTenth() {
let s: [[Double]] = DbAmp.Control(ConstantAudioGen(-20.0)).calculatedSamples(graph: graph, count: 8)
#expect(abs(s[0][7] - 0.1) < 1e-9)
}
@Test func mulAddAppliedAfterConversion() {
let mulValue: Double = 2.0
let addValue: Double = 0.5
let s: [[Double]] = DbAmp.Control(
ConstantAudioGen(0.0),
mul: mulValue,
add: addValue
).calculatedSamples(graph: graph, count: 8)
#expect(abs(s[0][7] - (1.0 * mulValue + addValue)) < 1e-10)
}
}