音频CMSampleBuffer格式

时间:2011-11-08 11:57:57

标签: ios avfoundation core-audio audio-streaming audio-recording

使用AVCaptureAudioDataOutput时,CMSampleBuffer中存储的数据是什么?它通过委托方法–captureOutput:didOutputSampleBuffer:fromConnection:提供CMSampleBuffers,但CMSampleBuffer中有什么内容? PCM还是压缩?什么是采样率,通道数量等?如何将其用于从设备流式传输音频? 谷歌搜索几个小时并没有帮助我。

提前致谢

2 个答案:

答案 0 :(得分:8)

看起来你可以这样得到ASBD:

sampleBuffer->
  CMSampleBufferGetFormatDescription ->
    CMAudioFormatDescriptionGetStreamBasicDescription

然后ASBD将详细说明帧大小(如果它是压缩的,字节序等)

为了证明这一点(没有错误检查)并获得采样率:

CMSampleBufferRef cmSampleBuffer = ...;

CMFormatDescriptionRef formatDescription =
  CMSampleBufferGetFormatDescription(cmSampleBuffer);

const AudioStreamBasicDescription* const asbd =
  CMAudioFormatDescriptionGetStreamBasicDescription(formatDescription);

double sampleRate = asbd->mSampleRate;

答案 1 :(得分:0)

斯威夫特 5

let formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer)
let asbd = CMAudioFormatDescriptionGetStreamBasicDescription(formatDescription!)
let sampleRate = asbd?.pointee.mSampleRate