35 lines
1022 B
Swift
35 lines
1022 B
Swift
import Domain
|
|
import Foundation
|
|
|
|
public struct OutputDeviceInfo: Hashable, Sendable {
|
|
public var id: UInt32
|
|
public var name: String
|
|
public var nominalRate: Double
|
|
public var availableRates: [Double]
|
|
|
|
public init(id: UInt32, name: String, nominalRate: Double, availableRates: [Double]) {
|
|
self.id = id
|
|
self.name = name
|
|
self.nominalRate = nominalRate
|
|
self.availableRates = availableRates
|
|
}
|
|
}
|
|
|
|
public struct SampleRateMatcher: Sendable {
|
|
public var isEnabled: Bool
|
|
|
|
public init(isEnabled: Bool) {
|
|
self.isEnabled = isEnabled
|
|
}
|
|
|
|
public func targetRate(for format: AudioFormat?, on device: OutputDeviceInfo?) -> Double? {
|
|
guard isEnabled, let device, let rate = format?.sampleRate.map(Double.init) else { return nil }
|
|
guard rate != device.nominalRate, device.availableRates.contains(rate) else { return nil }
|
|
return rate
|
|
}
|
|
}
|
|
|
|
public protocol PlaybackTuning: Sendable {
|
|
func setMatchesSampleRate(_ isOn: Bool) async
|
|
}
|