gpt4 book ai didi

ios - 监听 AVAudioPCMBuffer

转载 作者:可可西里 更新时间:2023-11-01 00:35:43 31 4
gpt4 key购买 nike

我已经实现了 installTap 方法,它为我提供了音频缓冲区浮点示例。我已经通过我的 C++ DSP 库过滤了它们。我想将此缓冲区“发送”到耳机/扬声器。我从示例中再次执行了 AVAudioPCMBuffer。任何人都知道该怎么做?

代码:

node.installTap(onBus: bus, bufferSize: AVAudioFrameCount(BUFFER_SIZE), format: node.inputFormat(forBus: bus), block: { (buffer : AVAudioPCMBuffer ,time : AVAudioTime) in

let root = buffer.floatChannelData!.pointee


// First pointer defines chanels
// Second pointer defines floats values

for i in 0 ..< BUFFER_SIZE{
self.signalData[i] = Double(root.advanced(by: i).pointee) * self.gainCorrection
}
let signalDataPreEq = self.signalData

let filteredSignal = shared.EQ.filterBuffer(UnsafeMutablePointer<Double>(mutating: self.signalData), with_count: Int32(BUFFER_SIZE))

self.signalData = Array(UnsafeBufferPointer(start : filteredSignal, count : BUFFER_SIZE))

for i in 0 ..< BUFFER_SIZE{
root.advanced(by: i).pointee = Float(self.signalData[i])
}
// HERE I WANT TO LISTEN(PLAYBACK) AUDIO FROM BUFFER

谢谢

最佳答案

您可以使用 AVAudioPlayerNode 来播放您的 AVAudioPCMBuffer:

let player = AVAudioPlayerNode()
engine.attach(player)

let bus = 0
let inputFormat = node.inputFormat(forBus: bus)
engine.connect(player, to: engine.mainMixerNode, format: inputFormat)

node.installTap(...) {
// other stuff
player.scheduleBuffer(filteredSignal) // filteredSignal is your AVAudioPCMBuffer?
}

// engine.start()

player.play()

关于ios - 监听 AVAudioPCMBuffer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43820432/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com