Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

录音播放AudioUnit的使用,如有错误请指出并修改 #65

Open
xinzhuzi opened this issue Nov 14, 2016 · 0 comments
Open

录音播放AudioUnit的使用,如有错误请指出并修改 #65

xinzhuzi opened this issue Nov 14, 2016 · 0 comments

Comments

@xinzhuzi
Copy link

录音播放文件MicSource.mm 录音回调函数中使用AudioUnitRender(...)传入的AudioBufferList应该malloc申请内存空间,然后再free().不然会造成不必要的bug!如下:
static OSStatus handleInputBuffer(void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList ioData)
{
videocore::iOS::MicSource
mc =static_castvideocore::iOS::MicSource*(inRefCon);

AudioBuffer buffer;
buffer.mData = NULL;
buffer.mDataByteSize = 0;
buffer.mNumberChannels = 2;

AudioBufferList *buffers = (AudioBufferList *)malloc(sizeof(AudioBufferList));
buffers->mNumberBuffers = 1;
buffers->mBuffers[0] = buffer;

OSStatus status = AudioUnitRender(mc->audioUnit(),
                                  ioActionFlags,
                                  inTimeStamp,
                                  inBusNumber,
                                  inNumberFrames,
                                  buffers);

if(!status) {
    mc->inputCallback((uint8_t*)buffers->mBuffers[0].mData, buffers->mBuffers[0].mDataByteSize, inNumberFrames);
}
free(buffers);
return status;

}

如有错误,请指出并修改!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant