相关代码如下
//缓冲区个数
const static NSUInteger kQueueBufferNumber = 3;
//配置 AudioStreamBasicDescription
_audioDescription.mBytesPerFrame = 2; //每一个帧包含 2 字节
_audioDescription.mFramesPerPacket = 1;//每一个 packet 一帧数据
_audioDescription.mBytesPerPacket = 2; //每一个 packet 包含 2 个字节的数据
//计算每个缓冲区大小,只有大于 2^15 时播放才有声音
_everyBufferSize = (NSUInteger) pow(_audioDescription.mBytesPerPacket, 15);
for (int i = 0; i < kQueueBufferNumber; i++) {
OSStatus allocResult = AudioQueueAllocateBuffer(_audioQueue, _everyBufferSize, &_audioQueueBuffers[i]);
if (allocResult != noErr) {
NSLog(@"SSTAudioQueuePlayer AudioQueueAllocateBuffer 失败");
return nil;
}
}