AudioQueue不输出任何声音 [英] AudioQueue does not output any sound

查看:305
本文介绍了AudioQueue不输出任何声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有麻烦在我的iPhone实验得到的声音输出,我的想法。

I have trouble getting sound output on my iPhone experiment and I'm out of ideas.

下面是我的回调填补了音频队列缓冲区

Here is my callback to fill the Audio Queue buffer

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

我安装使用下面的代码片段音频队列

I setup the audio queue using the following snippet

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

The library I'm using is outputting linear PCM 16bit 44hz.

推荐答案

我通常使用3缓冲区。你至少需要2,因为作为一个得到发挥,另一种是由您的code填补。如果你只有一个,有没有足够的时间来填写相同的缓冲区,并重新入队,并有播放是无缝的。所以它可能只是停止你的队列,因为它跑出缓冲区。

I usually use 3 buffers. You need at least 2 because as one gets played, the other one is filled by your code. If you have only one, there's not enough time to fill the same buffer and re-enqueue it and have playback be seamless. So it probably just stops your queue because it ran out of buffers.

这篇关于AudioQueue不输出任何声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆