Skip to content

Commit 6f87785

Browse files
authored
[AUDIO_WORKLET] clarify docs and use for renderSizeHint (#25760)
Minor clarification of the docs and example.
1 parent 9a799f7 commit 6f87785

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

site/source/docs/api_reference/wasm_audio_worklets.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ and then, these processors are instantiated one or more times in the audio
4444
processing graph as AudioWorkletNodes.
4545

4646
Once a class type is instantiated on the Web Audio graph and the graph is
47-
running, a C/C++ function pointer callback will be invoked for each 128
48-
samples of the processed audio stream that flows through the node. Newer Web
49-
Audio API specs allow this to be changed, so for future compatibility use the
50-
``AudioSampleFrame``'s ``samplesPerChannel`` to get the value.
47+
running, a C/C++ function pointer callback will be invoked for each N samples
48+
of the processed audio stream that flows through the node (where N is is the
49+
number of samples per channel, exposed as ``AudioSampleFrame``'s
50+
``samplesPerChannel``, always 128 in the 1.0 Web Audio API, though with the 1.1
51+
API ``emscripten_create_audio_context()`` accepts a ``renderSizeHint`` option).
5152

5253
This callback will be executed on a dedicated separate audio processing
5354
thread with real-time processing priority. Each Web Audio context will

system/include/emscripten/webaudio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ typedef void (*EmscriptenWorkletProcessorCreatedCallback)(EMSCRIPTEN_WEBAUDIO_T
102102
void emscripten_create_wasm_audio_worklet_processor_async(EMSCRIPTEN_WEBAUDIO_T audioContext, const WebAudioWorkletProcessorCreateOptions *options, EmscriptenWorkletProcessorCreatedCallback callback, void *userData3);
103103

104104
// 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.
105-
// 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.
105+
// 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.
106106
int emscripten_audio_context_quantum_size(EMSCRIPTEN_WEBAUDIO_T audioContext);
107107

108108
// Returns the sampling rate of the given Audio Context, e.g. 48000 or 44100 or similar.

test/webaudio/audioworklet_test_shared.inc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,24 @@ EmscriptenStartWebAudioWorkletCallback getStartCallback(void);
9090

9191
// Common entry point for the mixer tests
9292
int main(void) {
93-
char* const workletStack = memalign(16, AUDIO_STACK_SIZE);
94-
emscripten_outf("Audio worklet stack at 0x%p", workletStack);
95-
assert(workletStack);
96-
97-
// Set at least the latency hint to test the attribute setting
98-
// (The render size we take from the calling code if set)
93+
// Set at least the latency hint to test the attribute setting (the render
94+
// size we take from the calling code if set).
9995
EmscriptenWebAudioCreateAttributes attrs = {
10096
.latencyHint = "balanced",
10197
#ifdef RENDER_SIZE_HINT
10298
.renderSizeHint = RENDER_SIZE_HINT
10399
#endif
104100
};
105101
EMSCRIPTEN_WEBAUDIO_T context = emscripten_create_audio_context(&attrs);
102+
// With the 1.1 API this may be values other than 128
103+
emscripten_outf("Audio context created with quantum size of %d samples", emscripten_audio_context_quantum_size(context));
104+
105+
// Here we create a fixed sized worklet stack, but could calculate taking the
106+
// quantum size above (ins and outs * bytes per quantum).
107+
char* const workletStack = memalign(16, AUDIO_STACK_SIZE);
108+
emscripten_outf("Audio worklet stack at 0x%p", workletStack);
109+
assert(workletStack);
110+
106111
emscripten_start_wasm_audio_worklet_thread_async(context, workletStack, AUDIO_STACK_SIZE, getStartCallback(), NULL);
107112

108113
#ifdef TEST_AND_EXIT

0 commit comments

Comments
 (0)