Skip to content

Commit 5163588

Browse files
committed
Added test harness hooks
1 parent ac98c9e commit 5163588

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

test/test_interactive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def test_audio_worklet_tone_generator(self):
306306
def test_audio_worklet_modularize(self):
307307
self.btest('webaudio/audioworklet.c', expected='0', args=['-sAUDIO_WORKLET', '-sWASM_WORKERS', '-sMINIMAL_RUNTIME', '-sMODULARIZE'])
308308

309-
# Tests an AudioWorklet with multiple stereo inputs mixing to a single output
309+
# Tests an AudioWorklet with multiple stereo inputs mixing in the processor to a single stereo output
310310
def test_audio_worklet_stereo_io(self):
311311
os.mkdir('audio_files')
312312
shutil.copy(test_file('webaudio/audio_files/emscripten-beat.mp3'), 'audio_files/')

test/webaudio/audioworklet_in_out_stereo.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@
55
#include <emscripten/em_js.h>
66
#include <emscripten/webaudio.h>
77

8+
// This needs to be big enough for the stereo output, 2x inputs and the worker stack
89
#define AUDIO_STACK_SIZE 4096
910

11+
// REPORT_RESULT is defined when running in Emscripten test harness.
1012
#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;
1321
}
1422
#endif
1523

@@ -49,6 +57,9 @@ EM_JS(void, toggleTrack, (EMSCRIPTEN_WEBAUDIO_T srcID), {
4957

5058
// Callback to process and mix the audio tracks
5159
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
5263
// Single stereo output
5364
assert(numOutputs == 1 && outputs[0].numberOfChannels == 2);
5465
for (int n = 0; n < numInputs; n++) {
@@ -116,6 +127,10 @@ void processorCreated(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* data) {
116127
}
117128

118129
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
119134
} else {
120135
printf("Audio worklet node creation failed\n");
121136
}

0 commit comments

Comments
 (0)