|
1 | 1 | #include <emscripten/webaudio.h> |
2 | 2 | #include <emscripten/em_math.h> |
3 | 3 |
|
| 4 | +#include <stdio.h> |
| 5 | + |
4 | 6 | // This program tests that sharing the WebAssembly Memory works between the |
5 | 7 | // audio generator thread and the main browser UI thread. Two sliders, |
6 | 8 | // frequency and volume, can be adjusted on the HTML page, and the audio thread |
@@ -68,9 +70,6 @@ bool observe_test_end(double time, void *userData) { |
68 | 70 | void AudioWorkletProcessorCreated(EMSCRIPTEN_WEBAUDIO_T audioContext, bool success, void *userData) { |
69 | 71 | if (!success) return; |
70 | 72 |
|
71 | | - // Get the buffer's quantum size, we'll report this later |
72 | | - int quantumSize = emscripten_audio_context_quantum_size(audioContext); |
73 | | - |
74 | 73 | // Specify the input and output node configurations for the Wasm Audio |
75 | 74 | // Worklet. A simple setup with single mono output channel here, and no |
76 | 75 | // inputs. |
@@ -101,12 +100,7 @@ void AudioWorkletProcessorCreated(EMSCRIPTEN_WEBAUDIO_T audioContext, bool succe |
101 | 100 | audioContext.suspend(); |
102 | 101 | } |
103 | 102 | }; |
104 | | - |
105 | | - // Report the buffer size out of interest |
106 | | - let quantumText = document.createElement('p'); |
107 | | - quantumText.innerHTML += `(Buffer quantum size: ${$1})`; |
108 | | - document.body.appendChild(quantumText); |
109 | | - }, audioContext, quantumSize); |
| 103 | + }, audioContext); |
110 | 104 |
|
111 | 105 | #ifdef REPORT_RESULT |
112 | 106 | emscripten_set_timeout_loop(observe_test_end, 10, 0); |
@@ -156,6 +150,12 @@ int main() { |
156 | 150 |
|
157 | 151 | EMSCRIPTEN_WEBAUDIO_T context = emscripten_create_audio_context(&attrs); |
158 | 152 |
|
| 153 | + // Get the context's quantum size. Once the audio API allows this to be user |
| 154 | + // defined or exposes the hardware's own value, this will be needed to |
| 155 | + // determine the worklet stack size. |
| 156 | + int quantumSize = emscripten_audio_context_quantum_size(context); |
| 157 | + printf("Context quantum size: %d\n", quantumSize); |
| 158 | + |
159 | 159 | // and kick off Audio Worklet scope initialization, which shares the Wasm |
160 | 160 | // Module and Memory to the AudioWorklet scope and initializes its stack. |
161 | 161 | emscripten_start_wasm_audio_worklet_thread_async(context, wasmAudioWorkletStack, sizeof(wasmAudioWorkletStack), WebAudioWorkletThreadInitialized, 0); |
|
0 commit comments