Re: Convert AudioBufferList to CMSampleBuffer
Re: Convert AudioBufferList to CMSampleBuffer
- Subject: Re: Convert AudioBufferList to CMSampleBuffer
- From: patrick machielse <email@hidden>
- Date: Wed, 09 May 2012 13:01:37 +0200
Op 9 mei 2012, om 08:51 heeft Heinrich Fink het volgende geschreven:
>> CMSampleTimingInfo timing = { CMTimeMakeWithSeconds(1 / 44100.0, 1), kCMTimeZero, kCMTimeInvalid };
>
> This might not be doing what you expect. CMTimeMakeWithSeconds(1 / 44100.0, 1) will actually be rounded off to [value=0, timescale=1], meaning your sample timing info will contain a duration of zero, which I am sure is not what you aimed for. Use CMTimeMake(1, 44100) instead.
Thank you Heinrich,
It seems that CMTimeMakeWithSeconds(1 / 44100.0, 1) was indeed the problem. CMTimeMake(1, 44100) makes my export code work!
> I recommend you to look over the header documentation in CMSampleBuffer.h about CMSampleBufferCreate, especially the section "Example of usage for uncompressed non-interleaved audio:”. This really is the best source of documentation regarding CoreMedia.
Yes, I used that information to create the code I have so far. But because it's only 'pseudo code' translating it into a working example required some trial and error (and friendly help from outside...).
'-12731': kCMSampleBufferError_RequiredParameterMissing would not have indicated a problem with CMTimeMakeWithSeconds to me. It's better than the infamous '-50' error -- but not much better.
Thanks again,
patrick
> On May 8, 2012, at 22:40 , patrick machielse wrote:
>
>> 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?
_______________________________________________
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