//___FILEHEADER___ // // In-tree template — drop this file under Sources/Lyrebird/Generators/Noise/. // Extends `NoiseBase`, whose designated init is module-internal, so this // template is not usable from a project that depends on Lyrebird as a package. // External users should start from the basic `LyrebirdGenerator` template and // declare rngState + xorshift64 inline. // MARK: - ___FILEBASENAMEASIDENTIFIER___ /// One-line description of ___FILEBASENAMEASIDENTIFIER___. /// /// Extends `NoiseBase` so `rngState: UInt64` and `_mulAdd` are inherited. /// Use `xorshift64Next(&rngState)` to draw a `[-1, 1]` sample per call. /// /// Each instance is independently seeded — concurrent instances produce /// uncorrelated output. /// /// ## Usage /// ```swift /// let n = ___FILEBASENAMEASIDENTIFIER___.Audio() /// let n = ___FILEBASENAMEASIDENTIFIER___.Audio(seed: 42) // deterministic for tests /// ``` public enum ___FILEBASENAMEASIDENTIFIER___ { /// Shared PRNG state and output buffer for both rate variants. public class _Base: NoiseBase { override init( initialRngState: UInt64, mul: any ValidGeneratorInput = 1.0, add: any ValidGeneratorInput = 0.0 ) { super.init(initialRngState: initialRngState, mul: mul, add: add) } /// Draw one sample in `[-1, 1]`. Replace this body with any /// distribution-shaping logic — clip, fold, threshold, etc. func nextSample() -> Double { xorshift64Next(&rngState) } } /// Audio-rate ___FILEBASENAMEASIDENTIFIER___. /// /// - Parameters: /// - seed: PRNG seed. Defaults to a time-derived value for unique instances. /// Pass an explicit seed for reproducible test output. /// - mul: Output multiplier applied after synthesis. Defaults to `1.0`. /// - add: Offset added after multiplier. Defaults to `0.0`. public final class Audio: _Base, AudioGenerator { /// - Parameters: /// - seed: PRNG seed. /// - mul: Output multiplier. /// - add: Output offset. public init( seed: UInt64? = nil, mul: any ValidGeneratorInput = 1.0, add: any ValidGeneratorInput = 0.0 ) { // Pick a unique mix constant so this Audio variant doesn't correlate // with sibling Control / sibling generators when both default-seed // within the same nanosecond. let audioMixConstant: UInt64 = 0xA110_AAAA_5A5A_3C3C let initialRngState = lyrebirdSeedXorshift64(from: seed, mixConstant: audioMixConstant) super.init(initialRngState: initialRngState, mul: mul, add: add) } public func _computeSamples( graph: SynthGraph, count: Int ) -> [[Double]] { _checkCount(count) for i: Int in 0.. [[Double]] { _calculatedSamplesBlockRate(graph: graph, count: count) } public func _computeSamples( graph: SynthGraph, count: Int ) -> [[Double]] { _checkCount(count) let target: Double = nextSample() let rampStart: Double = _rampTarget _rampTarget = target guard count > 0 else { return _result } previousOutputValue = fillRampedResult( into: &_result, from: rampStart, to: target, mulAdd: _mulAdd, graph: graph, count: count) return _result } } } extension ___FILEBASENAMEASIDENTIFIER___: GeneratorEnum { public typealias AudioType = ___FILEBASENAMEASIDENTIFIER___.Audio public typealias ControlType = ___FILEBASENAMEASIDENTIFIER___.Control }