|
5 | 5 | #include <emscripten/em_js.h>
|
6 | 6 | #include <emscripten/webaudio.h>
|
7 | 7 |
|
| 8 | +// This needs to be big enough for the stereo output, 2x inputs and the worker stack |
8 | 9 | #define AUDIO_STACK_SIZE 4096
|
9 | 10 |
|
| 11 | +// REPORT_RESULT is defined when running in Emscripten test harness. |
10 | 12 | #ifdef REPORT_RESULT
|
11 |
| -void playedAndMixed(void* data) { |
12 |
| - REPORT_RESULT(0); |
| 13 | +// Count the mixed frames and return after 375 frames (1 second with the default 128 size) |
| 14 | +volatile int audioProcessedCount = 0; |
| 15 | +bool playedAndMixed(double time, void* data) { |
| 16 | + if (audioProcessedCount >= 375) { |
| 17 | + REPORT_RESULT(0); |
| 18 | + return false; |
| 19 | + } |
| 20 | + return true; |
13 | 21 | }
|
14 | 22 | #endif
|
15 | 23 |
|
@@ -49,6 +57,9 @@ EM_JS(void, toggleTrack, (EMSCRIPTEN_WEBAUDIO_T srcID), {
|
49 | 57 |
|
50 | 58 | // Callback to process and mix the audio tracks
|
51 | 59 | bool process(int numInputs, const AudioSampleFrame* inputs, int numOutputs, AudioSampleFrame* outputs, int numParams, const AudioParamFrame* params, void* data) {
|
| 60 | +#ifdef REPORT_RESULT |
| 61 | + audioProcessedCount++; |
| 62 | +#endif |
52 | 63 | // Single stereo output
|
53 | 64 | assert(numOutputs == 1 && outputs[0].numberOfChannels == 2);
|
54 | 65 | for (int n = 0; n < numInputs; n++) {
|
@@ -116,6 +127,10 @@ void processorCreated(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* data) {
|
116 | 127 | }
|
117 | 128 |
|
118 | 129 | emscripten_set_click_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, (void*) (context), false, &onClick);
|
| 130 | + |
| 131 | +#ifdef REPORT_RESULT |
| 132 | + emscripten_set_timeout_loop(&playedAndMixed, 16, NULL); |
| 133 | +#endif |
119 | 134 | } else {
|
120 | 135 | printf("Audio worklet node creation failed\n");
|
121 | 136 | }
|
|
0 commit comments