提问人:Mozalic Hu 提问时间:11/14/2023 更新时间:11/14/2023 访问量:13
AVAudioPlayerNode 可以进行一对多连接吗
Can AVAudioPlayerNode make a one-to-many connetion
问:
我尝试将用户麦克风和 AVAudioPlayerNode 混合使用,并将其写入文件。同时,我想让两个单独的流做一些事情。
我用下面来建立联系。通过使用此连接,点击 recorderMixNode 回调空缓冲区。正确点击 mainMixer 和 inputMixNode 回调。
try input.setVoiceProcessingEnabled(true)
let output = engine.outputNode
let mainMixer = engine.mainMixerNode
engine.attach(player)
engine.attach(recorderMixNode)
engine.attach(inputMixNode)
let newFormat = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: 24000, channels: 1, interleaved: true)!
engine.connect(player, to: [AVAudioConnectionPoint(node: recorderMixNode, bus: 0), AVAudioConnectionPoint(node: mainMixer, bus: 0)], fromBus: 0, format: newFormat)
engine.connect(mainMixer, to: output, format: nil)
engine.connect(input, to: [AVAudioConnectionPoint(node: recorderMixNode, bus: recorderMixNode.nextAvailableInputBus), AVAudioConnectionPoint(node: inputMixNode, bus: 0)], fromBus: 0, format: newFormat)//
recorderMixNode.installTap(onBus: 0, bufferSize: 1600, format: newFormat) { [weak self] buffer, when in
//write buffer to file
}
inputMixNode.installTap(onBus: 0, bufferSize: 1600, format: newFormat) { [weak self] buffer, when in
//handle input
}
mainMixer.installTap(onBus: 0, bufferSize: 2400, format: nil) { [weak self] buffer, when in
//handle output
}
engine.prepare()
我试过了:
删除玩家与 recorderMixNode 的连接:可以正确录制输入。
删除输入与 recorderMixNode 的连接:无法正确录制播放器。
new a AVAudioPlayerNode 仅连接到 recorderMixNode:调用 AVAudioPlayerNode.play() 时崩溃,让播放器“处于断开连接状态时启动”。猜测导致 recorderMixNode 无法连接到输出。
我期待:
我想知道 AVAudioPlayerNode 是否可以进行一对多连接。 如果不是,是否有任何建议的设置,以使播放器流式传输到两个节点
答: 暂无答案
评论