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

查看:30
本文介绍了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 16 位 44hz.

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

推荐答案

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

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天全站免登陆