broken changes
This commit is contained in:
+12
-1
@@ -92,13 +92,24 @@ import CoreAudio
|
||||
private var mixURL: URL { waveformCacheDirectory.deletingLastPathComponent().appendingPathComponent("GlobalMixer.json") }
|
||||
private var restoringMix = true
|
||||
private var persistsMix = true
|
||||
func routeOutput(_ device: AudioDeviceID) throws {
|
||||
func routeOutput(_ device: AudioDeviceID,firstChannel: Int = 0) throws {
|
||||
guard let unit = engine.outputNode.audioUnit else { throw LibraryError.message("Audio output unavailable") }
|
||||
let running = engine.isRunning;engine.stop();var value = device
|
||||
let result = AudioUnitSetProperty(unit,kAudioOutputUnitProperty_CurrentDevice,kAudioUnitScope_Global,0,&value,UInt32(MemoryLayout.size(ofValue:value)))
|
||||
guard result == noErr else { if running { try? engine.start() };throw LibraryError.message("Audio routing failed (\(result))") }
|
||||
var map = try DJAudioRouting.channelMap(channels:DJAudioDevice.channelCount(device),first:firstChannel)
|
||||
let mapResult = map.withUnsafeMutableBytes { AudioUnitSetProperty(unit,kAudioOutputUnitProperty_ChannelMap,kAudioUnitScope_Input,0,$0.baseAddress!,UInt32($0.count)) }
|
||||
guard mapResult == noErr else { if running { try? engine.start() };throw LibraryError.message("Audio channel routing failed (\(mapResult))") }
|
||||
if running { try engine.start() }
|
||||
}
|
||||
func outputChannelMap() -> [Int32] {
|
||||
guard let unit = engine.outputNode.audioUnit else { return [] }
|
||||
var size: UInt32 = 0
|
||||
guard AudioUnitGetPropertyInfo(unit,kAudioOutputUnitProperty_ChannelMap,kAudioUnitScope_Input,0,&size,nil) == noErr,size > 0 else { return [] }
|
||||
var values = [Int32](repeating:-1,count:Int(size)/4)
|
||||
let result = values.withUnsafeMutableBytes { AudioUnitGetProperty(unit,kAudioOutputUnitProperty_ChannelMap,kAudioUnitScope_Input,0,$0.baseAddress!,&size) }
|
||||
return result == noErr ? values : []
|
||||
}
|
||||
struct GlobalMix: Codable, Equatable {
|
||||
var volume: Double; var low: Double; var mid: Double; var high: Double; var filter: Double; var enabled: Bool
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user