Formato de audio CMSampleBuffer

What is the data stored in CMSampleBuffer when using AVCaptureAudioDataOutput? It delivers CMSampleBuffers via delegate method –captureOutput:didOutputSampleBuffer:fromConnection: but what's inside CMSampleBuffer? PCM or compressed? What are the samplerates, number of channels, etc.? How this can be used for streaming audio from device? Googling for several hours didn't helped me.

Gracias por adelantado

preguntado el 08 de noviembre de 11 a las 11:11

2 Respuestas

looks like you can get the ASBD this way:

sampleBuffer->
  CMSampleBufferGetFormatDescription ->
    CMAudioFormatDescriptionGetStreamBasicDescription

then the ASBD will detail the frame sizes, if it is compressed, endianness, etc.

To demonstrate this (with no error checking) and get the sample rate:

CMSampleBufferRef cmSampleBuffer = ...;

CMFormatDescriptionRef formatDescription =
  CMSampleBufferGetFormatDescription(cmSampleBuffer);

const AudioStreamBasicDescription* const asbd =
  CMAudioFormatDescriptionGetStreamBasicDescription(formatDescription);

double sampleRate = asbd->mSampleRate;

Respondido 17 Feb 15, 02:02

thanks! i used just CMSampleBufferGetFormatDescription and it showed all the info i'm wondering - peetonn

and is it possible to configure AVAudioOutput with different parameters that i receive? - peetonn

@peetonn you're welcome. regarding your question: I'm not sure if you mean AudioOutputUnit, AVAudioPlayery AVCaptureAudioDataOutput cuando tu dices AVAudioOutput. I grew up on the Core and AU layers; I'd guess that it is whatever they want to provide, to avoid conversion overhead. It's worth searching here. - Justin

Swift 5

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

Respondido el 26 de enero de 21 a las 17:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.