You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
769 B
29 lines
769 B
import Foundation
|
|
|
|
/// dB ↔ linear gain helpers. -60 dB and below count as silence.
|
|
public enum Level {
|
|
public static let floorDB: Float = -60
|
|
|
|
public static func gain(fromDB db: Float) -> Float {
|
|
db <= floorDB ? 0 : powf(10, db / 20)
|
|
}
|
|
|
|
public static func db(fromGain gain: Float) -> Float {
|
|
gain <= 0 ? floorDB : max(floorDB, 20 * log10f(gain))
|
|
}
|
|
}
|
|
|
|
/// Which part of a stereo source feeds a mono output channel.
|
|
public enum ChannelSelection: String, Codable, CaseIterable, Sendable {
|
|
case left, right, mono
|
|
|
|
@inline(__always)
|
|
public func sample(left: Float, right: Float) -> Float {
|
|
switch self {
|
|
case .left: left
|
|
case .right: right
|
|
case .mono: 0.5 * (left + right)
|
|
}
|
|
}
|
|
}
|