Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
3 changes: 3 additions & 0 deletions src/lib/libwebaudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ var LibraryWebAudio = {
numberOfInputs: {{{ makeGetValue('options', C_STRUCTS.EmscriptenAudioWorkletNodeCreateOptions.numberOfInputs, 'i32') }}},
numberOfOutputs: optionsOutputs,
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)

processorOptions: {
callback,
userData,
Expand Down
7 changes: 5 additions & 2 deletions src/struct_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@
],
"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.

]
}
},
{
Expand Down Expand Up @@ -1293,7 +1293,10 @@
"EmscriptenAudioWorkletNodeCreateOptions": [
"numberOfInputs",
"numberOfOutputs",
"outputChannelCounts"
"outputChannelCounts",
"channelCount",
"channelCountMode",
"channelInterpretation"
]
}
},
Expand Down
5 changes: 4 additions & 1 deletion src/struct_info_generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,10 @@
"samplesPerChannel": 4
},
"EmscriptenAudioWorkletNodeCreateOptions": {
"__size__": 12,
"__size__": 24,
"channelCount": 12,
"channelCountMode": 16,
"channelInterpretation": 20,
"numberOfInputs": 0,
"numberOfOutputs": 4,
"outputChannelCounts": 8
Expand Down
5 changes: 4 additions & 1 deletion src/struct_info_generated_wasm64.json
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,10 @@
"samplesPerChannel": 4
},
"EmscriptenAudioWorkletNodeCreateOptions": {
"__size__": 16,
"__size__": 32,
"channelCount": 16,
"channelCountMode": 24,
"channelInterpretation": 28,
"numberOfInputs": 0,
"numberOfOutputs": 4,
"outputChannelCounts": 8
Expand Down
15 changes: 15 additions & 0 deletions system/include/emscripten/webaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ typedef struct AudioParamFrame

typedef bool (*EmscriptenWorkletNodeProcessCallback)(int numInputs, const AudioSampleFrame *inputs, int numOutputs, AudioSampleFrame *outputs, int numParams, const AudioParamFrame *params, void *userData4);

typedef enum {
WEBAUDIO_CHANNEL_COUNT_MODE_MAX = 0,
WEBAUDIO_CHANNEL_COUNT_MODE_CLAMPED_MAX = 1,
WEBAUDIO_CHANNEL_COUNT_MODE_EXPLICIT = 2
} WEBAUDIO_CHANNEL_COUNT_MODE;

typedef enum {
WEBAUDIO_CHANNEL_INTERPRETATION_SPEAKERS = 0,
WEBAUDIO_CHANNEL_INTERPRETATION_DISCRETE = 1
} WEBAUDIO_CHANNEL_INTERPRETATION;

typedef struct EmscriptenAudioWorkletNodeCreateOptions
{
// How many audio nodes does this node take inputs from? Default=1
Expand All @@ -134,6 +145,10 @@ typedef struct EmscriptenAudioWorkletNodeCreateOptions
int numberOfOutputs;
// For each output, specifies the number of audio channels (1=mono/2=stereo/etc.) for that output. Default=an array of ones for each output channel.
int *outputChannelCounts;
unsigned long channelCount;
WEBAUDIO_CHANNEL_COUNT_MODE channelCountMode;
WEBAUDIO_CHANNEL_INTERPRETATION channelInterpretation;

} EmscriptenAudioWorkletNodeCreateOptions;

// Instantiates the given AudioWorkletProcessor as an AudioWorkletNode, which continuously calls the specified processCallback() function on the browser's audio thread to perform audio processing.
Expand Down
5 changes: 4 additions & 1 deletion test/webaudio/audioworklet.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ void AudioWorkletProcessorCreated(EMSCRIPTEN_WEBAUDIO_T audioContext, bool succe
EmscriptenAudioWorkletNodeCreateOptions options = {
.numberOfInputs = 0,
.numberOfOutputs = 1,
.outputChannelCounts = outputChannelCounts
.outputChannelCounts = outputChannelCounts,
.channelCount = 1,
.channelCountMode = WEBAUDIO_CHANNEL_COUNT_MODE_EXPLICIT,
.channelInterpretation = WEBAUDIO_CHANNEL_INTERPRETATION_SPEAKERS,
};

// Instantiate the noise-generator Audio Worklet Processor.
Expand Down