问题描述
我有麻烦在我的iPhone实验得到的声音输出,我的想法。
I have trouble getting sound output on my iPhone experiment and I'm out of ideas.
下面是我的回调填补了音频队列缓冲区
Here is my callback to fill the Audio Queue buffer
void AudioOutputCallback(void *user, AudioQueueRef refQueue, AudioQueueBufferRef inBuffer)
{
NSLog(@"callback called");
inBuffer->mAudioDataByteSize = 1024;
gme_play((Music_Emu*)user, 1024, (short *)inBuffer->mAudioData);
AudioQueueEnqueueBuffer(refQueue, inBuffer, 0, NULL);
}
我安装使用下面的代码片段音频队列
I setup the audio queue using the following snippet
// Create stream description
AudioStreamBasicDescription streamDescription;
streamDescription.mSampleRate = 44100;
streamDescription.mFormatID = kAudioFormatLinearPCM;
streamDescription.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
streamDescription.mBytesPerPacket = 1024;
streamDescription.mFramesPerPacket = 1024 / 4;
streamDescription.mBytesPerFrame = 2 * sizeof(short);
streamDescription.mChannelsPerFrame = 2;
streamDescription.mBitsPerChannel = 16;
AudioQueueNewOutput(&streamDescription, AudioOutputCallback, theEmu, NULL, NULL, 0, &theAudioQueue);
OSStatus errorCode = AudioQueueAllocateBuffer(theAudioQueue, 1024, &someBuffer);
if( errorCode )
{
NSLog(@"Cannot allocate buffer");
}
AudioOutputCallback(theEmu, theAudioQueue, someBuffer);
AudioQueueSetParameter(theAudioQueue, kAudioQueueParam_Volume, 1.0);
AudioQueueStart(theAudioQueue, NULL);
我使用的库是输出线性PCM 16bit的44hz。
The library I'm using is outputting linear PCM 16bit 44hz.
推荐答案
我通常使用3缓冲区。你至少需要2,因为作为一个得到发挥,另一种是由您的code填补。如果你只有一个,有没有足够的时间来填写相同的缓冲区,并重新入队,并有播放是无缝的。所以它可能只是停止你的队列,因为它跑出缓冲区。
I usually use 3 buffers. You need at least 2 because as one gets played, the other one is filled by your code. If you have only one, there's not enough time to fill the same buffer and re-enqueue it and have playback be seamless. So it probably just stops your queue because it ran out of buffers.
这篇关于AudioQueue不输出任何声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!