Skip to content

Fix iteration of OpenAL src.bufQueue #23916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/libopenal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4056,7 +4056,7 @@ var LibraryOpenAL = {

// Find the first non-zero buffer in the queue to determine the proper format
var templateBuf = AL.buffers[0];
for (var buf of src.bufQueue.length) {
for (var buf of src.bufQueue) {
if (buf.id !== 0) {
templateBuf = buf;
break;
Expand Down
5 changes: 3 additions & 2 deletions test/openal/test_openal_buffers.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ void iter() {
alGetSourcef(source, AL_PITCH, &testPitch);
assert(pitch == testPitch);
#endif

#ifndef TEST_INTERACTIVE
offset = size;
#endif
// Exit once we've processed the entire clip.
if (offset >= size) {
#if __EMSCRIPTEN__
Expand Down Expand Up @@ -192,7 +194,6 @@ int main(int argc, char* argv[]) {
ALint srcLen = 0;
alGetSourcei(source, 0x2009 /* AL_BYTE_LENGTH_SOFT */, &srcLen);
assert(srcLen == NUM_BUFFERS * BUFFER_SIZE);

#ifdef TEST_ANIMATED_PITCH
printf("You should hear a clip of the 1902 piano song \"The Entertainer\" played back at a high pitch rate, and animated to slow down to half playback speed.\n");
#else
Expand Down
5 changes: 3 additions & 2 deletions test/openal/test_openal_playback.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,11 @@ int main() {

#ifdef __EMSCRIPTEN__

intptr_t first_src = sources[0];
#if defined(TEST_LOOPED_PLAYBACK)
emscripten_set_main_loop_arg(main_tick, (void*)sources[0], 0, 0);
emscripten_set_main_loop_arg(main_tick, (void*)first_src, 0, 0);
#else
emscripten_async_call(playSource, (void*)(sources[0]), 700);
emscripten_async_call(playSource, (void*)first_src, 700);
#endif
#else
usleep(700000);
Expand Down
7 changes: 7 additions & 0 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2323,6 +2323,13 @@ def test_openal_capture_sanity(self):
def test_openal_extensions(self):
self.btest_exit('openal/test_openal_extensions.c')

def test_openal_playback(self):
shutil.copy(test_file('sounds/audio.wav'), '.')
self.btest_exit('openal/test_openal_playback.c', emcc_args=['-O2', '--preload-file', 'audio.wav'],)

def test_openal_buffers(self):
self.btest_exit('openal/test_openal_buffers.c', emcc_args=['--preload-file', test_file('sounds/the_entertainer.wav') + '@/'],)

def test_runtimelink(self):
create_file('header.h', r'''
struct point {
Expand Down
4 changes: 2 additions & 2 deletions test/test_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ def test_openal_playback(self, args):
self.btest('openal/test_openal_playback.c', '1', emcc_args=['-O2', '--preload-file', 'audio.wav'] + args)

def test_openal_buffers(self):
self.btest_exit('openal/test_openal_buffers.c', emcc_args=['--preload-file', test_file('sounds/the_entertainer.wav') + '@/'],)
self.btest_exit('openal/test_openal_buffers.c', emcc_args=['-DTEST_INTERACTIVE=1', '--preload-file', test_file('sounds/the_entertainer.wav') + '@/'],)

def test_openal_buffers_animated_pitch(self):
self.btest_exit('openal/test_openal_buffers.c', emcc_args=['-DTEST_ANIMATED_PITCH=1', '--preload-file', test_file('sounds/the_entertainer.wav') + '@/'],)
self.btest_exit('openal/test_openal_buffers.c', emcc_args=['-DTEST_INTERACTIVE=1', '-DTEST_ANIMATED_PITCH=1', '--preload-file', test_file('sounds/the_entertainer.wav') + '@/'],)

def test_openal_looped_pitched_playback(self):
self.btest('openal/test_openal_playback.c', '1', emcc_args=['-DTEST_LOOPED_PLAYBACK=1', '--preload-file', test_file('sounds/the_entertainer.wav') + '@/audio.wav'],)
Expand Down