我有正在與2個通道設置頻道地圖屬性迅速版本。我沒有使用完整的多通道系統進行測試,但原理應該是相同的。
let engine = AVAudioEngine()
let player = AVAudioPlayerNode()
func testCode(){
// get output hardware format
let output = engine.outputNode
let outputHWFormat = output.outputFormatForBus(0)
// connect mixer to output
let mixer = engine.mainMixerNode
engine.connect(mixer, to: output, format: outputHWFormat)
//then work on the player end by first attaching the player to the engine
engine.attachNode(player)
//find the audiofile
guard let audioFileURL = NSBundle.mainBundle().URLForResource("tones", withExtension: "wav") else {
fatalError("audio file is not in bundle.")
}
var songFile:AVAudioFile?
do {
songFile = try AVAudioFile(forReading: audioFileURL)
print(songFile!.processingFormat)
// connect player to mixer
engine.connect(player, to: mixer, format: songFile!.processingFormat)
} catch {
fatalError("canot create AVAudioFile \(error)")
}
let channelMap: [Int32] = [0, 1] //left out left, right out right
//let channelMap: [Int32] = [1, 0] //right out left, left out right
let propSize: UInt32 = UInt32(channelMap.count) * UInt32(sizeof(sint32))
let code: OSStatus = AudioUnitSetProperty((engine.inputNode?.audioUnit)!,
kAudioOutputUnitProperty_ChannelMap,
kAudioUnitScope_Global,
1,
channelMap,
propSize);
print(code)
do {
try engine.start()
} catch {
fatalError("Could not start engine. error: \(error).")
}
player.scheduleFile(songFile!, atTime: nil) {
print("done")
self.player.play()
}
player.play()
}
這是我的理解是AVAudioEngine僅在iOS框架 - 這樣就不會工作。 iOS和OS-X框架的蘋果文檔非常相互交織 - 很遺憾,沒有對每個平臺單獨提供什麼解釋。 –
我在嘗試使用AVAudioEngine和AVAudioPlayerNode以及mainMixerNode的另一個路徑。我還沒有弄清楚我是否可以將mainMixerNode分配給除默認值以外的其他硬件通道。也許這比使用AVPlayer更好? –
入門頻道地圖工作作爲描述這裏](https://developer.apple.com/library/prerelease/content/technotes/tn2091/_index.html#//apple_ref/doc/uid/DTS10003118-CH1-CHANNELMAPPING)還沒有工作,但希望很快。 –