Skip to content

Commit 1b36ec5

Browse files
authored
Clarify which userData field flows to which function callback in Web Audio. Addresses emscripten-core#18989. (emscripten-core#19010)
1 parent ae33626 commit 1b36ec5

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

system/include/emscripten/webaudio.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,20 @@ typedef int AUDIO_CONTEXT_STATE;
3434
#define AUDIO_CONTEXT_STATE_CLOSED 2
3535
#define AUDIO_CONTEXT_STATE_INTERRUPTED 3
3636

37-
typedef void (*EmscriptenResumeAudioContextCallback)(EMSCRIPTEN_WEBAUDIO_T audioContext, AUDIO_CONTEXT_STATE state, void *userData);
37+
typedef void (*EmscriptenResumeAudioContextCallback)(EMSCRIPTEN_WEBAUDIO_T audioContext, AUDIO_CONTEXT_STATE state, void *userData1);
3838

3939
// Resumes the given AudioContext. The specified callback will fire when the AudioContext has completed resuming. Call this function
4040
// inside a user event handler (mousedown, button click, etc.)
41-
void emscripten_resume_audio_context_async(EMSCRIPTEN_WEBAUDIO_T audioContext, EmscriptenResumeAudioContextCallback callback, void *userData);
41+
// userData1: A custom userdata pointer to pass to the callback function. This value will be passed on to the call to the given EmscriptenResumeAudioContextCallback callback function.
42+
void emscripten_resume_audio_context_async(EMSCRIPTEN_WEBAUDIO_T audioContext, EmscriptenResumeAudioContextCallback callback, void *userData1);
4243

4344
// Synchronously attempts to resume the given AudioContext.
4445
void emscripten_resume_audio_context_sync(EMSCRIPTEN_WEBAUDIO_T audioContext);
4546

4647
// Returns the current AudioContext state.
4748
AUDIO_CONTEXT_STATE emscripten_audio_context_state(EMSCRIPTEN_WEBAUDIO_T audioContext);
4849

49-
typedef void (*EmscriptenStartWebAudioWorkletCallback)(EMSCRIPTEN_WEBAUDIO_T audioContext, EM_BOOL success, void *userData);
50+
typedef void (*EmscriptenStartWebAudioWorkletCallback)(EMSCRIPTEN_WEBAUDIO_T audioContext, EM_BOOL success, void *userData2);
5051

5152
// Calls .suspend() on the given AudioContext and releases the JS object table
5253
// reference to the given audio context. The specified handle is invalid
@@ -65,8 +66,8 @@ void emscripten_destroy_web_audio_node(EMSCRIPTEN_WEBAUDIO_T objectHandle);
6566
// stackLowestAddress: The base address for the thread's stack. Must be aligned to 16 bytes. Use e.g. memalign(16, 1024) to allocate a 1KB stack for the thread.
6667
// stackSize: The size of the thread's stack. Must be a multiple of 16 bytes.
6768
// callback: The callback function that will be run when thread creation either succeeds or fails.
68-
// userData: A custom userdata pointer to pass to the callback function.
69-
void emscripten_start_wasm_audio_worklet_thread_async(EMSCRIPTEN_WEBAUDIO_T audioContext, void *stackLowestAddress, uint32_t stackSize, EmscriptenStartWebAudioWorkletCallback callback, void *userData);
69+
// userData2: A custom userdata pointer to pass to the callback function. This value will be passed on to the call to the given EmscriptenStartWebAudioWorkletCallback callback function.
70+
void emscripten_start_wasm_audio_worklet_thread_async(EMSCRIPTEN_WEBAUDIO_T audioContext, void *stackLowestAddress, uint32_t stackSize, EmscriptenStartWebAudioWorkletCallback callback, void *userData2);
7071

7172
typedef int WEBAUDIO_PARAM_AUTOMATION_RATE;
7273
#define WEBAUDIO_PARAM_A_RATE 0
@@ -88,10 +89,11 @@ typedef struct WebAudioWorkletProcessorCreateOptions
8889
const WebAudioParamDescriptor *audioParamDescriptors;
8990
} WebAudioWorkletProcessorCreateOptions;
9091

91-
typedef void (*EmscriptenWorkletProcessorCreatedCallback)(EMSCRIPTEN_WEBAUDIO_T audioContext, EM_BOOL success, void *userData);
92+
typedef void (*EmscriptenWorkletProcessorCreatedCallback)(EMSCRIPTEN_WEBAUDIO_T audioContext, EM_BOOL success, void *userData3);
9293

9394
// Creates a new AudioWorkletProcessor with the given name and specified set of control parameters.
94-
void emscripten_create_wasm_audio_worklet_processor_async(EMSCRIPTEN_WEBAUDIO_T audioContext, const WebAudioWorkletProcessorCreateOptions *options, EmscriptenWorkletProcessorCreatedCallback callback, void *userData);
95+
// userData3: A custom userdata pointer to pass to the callback function. This value will be passed on to the call to the given EmscriptenWorkletProcessorCreatedCallback callback function.
96+
void emscripten_create_wasm_audio_worklet_processor_async(EMSCRIPTEN_WEBAUDIO_T audioContext, const WebAudioWorkletProcessorCreateOptions *options, EmscriptenWorkletProcessorCreatedCallback callback, void *userData3);
9597

9698
typedef int EMSCRIPTEN_AUDIO_WORKLET_NODE_T;
9799

@@ -111,7 +113,7 @@ typedef struct AudioParamFrame
111113
float *data;
112114
} AudioParamFrame;
113115

114-
typedef EM_BOOL (*EmscriptenWorkletNodeProcessCallback)(int numInputs, const AudioSampleFrame *inputs, int numOutputs, AudioSampleFrame *outputs, int numParams, const AudioParamFrame *params, void *userData);
116+
typedef EM_BOOL (*EmscriptenWorkletNodeProcessCallback)(int numInputs, const AudioSampleFrame *inputs, int numOutputs, AudioSampleFrame *outputs, int numParams, const AudioParamFrame *params, void *userData4);
115117

116118
typedef struct EmscriptenAudioWorkletNodeCreateOptions
117119
{
@@ -124,7 +126,8 @@ typedef struct EmscriptenAudioWorkletNodeCreateOptions
124126
} EmscriptenAudioWorkletNodeCreateOptions;
125127

126128
// Instantiates the given AudioWorkletProcessor as an AudioWorkletNode, which continuously calls the specified processCallback() function on the browser's audio thread to perform audio processing.
127-
EMSCRIPTEN_AUDIO_WORKLET_NODE_T emscripten_create_wasm_audio_worklet_node(EMSCRIPTEN_WEBAUDIO_T audioContext, const char *name, const EmscriptenAudioWorkletNodeCreateOptions *options, EmscriptenWorkletNodeProcessCallback processCallback, void *userData);
129+
// userData4: A custom userdata pointer to pass to the callback function. This value will be passed on to the call to the given EmscriptenWorkletNodeProcessCallback callback function.
130+
EMSCRIPTEN_AUDIO_WORKLET_NODE_T emscripten_create_wasm_audio_worklet_node(EMSCRIPTEN_WEBAUDIO_T audioContext, const char *name, const EmscriptenAudioWorkletNodeCreateOptions *options, EmscriptenWorkletNodeProcessCallback processCallback, void *userData4);
128131

129132
// Returns EM_TRUE if the current thread is executing a Wasm AudioWorklet, EM_FALSE otherwise.
130133
// Note that calling this function can be relatively slow as it incurs a Wasm->JS transition,

0 commit comments

Comments
 (0)