Skip to content

Add missing options to EmscriptenAudioWorkletNodeCreateOptions - #25497

Merged
juj merged 12 commits into
emscripten-core:mainfrom
nikitha-m:add_missing_options
Oct 23, 2025
Merged

juj merged 12 commits into
emscripten-core:mainfrom
nikitha-m:add_missing_options

Conversation

@nikitha-m

@nikitha-m nikitha-m commented Oct 5, 2025 •

Copy link
Copy Markdown
Contributor

Problem Description

The EmscriptenAudioWorkletNodeCreateOptions struct currently only exposes options specific to AudioWorkletNode itself (numberOfInputs, numberOfOutputs, outputChannelCounts), but AudioWorkletNode inherits from AudioNode which has additional properties:

  • channelCount
  • channelCountMode
  • channelInterpretation

Fix

  • Extend the C struct in system/include/emscripten/webaudio.h.
  • Update the JavaScript implementation in src/lib/libwebaudio.js to pass these options to the AudioWorkletNode constructor.

Fixes: #23982

Comment thread system/include/emscripten/webaudio.h Resolved
Comment thread system/include/emscripten/webaudio.h Resolved
@nikitha-m

Copy link
Copy Markdown
Contributor Author

@juj how do i run test cases locally? I followed the docs but I'm facing some issues while running these commands

emsdk install tot
emsdk activate tot

@juj

juj commented Oct 9, 2025

Copy link
Copy Markdown
Collaborator

Yeah, that is how you install a pre-compiled Emscripten. If installing tot doesn't work, you can also try emsdk install latest followed by emsdk activate latest.

To run browser audio-related tests, you can run test/runner browser.test_*audio* and test/runner interactive.test_*audio*. The first suite is automated, but the second suite requires an interactive user to prod the tests forward.

If installing tot or latest doesn't work out, you can also try these steps to build all from source: https://bugzilla.mozilla.org/show_bug.cgi?id=1992558#c2

@nikitha-m

Copy link
Copy Markdown
Contributor Author

@juj i think it's done. Is this fine?

Comment thread src/lib/libwebaudio.js Outdated
outputChannelCount: readChannelCountArray({{{ makeGetValue('options', C_STRUCTS.EmscriptenAudioWorkletNodeCreateOptions.outputChannelCounts, 'i32*') }}}, optionsOutputs),
channelCount: (function(){ var v = {{{ makeGetValue('options', C_STRUCTS.EmscriptenAudioWorkletNodeCreateOptions.channelCount, 'u32') }}}; return v > 0 ? v : undefined; })(),
channelCountMode: (function(){ var v = {{{ makeGetValue('options', C_STRUCTS.EmscriptenAudioWorkletNodeCreateOptions.channelCountMode, 'i32') }}}; var arr = ['max','clamped-max','explicit']; return arr[v] || undefined; })(),
channelInterpretation: (function(){ var v = {{{ makeGetValue('options', C_STRUCTS.EmscriptenAudioWorkletNodeCreateOptions.channelInterpretation, 'i32') }}}; var arr = ['speakers','discrete']; return arr[v] || undefined; })(),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The anonymous functions and || undefined should be unnecessary here, they take up code size for no benefit.

E.g. channelCountMode: ['max','clamped-max','explicit'][{{{ makeGetValue(...) }}}], looks like would be enough here?

One thing to verify here is how do older browsers behave (or Safari) that do not yet support these options? If you run in an older browser that does not support any of this, would that cause an error?

It would be good to have a short test of non-default channelCountMode and non-default channelInterpretation to ensure that it works.

@juj juj Oct 16, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Did you have a chance to look at the above review comment?

How about this code:

      channelCount: {{{ makeGetValue('options', C_STRUCTS.EmscriptenAudioWorkletNodeCreateOptions.channelCount, 'u32') }}} || undefined,
      channelCountMode: [/*'max'*/,'clamped-max','explicit'][{{{ makeGetValue('options', C_STRUCTS.EmscriptenAudioWorkletNodeCreateOptions.channelCountMode, 'i32') }}}],
      channelInterpretation: [/*'speakers'*/,'discrete'][{{{ makeGetValue('options', C_STRUCTS.EmscriptenAudioWorkletNodeCreateOptions.channelInterpretation, 'i32') }}}],

It is shorter for the same effect? ('max' and 'speakers' are the default in the spec if I understand correctly)

Comment thread system/include/emscripten/webaudio.h Resolved
@nikitha-m

Copy link
Copy Markdown
Contributor Author

@juj @cwoffenden could you please lmk if any changes are required other than adding comments?

@nikitha-m

Copy link
Copy Markdown
Contributor Author

@juj This test case that failed doesn't look like its related to the webaudio related tests can you help me with this?

@sbc100

sbc100 commented Oct 19, 2025

Copy link
Copy Markdown
Collaborator

@nikitha-m can you try merging/rebasing with main?

Comment thread src/struct_info.json
],
"EmscriptenWebSocketCreateAttributes": [
"protocols"
]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Minor: formatting got lost.

@cwoffenden cwoffenden left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

With the changes that @juj suggested, this all now looks compact and correct.

@sbc100 sbc100 changed the title fix: added missing options to EmscriptenAudioWorkletNodeCreateOptions closes #23982 Add missing options to EmscriptenAudioWorkletNodeCreateOptions Oct 20, 2025
@nikitha-m

Copy link
Copy Markdown
Contributor Author

@juj @cwoffenden its done

@cwoffenden

Copy link
Copy Markdown
Collaborator

@juj @cwoffenden its done

I can neither approve nor merge, I can just say that it looks correct and doesn't break anything. I've not personally used these audio node properties for mixing so I can't comment further (we perform all the mixing ourselves and to a regular stereo output).

@juj

juj commented Oct 23, 2025

Copy link
Copy Markdown
Collaborator

Hmm looks like CircleCI is stuck here on code size checks.

I'll land this and re-roll the code size update action, I think those will change here.

Thanks for the contribution @nikitha-m .

@juj
juj merged commit ee18e42 into emscripten-core:main Oct 23, 2025
inolen pushed a commit to inolen/emscripten that referenced this pull request Feb 13, 2026
…ipten-core#25497)

## Problem Description
The EmscriptenAudioWorkletNodeCreateOptions struct currently only
exposes options specific to AudioWorkletNode itself (numberOfInputs,
numberOfOutputs, outputChannelCounts), but AudioWorkletNode inherits
from AudioNode which has additional properties:

- channelCount 
- channelCountMode 
- channelInterpretation 

## Fix 

- Extend the C struct in `system/include/emscripten/webaudio.h`.
- Update the JavaScript implementation in `src/lib/libwebaudio.js` to
pass these options to the `AudioWorkletNode` constructor.

Fixes: emscripten-core#23982

---------

Co-authored-by: Nikitha Mohithe <[email protected]>
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.

EmscriptenAudioWorkletNodeCreateOptions missing couple of options

4 participants