如何多次跳转到特定偏移量?
想象一下这个函数:
void SoundManager::playSource(ALuint sourceID, float offset)
{
alSourceStop(sourceID);
ALint iTotal = 0;
ALint iCurrent = 0;
ALint uiBuffer = 0;
alGetSourcei(sourceID, AL_BUFFER, &uiBuffer);
alGetBufferi(uiBuffer, AL_SIZE, &iTotal);
iCurrent = iTotal * offset;
alSourcei(sourceID, AL_BYTE_OFFSET, iCurrent);
alSourcePlay(sourceID);
}
这个想法是调用 playSource(x, 0.5f)
会跳转到(大约)缓冲区的一半,等等。
我第一次调用它时它工作正常,但如果我调用它再次在同一源上(无论该源是否正在播放)它开始播放,就好像我用偏移量 0 调用它一样。
有什么想法吗?
Imagine this function:
void SoundManager::playSource(ALuint sourceID, float offset)
{
alSourceStop(sourceID);
ALint iTotal = 0;
ALint iCurrent = 0;
ALint uiBuffer = 0;
alGetSourcei(sourceID, AL_BUFFER, &uiBuffer);
alGetBufferi(uiBuffer, AL_SIZE, &iTotal);
iCurrent = iTotal * offset;
alSourcei(sourceID, AL_BYTE_OFFSET, iCurrent);
alSourcePlay(sourceID);
}
The idea is calling playSource(x, 0.5f)
would jump to (roughly) halfway through the buffer, etc.
It works fine the first time I call it, but if I call it again on the same source (whether that source is playing or not) it begins playing as though I'd called it with offset 0.
Any ideas why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决了!
尽管 API 声称设置偏移量适用于任何状态的源,但问题是我应该在开始时调用
alSourceRewind
而不是alSourceStop
。看来设置偏移量仅适用于处于 AL_INITIAL 状态的源。
Solved!
Even though the API claims that setting the offsets works on sources in any state, the problem was I should have been calling
alSourceRewind
instead ofalSourceStop
at the start.It seems setting offsets only works on sources in the
AL_INITIAL
state.你可以先播放音频文件,然后像这样调用
setOffset
,不需要调用alSourcePlay
:you can play the audio file first,then call
setOffset
like this,don't need to callalSourcePlay
: