2

我已经实现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

谢谢

4

1 回答 1

5

您可以使用 anAVAudioPlayerNode来播放您AVAudioPCMBuffer的 s:

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()
于 2017-05-07T01:46:12.140 回答