Skip to content

Conversation

@nikitha-m
Copy link
Contributor

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

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

@nikitha-m
Copy link
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
Copy link
Collaborator

juj commented Oct 9, 2025

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
Contributor Author

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

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
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.

Copy link
Collaborator

@juj juj Oct 16, 2025

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)

@nikitha-m
Copy link
Contributor Author

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

@nikitha-m
Copy link
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
Copy link
Collaborator

sbc100 commented Oct 19, 2025

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

],
"EmscriptenWebSocketCreateAttributes": [
"protocols"
]
Copy link
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.

Copy link
Collaborator

@cwoffenden cwoffenden left a comment

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
Contributor Author

@juj @cwoffenden its done

@cwoffenden
Copy link
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
Copy link
Collaborator

juj commented Oct 23, 2025

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
32 checks passed
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