Skip to content

Commit ee18e42

Browse files
nikitha-mNikitha Mohithe
andauthored
Add missing options to EmscriptenAudioWorkletNodeCreateOptions (#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: #23982 --------- Co-authored-by: Nikitha Mohithe <nikithamohite@Nikithas-MacBook-Air.local>
1 parent ca05955 commit ee18e42

File tree

6 files changed

+37
-4
lines changed

6 files changed

+37
-4
lines changed

src/lib/libwebaudio.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ var LibraryWebAudio = {
318318
numberOfInputs: {{{ makeGetValue('options', C_STRUCTS.EmscriptenAudioWorkletNodeCreateOptions.numberOfInputs, 'i32') }}},
319319
numberOfOutputs: optionsOutputs,
320320
outputChannelCount: readChannelCountArray({{{ makeGetValue('options', C_STRUCTS.EmscriptenAudioWorkletNodeCreateOptions.outputChannelCounts, 'i32*') }}}, optionsOutputs),
321+
channelCount: {{{ makeGetValue('options', C_STRUCTS.EmscriptenAudioWorkletNodeCreateOptions.channelCount, 'u32') }}} || undefined,
322+
channelCountMode: [/*'max'*/,'clamped-max','explicit'][{{{ makeGetValue('options', C_STRUCTS.EmscriptenAudioWorkletNodeCreateOptions.channelCountMode, 'i32') }}}],
323+
channelInterpretation: [/*'speakers'*/,'discrete'][{{{ makeGetValue('options', C_STRUCTS.EmscriptenAudioWorkletNodeCreateOptions.channelInterpretation, 'i32') }}}],
321324
processorOptions: {
322325
callback,
323326
userData,

src/struct_info.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,10 @@
12931293
"EmscriptenAudioWorkletNodeCreateOptions": [
12941294
"numberOfInputs",
12951295
"numberOfOutputs",
1296-
"outputChannelCounts"
1296+
"outputChannelCounts",
1297+
"channelCount",
1298+
"channelCountMode",
1299+
"channelInterpretation"
12971300
]
12981301
}
12991302
},

src/struct_info_generated.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,10 @@
535535
"samplesPerChannel": 4
536536
},
537537
"EmscriptenAudioWorkletNodeCreateOptions": {
538-
"__size__": 12,
538+
"__size__": 24,
539+
"channelCount": 12,
540+
"channelCountMode": 16,
541+
"channelInterpretation": 20,
539542
"numberOfInputs": 0,
540543
"numberOfOutputs": 4,
541544
"outputChannelCounts": 8

src/struct_info_generated_wasm64.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,10 @@
535535
"samplesPerChannel": 4
536536
},
537537
"EmscriptenAudioWorkletNodeCreateOptions": {
538-
"__size__": 16,
538+
"__size__": 32,
539+
"channelCount": 16,
540+
"channelCountMode": 24,
541+
"channelInterpretation": 28,
539542
"numberOfInputs": 0,
540543
"numberOfOutputs": 4,
541544
"outputChannelCounts": 8

system/include/emscripten/webaudio.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ typedef struct AudioParamFrame
126126

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

129+
typedef enum {
130+
WEBAUDIO_CHANNEL_COUNT_MODE_MAX = 0,
131+
WEBAUDIO_CHANNEL_COUNT_MODE_CLAMPED_MAX = 1,
132+
WEBAUDIO_CHANNEL_COUNT_MODE_EXPLICIT = 2
133+
} WEBAUDIO_CHANNEL_COUNT_MODE;
134+
135+
typedef enum {
136+
WEBAUDIO_CHANNEL_INTERPRETATION_SPEAKERS = 0,
137+
WEBAUDIO_CHANNEL_INTERPRETATION_DISCRETE = 1
138+
} WEBAUDIO_CHANNEL_INTERPRETATION;
139+
129140
typedef struct EmscriptenAudioWorkletNodeCreateOptions
130141
{
131142
// How many audio nodes does this node take inputs from? Default=1
@@ -134,6 +145,13 @@ typedef struct EmscriptenAudioWorkletNodeCreateOptions
134145
int numberOfOutputs;
135146
// 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.
136147
int *outputChannelCounts;
148+
// Number of channels used when up-mixing and down-mixing connections to any inputs to the node. Default=2
149+
unsigned long channelCount;
150+
// How channels will be counted when up-mixing and down-mixing connections to any inputs to the node? Default=max
151+
WEBAUDIO_CHANNEL_COUNT_MODE channelCountMode;
152+
// How individual channels will be treated when up-mixing and down-mixing connections to any inputs to the node? Default=speakers
153+
WEBAUDIO_CHANNEL_INTERPRETATION channelInterpretation;
154+
137155
} EmscriptenAudioWorkletNodeCreateOptions;
138156

139157
// Instantiates the given AudioWorkletProcessor as an AudioWorkletNode, which continuously calls the specified processCallback() function on the browser's audio thread to perform audio processing.

test/webaudio/audioworklet.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ void AudioWorkletProcessorCreated(EMSCRIPTEN_WEBAUDIO_T audioContext, bool succe
9292
EmscriptenAudioWorkletNodeCreateOptions options = {
9393
.numberOfInputs = 0,
9494
.numberOfOutputs = 1,
95-
.outputChannelCounts = outputChannelCounts
95+
.outputChannelCounts = outputChannelCounts,
96+
.channelCount = 1,
97+
.channelCountMode = WEBAUDIO_CHANNEL_COUNT_MODE_EXPLICIT,
98+
.channelInterpretation = WEBAUDIO_CHANNEL_INTERPRETATION_SPEAKERS,
9699
};
97100

98101
// Instantiate the noise-generator Audio Worklet Processor.

0 commit comments

Comments
 (0)