OGeek|极客世界-中国程序员成长平台

标题: iphone - iOS,音频队列 : Buffer size is not contant [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 07:58
标题: iphone - iOS,音频队列 : Buffer size is not contant

我在我的应用程序中使用音频队列服务。在分配缓冲区时,我将缓冲区大小设置为 30000 个样本:

AudioQueueAllocateBuffer(mQueue, 30000, &mBuffers[i]);

但是回调的后续调用是使用以下inNumberPacketDescriptions进行的:

30000
30000
30000
26928
30000
30000

它们并不总是等于 30000。为什么?

记录格式配置(使用CAStreamBasicDescription):

mRecordFormat.mSampleRate = kSampleRate;    
mRecordFormat.mChannelsPerFrame = 1;
mRecordFormat.mFormatID = kAudioFormatLinearPCM;
mRecordFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
mRecordFormat.mBitsPerChannel = 16;
mRecordFormat.mBytesPerPacket = mRecordFormat.mBytesPerFrame = (mRecordFormat.mBitsPerChannel / 8) * mRecordFormat.mChannelsPerFrame;
mRecordFormat.mFramesPerPacket = 1;

3 个缓冲区被使用。



Best Answer-推荐答案


编辑:我看到 iOS 在出现非二次方音频缓冲区时会自发地改变缓冲区大小。 (Another SO question 引用此)无论如何,

30000 是

(a) 巨大的缓冲区大小,以及

(b) 用于缓冲区的奇怪数字。通常它们是 2 的幂 - 即 *=2 来自 64,即 64、128、256、512、1024、2048、4096。我从未见过高于 4096 的,而且我做很多音频工作。

如果您有特殊原因需要使用异常大的缓冲区,则可以使用 nextPowerOfTwo 便利函数或自己硬编码数学。

关于iphone - iOS,音频队列 : Buffer size is not contant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6318354/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4