代码之家  ›  专栏  ›  技术社区  ›  Michaël Larouche

AudioQueue不输出任何声音

  •  0
  • Michaël Larouche  · 技术社区  · 14 年前

    在我的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 16位44hz。

    2 回复  |  直到 14 年前
        1
  •  1
  •   lucius    14 年前

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