AudioQueue不输出任何声音

时间:2010-08-01 23:29:41

标签: iphone audio core-audio audioqueue

我无法在iPhone实验中获得声音输出,而且我没有想法。

这是我的回调来填充音频队列缓冲区

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);
}

我使用以下代码段设置音频队列

    // 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。

2 个答案:

答案 0 :(得分:0)

改为分配两个缓冲区。

AudioQueues非常挑剔。

答案 1 :(得分:0)

我通常使用3个缓冲区。你需要至少2个,因为一个人被玩,另一个被你的代码填满。如果你只有一个,那么就没有足够的时间来填充相同的缓冲区并重新入队,并且无缝播放。所以它可能只是停止你的队列,因为它用完了缓冲区。