Ios 仅使用inNumberFrames信息在AudioBufferList中分配缓冲区

Ios 仅使用inNumberFrames信息在AudioBufferList中分配缓冲区,ios,callback,malloc,audiounit,audiobuffer,Ios,Callback,Malloc,Audiounit,Audiobuffer,我有一个记录器回调(kAudioOutputUnit\u SetInputCallback),其中我需要在AudioBufferList中分配缓冲区,在回调返回的数字帧中只包含一个信息。 我该怎么做?如何仅使用帧数来确定有多少数据可用 你也可以检查这个 OSStatus AudioCapturer::recordingCallback(void *inRefCon, AudioUnitRenderActionFlags *ioActi

我有一个记录器回调(kAudioOutputUnit\u SetInputCallback),其中我需要在AudioBufferList中分配缓冲区,在回调返回的数字帧中只包含一个信息。 我该怎么做?如何仅使用帧数来确定有多少数据可用

你也可以检查这个
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;
}