mercredi 23 avril 2014

How to simply play a CMSampleBufferRef audio data?


Vote count:

0




I'm capturing audio within an AVCaptureSession, now I'm about to play it.


I'm really not into lower level audio processing, so ObjectAL seems a fair choice for this, so I tried to get buffer pointer, some format information, then create an ObjectAL buffer.



-(void)captureOutput:(AVCaptureOutput*) captureOutput
didOutputSampleBuffer:(CMSampleBufferRef) sampleBuffer
fromConnection:(AVCaptureConnection*) connection
{
if ([captureOutput isKindOfClass:[AVCaptureAudioDataOutput class]])
{

// Get samples.
CMBlockBufferRef audioBuffer = CMSampleBufferGetDataBuffer(sampleBuffer);
size_t lengthAtOffset;
size_t totalLength;
char *samples;
CMBlockBufferGetDataPointer(audioBuffer, 0, &lengthAtOffset, &totalLength, &samples);

// Get format.
CMAudioFormatDescriptionRef format = CMSampleBufferGetFormatDescription(sampleBuffer);
const AudioStreamBasicDescription *description = CMAudioFormatDescriptionGetStreamBasicDescription(format);

ALBuffer *openALbuffer = [ALBuffer bufferWithName:@"buffer just captured before"
data:sampleBuffer
size:totalLength
format:description->mFormatID
frequency:description->mSampleRate];
}
}


It says Invalid Value:



OAL Error: +[ALWrapper bufferDataStatic:format:data:size:frequency:]: Invalid Value (error code 0x0000a003)


Is there any format / buffer conversation I have to utilize before create such ObjectAL (OpenAL) buffer?



asked 2 mins ago

Geri

2,911





Aucun commentaire:

Enregistrer un commentaire