Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions site/source/docs/api_reference/wasm_audio_worklets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion system/include/emscripten/webaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 11 additions & 6 deletions test/webaudio/audioworklet_test_shared.inc
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,24 @@ 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
.renderSizeHint = RENDER_SIZE_HINT
#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
Expand Down
Loading