diff --git a/src/lib/libwebaudio.js b/src/lib/libwebaudio.js index 9d13142700c47..6103c017c6e8f 100644 --- a/src/lib/libwebaudio.js +++ b/src/lib/libwebaudio.js @@ -183,7 +183,13 @@ let LibraryWebAudio = { // TODO: In MINIMAL_RUNTIME builds, read this file off of a preloaded Blob, // and/or embed from a string like with WASM_WORKERS==2 mode. - audioWorklet.addModule('{{{ TARGET_BASENAME }}}.aw.js').then(() => { + audioWorklet.addModule( +#if MINIMAL_RUNTIME + '{{{ TARGET_BASENAME }}}.aw.js' +#else + locateFile('{{{ TARGET_BASENAME }}}.aw.js') +#endif + ).then(() => { #if WEBAUDIO_DEBUG console.log(`emscripten_start_wasm_audio_worklet_thread_async() addModule('audioworklet.js') completed`); #endif diff --git a/test/test_browser.py b/test/test_browser.py index 15d40867f7c68..87e4facdee1a8 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -5521,6 +5521,22 @@ def test_full_js_library_strict(self): def test_audio_worklet(self, args): self.btest_exit('webaudio/audioworklet.c', emcc_args=['-sAUDIO_WORKLET', '-sWASM_WORKERS', '-DTEST_AND_EXIT'] + args) + # Test that when using audio worklets, it is possible to use the locateFile() machinery to reroute where the .aw.js file is loaded from. + @requires_sound_hardware + def test_audio_worklet_locatefile(self): + # Create a locateFile() function that loads .aw.js from a subdirectory. + create_file('shell.html', read_file(path_from_root('src/shell.html')).replace('var Module = {', ''' + var Module = { + locateFile: function(path, prefix) { + return path.includes('.aw.js') ? 'subdir/' + path : path; + }, + ''')) + + self.compile_btest('webaudio/audioworklet.c', ['--shell-file', 'shell.html', '-sAUDIO_WORKLET', '-sWASM_WORKERS', '-DTEST_AND_EXIT', '-o', 'test.html']) + ensure_dir('subdir') + shutil.move('test.aw.js', Path('subdir/test.aw.js')) + self.run_browser('test.html', '/report_result?exit:0') + # Tests that audioworklets and workers can be used at the same time # Note: doesn't need audio hardware (and has no AW code that tests 2GB or wasm64) def test_audio_worklet_worker(self):