Files
Lyrebird/Sources/Lyrebird/Generators/Math/DbAmp.swift
T
josh f8878324fd v2.1.1 release: delay-click fix + internal consolidation
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>
2026-10-07 21:20:49 -07:00

49 lines
1.7 KiB
Swift

// DbAmp.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
// MARK: - DbAmp
/// Converts a decibel value to a linear amplitude multiplier: `10^(dB / 20)`.
///
/// Control-rate only — intended for live gain knobs authored in dB (e.g. a pedal's
/// output-level control) that need to drive another generator's linear gain input
/// every block. Wraps the scalar `dbToAmp(_:)` helper so the conversion formula
/// lives in one place.
///
/// - Parameter signal: Input value in decibels.
public enum DbAmp {
public class _Base: UnaryMathBase {}
/// - Parameters:
/// - signal: Input value in decibels.
/// - 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 value in decibels.
/// - 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 = dbToAmp(inputSource.floatValue(graph: graph))
target = _mulAdd.applyScalar(target, graph: graph)
fillScalarRampedResult(into: &_result, previousOutputValue: &previousOutputValue, target: target, count: count)
return _result
}
}
}