diff --git a/site/source/docs/api_reference/wasm_audio_worklets.rst b/site/source/docs/api_reference/wasm_audio_worklets.rst index 95a20f0cae53c..7f92d13bdf3d5 100644 --- a/site/source/docs/api_reference/wasm_audio_worklets.rst +++ b/site/source/docs/api_reference/wasm_audio_worklets.rst @@ -44,10 +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. +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 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..3bf8e267a2dd3 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 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); + emscripten_start_wasm_audio_worklet_thread_async(context, workletStack, AUDIO_STACK_SIZE, getStartCallback(), NULL); #ifdef TEST_AND_EXIT