2010-08-01 178 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非常挑剔。