将CMSampleBuffer转换为AVAudioPCMBuffer以获得实时音频频率

问题描述 投票:1回答:1

我正在尝试从CMSampleBuffercaptureOutput返回的AVCaptureAudioDataOutputSampleBufferDelegate读取频率值。

想法是创建一个AVAudioPCMBuffer,以便我可以读取它的floatChannelData。但是我不确定如何将缓冲区传递给它。

我想我可以用它来创建它:

public func captureOutput(_ output: AVCaptureOutput,
                              didOutput sampleBuffer: CMSampleBuffer,
                              from connection: AVCaptureConnection) {
guard let blockBuffer = CMSampleBufferGetDataBuffer(sampleBuffer) else {
  return
}
let length = CMBlockBufferGetDataLength(blockBuffer)

let audioFormat = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: 44100, channels: 1, interleaved: false)
let pcmBuffer = AVAudioPCMBuffer(pcmFormat: audioFormat!, frameCapacity: AVAudioFrameCount(length))
pcmBuffer?.frameLength = pcmBuffer!.frameCapacity

但是我如何填充其数据?

ios swift audio-streaming
1个回答
0
投票

@@ Yunnosch,谢谢您。

© www.soinside.com 2019 - 2024. All rights reserved.