diff --git a/src/lib/libopenal.js b/src/lib/libopenal.js index 6142a67b41a62..2874544019b3d 100644 --- a/src/lib/libopenal.js +++ b/src/lib/libopenal.js @@ -724,9 +724,9 @@ var LibraryOpenAL = { AL.setSourceState(src, {{{ cDefs.AL_INITIAL }}}); } - if (src.bufQueue[src.bufsProcessed].audioBuf !== null) { - src.bufsProcessed = 0; - while (offset > src.bufQueue[src.bufsProcessed].audioBuf.duration) { + src.bufsProcessed = 0; + if (src.bufQueue.length && src.bufQueue[0].audioBuf) { + while (src.bufsProcessed < src.bufQueue.length && offset > src.bufQueue[src.bufsProcessed].audioBuf.duration) { offset -= src.bufQueue[src.bufsProcessed].audioBuf.duration; src.bufsProcessed++; } diff --git a/test/openal/test_openal_playback.c b/test/openal/test_openal_playback.c index 8aac17ce3e31b..524b534375c46 100644 --- a/test/openal/test_openal_playback.c +++ b/test/openal/test_openal_playback.c @@ -54,6 +54,11 @@ void playSource(void* arg) { alSourceStop(source); alGetSourcei(source, AL_SOURCE_STATE, &state); assert(state == AL_STOPPED); +#ifdef TEST_STOPPED_SEEK + alSourcef(source, AL_SEC_OFFSET, 0.5f); + alGetSourcei(source, AL_SOURCE_STATE, &state); + assert(state == AL_STOPPED); +#endif #endif alSourceRewindv(1, &source); @@ -69,6 +74,11 @@ void playSource(void* arg) { alSourceStopv(1, &source); alGetSourcei(source, AL_SOURCE_STATE, &state); assert(state == AL_STOPPED); +#ifdef TEST_STOPPED_SEEK + alSourcef(source, AL_SEC_OFFSET, 0.5f); + alGetSourcei(source, AL_SOURCE_STATE, &state); + assert(state == AL_STOPPED); +#endif test_finished(); #endif } @@ -293,7 +303,7 @@ int main() { printf("You should hear a short audio clip playing back.\n"); #endif -#ifdef __EMSCRIPTEN__ +#if defined(__EMSCRIPTEN__) && !defined(TEST_STOPPED_SEEK) intptr_t first_src = sources[0]; #if defined(TEST_LOOPED_PLAYBACK) diff --git a/test/test_interactive.py b/test/test_interactive.py index 7a4f90d6a73e9..a741e0c545021 100644 --- a/test/test_interactive.py +++ b/test/test_interactive.py @@ -160,6 +160,10 @@ def test_openal_playback(self, args): copy_asset('sounds/audio.wav') self.btest('openal/test_openal_playback.c', '1', cflags=['-O2', '--preload-file', 'audio.wav'] + args) + def test_openal_stopped_seek_playback(self): + copy_asset('sounds/audio.wav') + self.btest('openal/test_openal_playback.c', '1', cflags=['-DTEST_STOPPED_SEEK=1', '-O2', '--preload-file', 'audio.wav']) + def test_openal_buffers(self): self.btest_exit('openal/test_openal_buffers.c', cflags=['-DTEST_INTERACTIVE=1', '--preload-file', test_file('sounds/the_entertainer.wav') + '@/'])