• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Convert AudioBufferList to CMSampleBuffer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Convert AudioBufferList to CMSampleBuffer


  • Subject: Re: Convert AudioBufferList to CMSampleBuffer
  • From: Heinrich Fink <email@hidden>
  • Date: Wed, 09 May 2012 08:51:10 +0200

hi patrick,

>    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.

Also, don’t forget to set a proper presentation time stamp for any CMSampleBuffer instances other than your first chunk of audio data.

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.

best regards,

Heinrich

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?
>
> 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
>


 _______________________________________________
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


  • Follow-Ups:
    • Re: Convert AudioBufferList to CMSampleBuffer
      • From: patrick machielse <email@hidden>
References: 
 >Convert AudioBufferList to CMSampleBuffer (From: patrick machielse <email@hidden>)

  • Prev by Date: Re: About how many channels of 16/44.1 PCM audio should I be able to stream from disk on an iPhone 4?
  • Next by Date: RE: Addin instrument data to caf files
  • Previous by thread: Convert AudioBufferList to CMSampleBuffer
  • Next by thread: Re: Convert AudioBufferList to CMSampleBuffer
  • Index(es):
    • Date
    • Thread