开发者

Why would alSourceUnqueueBuffers fail with INVALID_OPERATION

Here's the code:

ALint cProcessedBuffers = 0;

ALenum alError = AL_NO_ERROR;
alGetSourcei(m_OpenALSourceId, AL_BUFFERS_PROCESSED, &cProcessedBuffers);
if((alError = alGetError开发者_如何学编程()) != AL_NO_ERROR) 
{
    throw "AudioClip::ProcessPlayedBuffers - error returned from alGetSroucei()";  
}   

alError = AL_NO_ERROR;    
if (cProcessedBuffers > 0)
{
    alSourceUnqueueBuffers(m_OpenALSourceId, cProcessedBuffers, arrBuffers);
    if((alError = alGetError()) != AL_NO_ERROR) 
    {
        throw "AudioClip::ProcessPlayedBuffers - error returned from alSourceUnqueueBuffers()";  
    }   
}

The call to alGetSourcei returns with cProcessedBuffers > 0, but the following call to alSourceUnqueueBuffers fails with an INVALID_OPERATION. This in an erratic error that does not always occur. The program containing this sample code is a single-threaded app running in a tight loop (typically would be sync'ed with a display loop, but in this case I'm not using a timed callback of any sort).



Try alSourceStop(m_OpenALSourceId) first. Then alUnqueueBuffers(), and after that, Restart playing by alSourcePlay(m_OpenALSourceId).

I solved the same problem by this way. But I don't know why have to do so in


Mentioned in this SO thread,

If you have AL_LOOPING enabled on a streaming source the unqueue operation will fail.

The looping flag has some sort of lock on the buffers when enabled. The answer by @MyMiracle hints at this as well, stopping the sound releases that hold, but it's not necessary..

AL_LOOPING is not meant to be set on a streaming source, as you manage the source data in the queue. Keep queuing, it will keep playing. Queue from the beginning of the data, it will loop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜