Skip to content
Closed
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
8 changes: 7 additions & 1 deletion src/lib/libwebaudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
'''))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this requires a custom shell.html.

I think you can just put the Module = { ... } stuff in a --pre-js file there.


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):
Expand Down