为什么 alSourceUnqueueBuffers 会因 INVALID_OPERATION 失败

发布于 2024-11-28 08:04:04 字数 806 浏览 0 评论 0原文

代码如下:

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

对 alGetSourcei 的调用返回 cProcessedBuffers > 。 0,但以下对 alSourceUnqueueBuffers 的调用失败并出现 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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑脸一如从前 2024-12-05 08:04:04

首先尝试 alSourceStop(m_OpenALSourceId)
然后是alUnqueueBuffers(),之后,通过alSourcePlay(m_OpenALSourceId)重新开始播放。

我通过这种方式解决了同样的问题。但我不知道为什么必须这样做


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

時窥 2024-12-05 08:04:04

此 SO 线程中提到,

如果您在流媒体源上启用了 AL_LOOPING,则取消队列操作将失败。

循环标志在启用时对缓冲区有某种锁定。 @MyMiracle 的答案也暗示了这一点,停止了声音的释放,但这不是必需的。

AL_LOOPING 并不意味着在流媒体源上设置,因为管理中的源数据队列。继续排队,就会继续播放。队列从数据开始,就会循环。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文