//___FILEHEADER___ import Foundation @_spi(LyrebirdExtensions) import LyrebirdSynth // MARK: - ___FILEBASENAMEASIDENTIFIER___ /// One-line description of ___FILEBASENAMEASIDENTIFIER___. /// /// Longer explanation: what the generator does, formula, edge cases. /// /// ## Usage /// ```swift /// let g = ___FILEBASENAMEASIDENTIFIER___.Audio(signal) /// let g = ___FILEBASENAMEASIDENTIFIER___.Control(signal) /// ``` public enum ___FILEBASENAMEASIDENTIFIER___ { /// Shared state between Audio and Control variants. /// /// Holds input references + MulAddSpec. Stored properties live here so the /// two final classes share the same field layout (and the same designated init). public class _Base: GeneratorBase { let inputSource: any ValidGeneratorInput let _mulAdd: MulAddSpec public init( _ signal: any ValidGeneratorInput, mul: any ValidGeneratorInput = 1.0, add: any ValidGeneratorInput = 0.0 ) { inputSource = signal _mulAdd = MulAddSpec(mul: mul, add: add) // GeneratorBase.init() allocates _result with one mono row of // lyrebirdDefaultResultBufferSize. Multi-channel generators call // super.init(channels: N) instead. } } /// Per-sample transform shared by Audio + Control. Replace this with the /// generator's actual formula. @inline(__always) static func _transform(_ value: Double) -> Double { // TODO: implement. return value } /// Audio-rate ___FILEBASENAMEASIDENTIFIER___. /// /// - Parameters: /// - signal: Input signal. /// - mul: Output multiplier. Defaults to `1.0`. /// - add: Output offset. Defaults to `0.0`. public final class Audio: _Base, AudioGenerator { /// - Parameters: /// - signal: Input signal. /// - mul: Output multiplier. Defaults to `1.0`. /// - add: Output offset. Defaults to `0.0`. public override init( _ signal: any ValidGeneratorInput, mul: any ValidGeneratorInput = 1.0, add: any ValidGeneratorInput = 0.0 ) { super.init(signal, mul: mul, add: add) } public func _computeSamples( graph: SynthGraph, count: Int ) -> [[Double]] { _checkCount(count) let block = inputSource.calculatedSamples(graph: graph, count: count).first ?? [] let n = block.count for i: Int in 0.. [[Double]] { _checkCount(count) var target = ___FILEBASENAMEASIDENTIFIER___._transform( inputSource.floatValue(graph: graph) ) if !_mulAdd.isIdentity { target = target * _mulAdd.mulInput.floatValue(graph: graph) + _mulAdd.addInput.floatValue(graph: graph) } guard count > 0 else { return _result } let rampStart: Double = previousOutputValue previousOutputValue = target let step = (target - rampStart) / Double(count) for i: Int in 0..