【发布时间】:2017-05-28 00:13:03
【问题描述】:
我已成功使用AVAudioPlayerNode 播放立体声和单声道文件。我想使用具有 3 个以上通道的文件(环绕文件)并能够以非线性方式路由音频。例如,我可以将文件通道 0 分配给输出通道 2,将文件通道 4 分配给输出通道 1。
音频接口的输出数量未知(2-40),这就是为什么我需要能够允许用户按照他们认为合适的方式路由音频。而WWDC 2015 507 中让用户在 Audio Midi Setup 中更改路由的解决方案并不是一个可行的解决方案。
我只能想到 1 种可能性(我对其他人持开放态度):为每个频道创建一个播放器,并为每个播放器加载仅一个频道的缓冲区 similar to this post。但即使通过海报承认,也存在问题。
所以我正在寻找一种方法将文件的每个通道复制到 AudioBuffer 中,例如:
let file = try AVAudioFile(forReading: audioURL)
let fullBuffer = AVAudioPCMBuffer(pcmFormat: file.processingFormat,
frameCapacity: AVAudioFrameCount(file.length))
try file.read(into: fullBuffer)
// channel 0
let buffer0 = AVAudioPCMBuffer(pcmFormat: file.processingFormat,
frameCapacity: AVAudioFrameCount(file.length))
// this doesn't work, unable to get fullBuffer channel and copy
// error on subscripting mBuffers
buffer0.audioBufferList.pointee.mBuffers.mData = fullBuffer.audioBufferList.pointee.mBuffers[0].mData
// repeat above buffer code for each channel from the fullBuffer
【问题讨论】:
标签: swift mono core-audio surround avaudiopcmbuffer