2010-08-01 173 views
0

我无法在iPhone实验中获得声音输出,并且我的想法已经消失。AudioQueue不会输出任何声音

这里是我的回调使用下面的代码片断

// 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库,填补了音频队列缓冲区

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

我设置音频队列。

回答

0

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

0

改为分配两个缓冲区。

AudioQueues非常挑剔。