From 98b9da050da1904db10ecb260ce151d149e93fc6 Mon Sep 17 00:00:00 2001 From: Carl Woffenden Date: Mon, 10 Nov 2025 16:41:26 +0100 Subject: [PATCH 1/4] Clarification on render size --- system/include/emscripten/webaudio.h | 2 +- test/webaudio/audioworklet_test_shared.inc | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/system/include/emscripten/webaudio.h b/system/include/emscripten/webaudio.h index 213bc81f7f985..1daa3521d9e46 100644 --- a/system/include/emscripten/webaudio.h +++ b/system/include/emscripten/webaudio.h @@ -102,7 +102,7 @@ typedef void (*EmscriptenWorkletProcessorCreatedCallback)(EMSCRIPTEN_WEBAUDIO_T void emscripten_create_wasm_audio_worklet_processor_async(EMSCRIPTEN_WEBAUDIO_T audioContext, const WebAudioWorkletProcessorCreateOptions *options, EmscriptenWorkletProcessorCreatedCallback callback, void *userData3); // Returns the number of samples processed per channel in an AudioSampleFrame, fixed at 128 in the Web Audio API 1.0 specification, and valid for the lifetime of the audio context. -// For this to change from the default 128, the context would need to be created with a yet unexposed WebAudioWorkletProcessorCreateOptions renderSizeHint, part of the 1.1 Web Audio API. +// For this to differ from the default 128, the context would need to be created with a WebAudioWorkletProcessorCreateOptions renderSizeHint, part of the 1.1 Web Audio API. int emscripten_audio_context_quantum_size(EMSCRIPTEN_WEBAUDIO_T audioContext); // Returns the sampling rate of the given Audio Context, e.g. 48000 or 44100 or similar. diff --git a/test/webaudio/audioworklet_test_shared.inc b/test/webaudio/audioworklet_test_shared.inc index 3e2b2d3ab67db..7d8a216e8b493 100644 --- a/test/webaudio/audioworklet_test_shared.inc +++ b/test/webaudio/audioworklet_test_shared.inc @@ -90,12 +90,8 @@ EmscriptenStartWebAudioWorkletCallback getStartCallback(void); // Common entry point for the mixer tests int main(void) { - char* const workletStack = memalign(16, AUDIO_STACK_SIZE); - emscripten_outf("Audio worklet stack at 0x%p", workletStack); - assert(workletStack); - - // Set at least the latency hint to test the attribute setting - // (The render size we take from the calling code if set) + // Set at least the latency hint to test the attribute setting (the render + // size we take from the calling code if set). EmscriptenWebAudioCreateAttributes attrs = { .latencyHint = "balanced", #ifdef RENDER_SIZE_HINT @@ -103,6 +99,15 @@ int main(void) { #endif }; EMSCRIPTEN_WEBAUDIO_T context = emscripten_create_audio_context(&attrs); + // With the 1.1 API this may be values other than 128 + emscripten_outf("Audio context created with quantum size of %d samples", emscripten_audio_context_quantum_size(context)); + + // Here we create a fixed sized worklet stack, but could decide based on the + // quantum size above (ins and outs * bytes per quantum)/ + char* const workletStack = memalign(16, AUDIO_STACK_SIZE); + emscripten_outf("Audio worklet stack at 0x%p", workletStack); + assert(workletStack); + emscripten_start_wasm_audio_worklet_thread_async(context, workletStack, AUDIO_STACK_SIZE, getStartCallback(), NULL); #ifdef TEST_AND_EXIT From 859451accf1e0fab7e890dcaba0cff38c14baf50 Mon Sep 17 00:00:00 2001 From: Carl Woffenden Date: Mon, 10 Nov 2025 16:47:17 +0100 Subject: [PATCH 2/4] Docs --- site/source/docs/api_reference/wasm_audio_worklets.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/site/source/docs/api_reference/wasm_audio_worklets.rst b/site/source/docs/api_reference/wasm_audio_worklets.rst index 95a20f0cae53c..49b72947e69a9 100644 --- a/site/source/docs/api_reference/wasm_audio_worklets.rst +++ b/site/source/docs/api_reference/wasm_audio_worklets.rst @@ -47,7 +47,9 @@ Once a class type is instantiated on the Web Audio graph and the graph is running, a C/C++ function pointer callback will be invoked for each 128 samples of the processed audio stream that flows through the node. Newer Web Audio API specs allow this to be changed, so for future compatibility use the -``AudioSampleFrame``'s ``samplesPerChannel`` to get the value. +``AudioSampleFrame``'s ``samplesPerChannel`` to get the value (and request the +preferred number of samples with ``EmscriptenWebAudioCreateAttributes``'s +``renderSizeHint`` option). This callback will be executed on a dedicated separate audio processing thread with real-time processing priority. Each Web Audio context will From 26aedfd948047e64f348c224e3ad3cd153781f8a Mon Sep 17 00:00:00 2001 From: Carl Woffenden Date: Mon, 10 Nov 2025 16:51:32 +0100 Subject: [PATCH 3/4] Use actual English --- test/webaudio/audioworklet_test_shared.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/webaudio/audioworklet_test_shared.inc b/test/webaudio/audioworklet_test_shared.inc index 7d8a216e8b493..3bf8e267a2dd3 100644 --- a/test/webaudio/audioworklet_test_shared.inc +++ b/test/webaudio/audioworklet_test_shared.inc @@ -102,8 +102,8 @@ int main(void) { // With the 1.1 API this may be values other than 128 emscripten_outf("Audio context created with quantum size of %d samples", emscripten_audio_context_quantum_size(context)); - // Here we create a fixed sized worklet stack, but could decide based on the - // quantum size above (ins and outs * bytes per quantum)/ + // Here we create a fixed sized worklet stack, but could calculate taking the + // quantum size above (ins and outs * bytes per quantum). char* const workletStack = memalign(16, AUDIO_STACK_SIZE); emscripten_outf("Audio worklet stack at 0x%p", workletStack); assert(workletStack); From f5090236fcef231357d5d4f83a5436a3397d35f2 Mon Sep 17 00:00:00 2001 From: Carl Woffenden Date: Tue, 11 Nov 2025 11:46:47 +0100 Subject: [PATCH 4/4] More docs clarification --- .../source/docs/api_reference/wasm_audio_worklets.rst | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/site/source/docs/api_reference/wasm_audio_worklets.rst b/site/source/docs/api_reference/wasm_audio_worklets.rst index 49b72947e69a9..7f92d13bdf3d5 100644 --- a/site/source/docs/api_reference/wasm_audio_worklets.rst +++ b/site/source/docs/api_reference/wasm_audio_worklets.rst @@ -44,12 +44,11 @@ and then, these processors are instantiated one or more times in the audio processing graph as AudioWorkletNodes. Once a class type is instantiated on the Web Audio graph and the graph is -running, a C/C++ function pointer callback will be invoked for each 128 -samples of the processed audio stream that flows through the node. Newer Web -Audio API specs allow this to be changed, so for future compatibility use the -``AudioSampleFrame``'s ``samplesPerChannel`` to get the value (and request the -preferred number of samples with ``EmscriptenWebAudioCreateAttributes``'s -``renderSizeHint`` option). +running, a C/C++ function pointer callback will be invoked for each N samples +of the processed audio stream that flows through the node (where N is is the +number of samples per channel, exposed as ``AudioSampleFrame``'s +``samplesPerChannel``, always 128 in the 1.0 Web Audio API, though with the 1.1 +API ``emscripten_create_audio_context()`` accepts a ``renderSizeHint`` option). This callback will be executed on a dedicated separate audio processing thread with real-time processing priority. Each Web Audio context will