我有一个录音机回调(kAudioOutputUnit_SetInputCallback),我需要在 AudioBufferList 中分配缓冲区,只有一个回调返回的 informatin-inNUMberFrames。我如何为此进行malloc?如何仅使用帧数确定有多少数据可用?
问问题
1739 次
1 回答
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;
}
于 2012-05-25T05:02:51.107 回答