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)
ObjectAL actually hooks to some OpenAL stuff I did not get into, you may understand it better:ALBuffer.m
, ALWrapper.m