我在 C 中有以下代码,它分配了具有适当长度的 AudioBufferList。
UInt32 bufferSizeBytes = bufferSizeFrames * sizeof(Float32);
propertySize = offsetof(AudioBufferList, mBuffers[0]) + (sizeof(AudioBuffer) * mRecordSBD.mChannelsPerFrame);
mBufferList = (AudioBufferList *) malloc(propertySize);
mBufferList->mNumberBuffers = mRecordSBD.mChannelsPerFrame;
for(UInt32 i = 0; i < mBufferList->mNumberBuffers; ++i)
{
mBufferList->mBuffers[i].mNumberChannels = 1;
mBufferList->mBuffers[i].mDataByteSize = bufferSizeBytes;
mBufferList->mBuffers[i].mData = malloc(bufferSizeBytes);
}
大多数时候,mChannelsPerFrame
是 2,所以上面的代码创建了两个缓冲区,每个通道一个。每个缓冲区都有一个保留的内存值bufferSizeBytes
。
如何在 Swift 中复制相同的行为?