我使用三个缓冲区和一个队列,通过网络播放 ADPCM 数据。从我的应用程序中解码数据,并通过从 Audacity 播放正确验证解码数据(未压缩的 pcm 数据)。但是,使用 AudioQueue 从我的应用程序播放时,我听不到任何声音。所有 AudioQueue API 返回值都是 noErr (0)。我一直在尝试通过分配三个缓冲区来跟踪AudioQueue 不会输出任何声音。它对我不起作用!有人知道如何显示更多 AudioQueue 日志,以便我可以捕捉到故障点,或者我的代码有什么问题吗?谢谢!
...
aq->mDataFormat.mSampleRate = format->nSamplesPerSec; // 44100
aq->mDataFormat.mChannelsPerFrame = format->nChannels; // 1
aq->mDataFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger |
kAudioFormatFlagIsPacked;
aq->mDataFormat.mFramesPerPacket = 1;
aq->mDataFormat.mBitsPerChannel = 16;
aq->mDataFormat.mFormatID = kAudioFormatLinearPCM;
...
// Fill data before starting
for (i = 0; i bufferByteSize >= size) {
aq->mBuffers[i]->mAudioDataByteSize =
size - (kNumberBuffers - 1 - i) * chunkSize;
memcpy(aq->mBuffers[i]->mAudioData,
src + aq->mBuffers[i]->mAudioDataByteSize,
aq->mBuffers[i]->mAudioDataByteSize);
status = AudioQueueEnqueueBuffer(aq->mQueue, aq->mBuffers[i], 0, NULL);
printf("%s: %d/%d bytes to enqueue - %d\n", __func__,
aq->mBuffers[i]->mAudioDataByteSize, size, status);
size -= aq->mBuffers[i]->mAudioDataByteSize;
src += aq->mBuffers[i]->mAudioDataByteSize;
} else {
aq->mBuffers[i]->mAudioDataByteSize = aq->bufferByteSize;
memcpy(aq->mBuffers[i]->mAudioData, src, aq->bufferByteSize);
status = AudioQueueEnqueueBuffer(aq->mQueue, aq->mBuffers[i], 0, NULL);
printf("%s: enqueue a full buffer[%d]\n - %d\n", __func__, i, status);
size -= aq->bufferByteSize;
src += aq->bufferByteSize;
}
}
}
...
status = AudioQueueSetParameter(aq->mQueue, kAudioQueueParam_Volume, 1.0);
printf("%s: set AudioQueue volume %d\n", __func__, status);
status = AudioQueueStart(aq->mQueue, NULL);
printf("%s: start AudioQueue [%d] %d\n", __func__, aq->bufferByteSize, status);