gpt4 book ai didi

ios - 仅使用 inNumberFrames 信息在 AudioBufferList 中分配缓冲区 iOS

转载 作者:行者123 更新时间:2023-11-28 22:56:14 26 4
gpt4 key购买 nike

我有一个录音机回调 (kAudioOutputUnit_SetInputCallback),我需要在其中分配 AudioBufferList 中的缓冲区,其中只有一个回调返回的信息 inNUmberFrames。我如何为此分配内存?如何仅使用帧数来确定有多少数据可用?

最佳答案

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

关于ios - 仅使用 inNumberFrames 信息在 AudioBufferList 中分配缓冲区 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10748609/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com