3

我在 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。

4

1 回答 1

1

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

于 2010-08-05T04:17:45.763 回答