Skip to content

[AUDIO_WORKLET] Support locateFile when loading audio worklet js file #20318

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

Conversation

FrancoisRecisio
Copy link
Contributor

@FrancoisRecisio FrancoisRecisio commented Sep 22, 2023

Fixes: #20316

Copy link
Collaborator

@RReverser RReverser left a comment

Choose a reason for hiding this comment

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

I'm running into this issue as well. The fix looks correct IMO.

@RReverser
Copy link
Collaborator

Needs rebase & conflict fix.

@@ -169,7 +169,7 @@ 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(locateFile('{{{ TARGET_BASENAME }}}.aw.js')).then(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does locateFile exist under MINIMAL_RUNTIME?

Can we get a test for this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That too, yeah.

Ideally, I'd rather merge aw.js into main JS, just like we did for pthread workers - there's nothing stopping it, and it would result in one less tiny file to download and worry about.

For now, any fix would be great though, given how long it's been broken.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the PR, however I don't now how do you want to test this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Finally it didn't pass the existing tests anyway

Copy link
Collaborator

Choose a reason for hiding this comment

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

For testing, you could copy one of the existing audio worklet tests in test_browser.py but generate the JS in a subfolder - that should reproduce the original issue.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The existing tests are already parameterised over various compile options, so should be able to check MINIMAL_RUNTIME vs MODULARIZE vs others as well.

…into audio_worklets_module_locate_file

# Conflicts:
#	src/lib/libwebaudio.js
@sbc100 sbc100 changed the title audio worklets addModule locateFile (#20316) [AUDIO_WORKLET] addModule locateFile (#20316) Mar 26, 2025
@sbc100 sbc100 changed the title [AUDIO_WORKLET] addModule locateFile (#20316) [AUDIO_WORKLET] Support locateFile when loading audio worklet js file (#20316) Mar 26, 2025
@sbc100 sbc100 changed the title [AUDIO_WORKLET] Support locateFile when loading audio worklet js file (#20316) [AUDIO_WORKLET] Support locateFile when loading audio worklet js file Mar 26, 2025
@Andonvr
Copy link

Andonvr commented Mar 30, 2025

This change would be of great help for me! Would love to see this added <3

@@ -183,7 +183,7 @@ 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(locateFile('{{{ TARGET_BASENAME }}}.aw.js')).then(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about

audioWorklet.addModule(
#if MINIMAL_RUNTIME
  '{{{ TARGET_BASENAME }}}.aw.js'
#else
  locateFile('{{{ TARGET_BASENAME }}}.aw.js')
#endif
).then(() => {

The locateFile function does not currently exist in MINIMAL_RUNTIME.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we also need the new URL(...) pattern here as well for ES6 bundlers.

Essentially copy the pattern from regular ww.js workers.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@sbc100 At this point, maybe this should be a parseTools macro for arbitrary resources?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you can think of way to express that that SGTM

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since original PR author might not be around, I posted a PR #24044 to gate the MINIMAL_RUNTIME part, and add a test.

parseTools macro and ES6 bundlers are good ideas that can be added in later PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

main .js cannot find the audio worklet .js file, if it's not in the root directory
5 participants