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];
}
}
}