gpt4 book ai didi

iPhone:AudioBufferList 初始化和释放

转载 作者:技术小花猫 更新时间:2023-10-29 10:56:57 34 4
gpt4 key购买 nike

初始化(分配内存)和释放(释放)具有 3 个 AudioBuffers 的 AudioBufferList 的正确方法是什么? (我知道可能有不止一种方法可以做到这一点。)

我想使用这 3 个缓冲区将音频文件的顺序部分读入其中,并使用音频单元播放它们。

最佳答案

这是我的做法:

AudioBufferList *
AllocateABL(UInt32 channelsPerFrame, UInt32 bytesPerFrame, bool interleaved, UInt32 capacityFrames)
{
AudioBufferList *bufferList = NULL;

UInt32 numBuffers = interleaved ? 1 : channelsPerFrame;
UInt32 channelsPerBuffer = interleaved ? channelsPerFrame : 1;

bufferList = static_cast<AudioBufferList *>(calloc(1, offsetof(AudioBufferList, mBuffers) + (sizeof(AudioBuffer) * numBuffers)));

bufferList->mNumberBuffers = numBuffers;

for(UInt32 bufferIndex = 0; bufferIndex < bufferList->mNumberBuffers; ++bufferIndex) {
bufferList->mBuffers[bufferIndex].mData = static_cast<void *>(calloc(capacityFrames, bytesPerFrame));
bufferList->mBuffers[bufferIndex].mDataByteSize = capacityFrames * bytesPerFrame;
bufferList->mBuffers[bufferIndex].mNumberChannels = channelsPerBuffer;
}

return bufferList;
}

关于iPhone:AudioBufferList 初始化和释放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3767527/

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