diff --git a/src/lib/libwebaudio.js b/src/lib/libwebaudio.js index 3378cc89792d9..bd8755a5e1503 100644 --- a/src/lib/libwebaudio.js +++ b/src/lib/libwebaudio.js @@ -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; })(), processorOptions: { callback, userData, diff --git a/src/struct_info.json b/src/struct_info.json index 7000a523fd589..2236e7d2048a3 100644 --- a/src/struct_info.json +++ b/src/struct_info.json @@ -1260,7 +1260,7 @@ ], "EmscriptenWebSocketCreateAttributes": [ "protocols" - ] +] } }, { @@ -1293,7 +1293,10 @@ "EmscriptenAudioWorkletNodeCreateOptions": [ "numberOfInputs", "numberOfOutputs", - "outputChannelCounts" + "outputChannelCounts", + "channelCount", + "channelCountMode", + "channelInterpretation" ] } }, diff --git a/src/struct_info_generated.json b/src/struct_info_generated.json index d19c5424c9107..d1ca2576292f4 100644 --- a/src/struct_info_generated.json +++ b/src/struct_info_generated.json @@ -535,7 +535,10 @@ "samplesPerChannel": 4 }, "EmscriptenAudioWorkletNodeCreateOptions": { - "__size__": 12, + "__size__": 24, + "channelCount": 12, + "channelCountMode": 16, + "channelInterpretation": 20, "numberOfInputs": 0, "numberOfOutputs": 4, "outputChannelCounts": 8 diff --git a/src/struct_info_generated_wasm64.json b/src/struct_info_generated_wasm64.json index 13d51209247f5..22254a5516602 100644 --- a/src/struct_info_generated_wasm64.json +++ b/src/struct_info_generated_wasm64.json @@ -535,7 +535,10 @@ "samplesPerChannel": 4 }, "EmscriptenAudioWorkletNodeCreateOptions": { - "__size__": 16, + "__size__": 32, + "channelCount": 16, + "channelCountMode": 24, + "channelInterpretation": 28, "numberOfInputs": 0, "numberOfOutputs": 4, "outputChannelCounts": 8 diff --git a/system/include/emscripten/webaudio.h b/system/include/emscripten/webaudio.h index 07d60e8525a86..122ad1e407c3b 100644 --- a/system/include/emscripten/webaudio.h +++ b/system/include/emscripten/webaudio.h @@ -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 @@ -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. diff --git a/test/webaudio/audioworklet.c b/test/webaudio/audioworklet.c index 883834b3843d7..979b59bb666ff 100644 --- a/test/webaudio/audioworklet.c +++ b/test/webaudio/audioworklet.c @@ -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.