Convert AudioBufferList to CMSampleBuffer
Convert AudioBufferList to CMSampleBuffer
- Subject: Convert AudioBufferList to CMSampleBuffer
- From: patrick machielse <email@hidden>
- Date: Tue, 08 May 2012 22:40:36 +0200
On iOS I need to write data coming in from an AUGraph/Unit to file. To this end I need to convert sample data contained in an AudioBufferList to a CMSampleBuffer in order to append it to a AVAssetWriterInput.
It seems there isn't a lot of info available on how to do that exactly (and successfully). I've managed to come up with the following code, which uses an available ASBD struct:
- (void)recordData:(AudioBufferList *)data frames:(UInt32)numberOfFrames
{
CMSampleBufferRef buff = NULL;
CMFormatDescriptionRef format = NULL;
OSStatus error = CMAudioFormatDescriptionCreate(kCFAllocatorDefault, &asbd, 0, NULL, 0, NULL, NULL, &format);
CMSampleTimingInfo timing = { CMTimeMakeWithSeconds(1 / 44100.0, 1), kCMTimeZero, kCMTimeInvalid };
error = CMSampleBufferCreate(kCFAllocatorDefault, NULL, false, NULL, NULL, format, numberOfFrames, 1, &timing, 0, NULL, &buff);
error = CMSampleBufferSetDataBufferFromAudioBufferList(buff, kCFAllocatorDefault, kCFAllocatorDefault, 0, data);
if ( error ) { NSLog(@"CMSampleBufferSetDataBufferFromAudioBufferList returned error: %ld", error); }
In the last line the error is '-12731': kCMSampleBufferError_RequiredParameterMissing. I'm not sure which that should be, there are so many?
Has anyone solved this before?
Thanks,
patrick
--
Patrick Machielse
Hieper Software
http://www.hieper.nl
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden