-->

Why would alSourceUnqueueBuffers fail with INVALID

2019-09-11 15:10发布

问题:

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).

回答1:


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



回答2:

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.



标签: openal