f8878324fd
Mirror of Lyrebird dev HEAD (9f791c7c) minus maintainer-only paths. Patch release: fixes the allpass fractional-delay click (DelayLine/CombFilter/AllpassFilter/ DelayLineFeedback under a modulated delay) and lands the internal code-quality consolidation pass (~160 deduped sites + shared base classes/helpers, bit-identical output). No public API removed or changed. See RELEASES.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
77 lines
2.9 KiB
Swift
77 lines
2.9 KiB
Swift
// Tan.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Foundation
|
|
|
|
// MARK: - Tan
|
|
|
|
/// Tangent waveshaper: `tan(signal)`. Input treated as radians. Output diverges
|
|
/// to ±∞ near `π/2 + kπ`; callers should clip or limit downstream when feeding
|
|
/// audio-rate inputs that approach those poles.
|
|
///
|
|
/// - Parameter signal: Input signal in radians.
|
|
public enum Tan {
|
|
public class _Base: UnaryMathBase {}
|
|
/// - Parameters:
|
|
/// - signal: Input signal in radians.
|
|
/// - mul: Output multiplier. Defaults to `1.0`.
|
|
/// - add: Output offset. Defaults to `0.0`.
|
|
public final class Audio: _Base, AudioGenerator {
|
|
/// - Parameters:
|
|
/// - signal: Input signal in radians.
|
|
/// - 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: [Double] = inputSource.calculatedSamples(graph: graph, count: count).first ?? []
|
|
let n: Int = block.count
|
|
for i: Int in 0..<count { _result[0][i] = Foundation.tan(i < n ? block[i] : 0.0) }
|
|
_mulAdd.applyIfNeeded(to: &_result, graph: graph, count: count)
|
|
return _result
|
|
}
|
|
}
|
|
/// - Parameters:
|
|
/// - signal: Input signal in radians.
|
|
/// - mul: Output multiplier. Defaults to `1.0`.
|
|
/// - add: Output offset. Defaults to `0.0`.
|
|
public final class Control: _Base, ControlGenerator {
|
|
public var previousOutputValue: Double = 0.0
|
|
/// - Parameters:
|
|
/// - signal: Input signal in radians.
|
|
/// - 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); _setupSubBlockBuffer() }
|
|
|
|
public func _computeSamples(
|
|
graph: SynthGraph,
|
|
count: Int
|
|
) -> [[Double]] {
|
|
_checkCount(count)
|
|
var target: Double = Foundation.tan(inputSource.floatValue(graph: graph))
|
|
target = _mulAdd.applyScalar(target, graph: graph)
|
|
fillScalarRampedResult(into: &_result, previousOutputValue: &previousOutputValue, target: target, count: count)
|
|
return _result
|
|
}
|
|
}
|
|
}
|
|
|
|
extension Tan: GeneratorEnum {
|
|
public typealias AudioType = Tan.Audio
|
|
public typealias ControlType = Tan.Control
|
|
}
|