• 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
How to convert AudioBufferList to CMSampleBufferRef?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to convert AudioBufferList to CMSampleBufferRef?


  • Subject: How to convert AudioBufferList to CMSampleBufferRef?
  • From: Eagle Offshore <email@hidden>
  • Date: Thu, 06 Mar 2014 10:27:12 -0800


I have a delegate function that is getting audio from a library with this callback signature:

-(void)microphone:(EZMicrophone *)microphone
    hasBufferList:(AudioBufferList *)bufferList
   withBufferSize:(UInt32)bufferSize
withNumberOfChannels:(UInt32)numberOfChannels

and I need to forward it to a chunk of code that wants a CMSampleBufferRef

- (void)processAudioBuffer:(CMSampleBufferRef)audioBuffer;

My humble attempt is below.  It logs this message: 

CMSampleBufferSetDataBufferFromAudioBufferList returned error: -12731

HELP? ...and THANKS!

-(void)microphone:(EZMicrophone *)microphone
    hasBufferList:(AudioBufferList *)bufferList
   withBufferSize:(UInt32)bufferSize
withNumberOfChannels:(UInt32)numberOfChannels
 {
    
    // Getting audio data as a buffer list that can be directly fed into the EZRecorder. This is happening on the audio thread - any UI updating needs a GCD main queue block. This will keep appending data to the tail of the audio file.
    if( self.recorder ){
        [self.recorder appendDataFromBufferList:bufferList
                                 withBufferSize:bufferSize];
    }
    
    if(self.audioWriter)
    {
        AudioStreamBasicDescription asbd = microphone.audioStreamBasicDescription;
        CMSampleBufferRef buff = NULL;
        CMFormatDescriptionRef format = NULL;
        OSStatus error = CMAudioFormatDescriptionCreate(kCFAllocatorDefault, &asbd, 0, NULL, 0, NULL, NULL, &format);
            
        CMSampleTimingInfo timing = { CMTimeMake(1, 44100), kCMTimeZero, kCMTimeInvalid };
        
        
        error = CMSampleBufferCreate(kCFAllocatorDefault, NULL, false, NULL, NULL, format, bufferSize, 1, &timing, 0, NULL, &buff);
        if ( error ) { NSLog(@"CMSampleBufferCreate returned error: %ld", error); }
        error = CMSampleBufferSetDataBufferFromAudioBufferList(buff, kCFAllocatorDefault, kCFAllocatorDefault, 0, bufferList);
        if ( error )
        {
            NSLog(@"CMSampleBufferSetDataBufferFromAudioBufferList returned error: %ld", error);
        }
        else
        {
            [self.audioWriter processAudioBuffer:buff];
        }
    }
}



 _______________________________________________
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

  • Prev by Date: Re: Get USB device info
  • Next by Date: strange noise when using remoteIO unit for playback and record simutaneously
  • Previous by thread: Re: Get USB device info
  • Next by thread: strange noise when using remoteIO unit for playback and record simutaneously
  • Index(es):
    • Date
    • Thread