I have a recorder callback(kAudioOutputUnit_SetInputCallback) in which I need to allocate buffers in AudioBufferList with only one informatin-inNUmberFrames that the callback returns. How do I malloc for this? How can I determine how much data is available using only the number of frames?
Asked
Active
Viewed 1,788 times
1 Answers
2
OSStatus AudioCapturer::recordingCallback(void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData) {
AudioCapturer *capturer=(AudioCapturer * )inRefCon;
AudioBuffer buffer;
buffer.mNumberChannels = 1;
buffer.mDataByteSize = inNumberFrames * 2;
buffer.mData = malloc( inNumberFrames * 2 );
// Put buffer in a AudioBufferList that is to be filled in the AudioUnitRender
AudioBufferList bufferList;
bufferList.mNumberBuffers = 1;
bufferList.mBuffers[0] = buffer;
// Then:
// Obtain recorded samples
OSStatus status;
status = AudioUnitRender(capturer->m_audioUnit,
ioActionFlags,
inTimeStamp,
inBusNumber,
inNumberFrames,
&bufferList);
capturer->checkStatus(status);
//use the bufferlist data and free the allocated buffer
free(bufferList.mBuffers[0].mData);
return noErr;
}

Saraswati
- 1,516
- 1
- 14
- 21
-
1u can also check this [link](http://atastypixel.com/blog/using-remoteio-audio-unit/) – Saraswati May 28 '12 at 05:46