Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Audio CMSampleBuffer format

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.

Thanks in advance

like image 459
peetonn Avatar asked Nov 08 '11 11:11

peetonn


1 Answers

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;
like image 50
justin Avatar answered Oct 01 '22 00:10

justin