Skip to content

Commit 632bd0d

Browse files
committed
Mixer test migrated to use CI changes
1 parent 0384fad commit 632bd0d

File tree

4 files changed

+34
-24
lines changed

4 files changed

+34
-24
lines changed

test/test_browser.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5495,17 +5495,21 @@ def test_audio_worklet_post_function(self, args):
54955495
def test_audio_worklet_modularize(self, args):
54965496
self.btest_exit('webaudio/audioworklet.c', args=['-sAUDIO_WORKLET', '-sWASM_WORKERS', '-sMODULARIZE=1', '-sEXPORT_NAME=MyModule', '--shell-file', test_file('shell_that_launches_modularize.html')] + args)
54975497

5498-
# Tests multiple inputs, forcing a larger stack (note: passing BROWSER_TEST is
5499-
# specific to this test to allow it to exit rather than play forever).
5498+
# Tests an AudioWorklet with multiple stereo inputs mixing in the processor
5499+
# via a varying parameter to a single stereo output (touching all of the API
5500+
# copying from structs)
55005501
@parameterized({
55015502
'': ([],),
55025503
'minimal_with_closure': (['-sMINIMAL_RUNTIME', '--closure=1', '-Oz'],),
55035504
})
5504-
def test_audio_worklet_stereo_io(self, args):
5505+
@no_wasm64('https://github.com/emscripten-core/emscripten/pull/23508')
5506+
@no_2gb('https://github.com/emscripten-core/emscripten/pull/23508')
5507+
@requires_sound_hardware
5508+
def test_audio_worklet_params_mixing(self, args):
55055509
os.mkdir('audio_files')
55065510
shutil.copy(test_file('webaudio/audio_files/emscripten-beat.mp3'), 'audio_files/')
55075511
shutil.copy(test_file('webaudio/audio_files/emscripten-bass.mp3'), 'audio_files/')
5508-
self.btest_exit('webaudio/audioworklet_in_out_stereo.c', args=['-sAUDIO_WORKLET', '-sWASM_WORKERS', '-DBROWSER_TEST'] + args)
5512+
self.btest_exit('webaudio/audioworklet_params_mixing.c', args=['-sAUDIO_WORKLET', '-sWASM_WORKERS', '-DTEST_AND_EXIT'] + args)
55095513

55105514
def test_error_reporting(self):
55115515
# Test catching/reporting Error objects

test/test_interactive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def test_audio_worklet_params_mixing(self):
339339
os.mkdir('audio_files')
340340
shutil.copy(test_file('webaudio/audio_files/emscripten-beat.mp3'), 'audio_files/')
341341
shutil.copy(test_file('webaudio/audio_files/emscripten-bass.mp3'), 'audio_files/')
342-
self.btest_exit('webaudio/audioworklet_params_mixing.c', args=['-sAUDIO_WORKLET', '-sWASM_WORKERS'])
342+
self.btest_exit('webaudio/audioworklet_params_mixing.c', args=['-sAUDIO_WORKLET', '-sWASM_WORKERS', '-DTEST_AND_EXIT'])
343343

344344

345345
class interactive64(interactive):

test/webaudio/audioworklet_params_mixing.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include <assert.h>
22
#include <string.h>
3-
#include <stdio.h>
43

54
#include <emscripten/em_js.h>
65
#include <emscripten/webaudio.h>
@@ -18,7 +17,9 @@
1817

1918
// Callback to process and mix the audio tracks
2019
bool process(int numInputs, const AudioSampleFrame* inputs, int numOutputs, AudioSampleFrame* outputs, int numParams, const AudioParamFrame* params, void* __unused data) {
20+
#ifdef TEST_AND_EXIT
2121
audioProcessedCount++;
22+
#endif
2223

2324
// Single stereo output
2425
assert(numOutputs == 1 && outputs[0].numberOfChannels == 2);
@@ -93,7 +94,7 @@ EM_JS(void, doFade, (EMSCRIPTEN_AUDIO_WORKLET_NODE_T workletID), {
9394
// Registered keypress event to call the JS doFade()
9495
bool onPress(int __unused type, const EmscriptenKeyboardEvent* e, void* data) {
9596
if (!e->repeat && data) {
96-
printf("Toggling fade\n");
97+
emscripten_out("Toggling fade");
9798
doFade(VOIDP_2_WA(data));
9899
}
99100
return false;
@@ -102,12 +103,12 @@ bool onPress(int __unused type, const EmscriptenKeyboardEvent* e, void* data) {
102103
// Audio processor created, now register the audio callback
103104
void processorCreated(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* __unused data) {
104105
if (!success) {
105-
printf("Audio worklet node creation failed\n");
106+
assert("Audio worklet failed in processorCreated()" && success);
106107
return;
107108
}
108-
printf("Audio worklet processor created\n");
109-
printf("Click to toggle audio playback\n");
110-
printf("Keypress to fade the beat in or out\n");
109+
emscripten_out("Audio worklet processor created");
110+
emscripten_out("Click to toggle audio playback");
111+
emscripten_out("Keypress to fade the beat in or out");
111112

112113
// Stereo output, two inputs
113114
int outputChannelCounts[1] = { 2 };
@@ -135,17 +136,19 @@ void processorCreated(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* __unuse
135136
// And a keypress to do affect the fader
136137
emscripten_set_keypress_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, WA_2_VOIDP(worklet), false, &onPress);
137138

139+
#ifdef TEST_AND_EXIT
138140
// Register the counter that exits the test after one second of mixing
139141
emscripten_set_timeout_loop(&playedAndMixed, 16, NULL);
142+
#endif
140143
}
141144

142145
// Worklet thread inited, now create the audio processor
143146
void initialisedWithParams(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* __unused data) {
144147
if (!success) {
145-
printf("Audio worklet failed to initialise\n");
148+
assert("Audio worklet failed initialised()" && success);
146149
return;
147150
}
148-
printf("Audio worklet initialised\n");
151+
emscripten_out("Audio worklet initialised");
149152

150153
// Custom audio params we'll use as a fader
151154
WebAudioParamDescriptor faderParam[] = {

test/webaudio/audioworklet_test_shared.inc

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,21 @@
1111
#define __unused __attribute__((unused))
1212
#endif
1313

14-
// Count the audio callbacks and return after 375 frames (1 second with the default 128 size)
14+
// Count the audio callbacks and return after 375 frames (1 second with the
15+
// default 128 size).
1516
//
1617
// *** Remove this in your own code ***
1718
//
19+
#ifdef TEST_AND_EXIT
1820
volatile int audioProcessedCount = 0;
1921
bool playedAndMixed(double __unused time, void* __unused data) {
2022
if (audioProcessedCount >= 375) {
21-
emscripten_force_exit(0);
23+
emscripten_force_exit(EXIT_SUCCESS);
2224
return false;
2325
}
2426
return true;
2527
}
28+
#endif
2629

2730
// ID to the beat and bass loops
2831
EMSCRIPTEN_WEBAUDIO_T beatID = 0;
@@ -67,10 +70,10 @@ EM_JS(void, toggleTrack, (EMSCRIPTEN_WEBAUDIO_T srcID), {
6770
bool onClick(int __unused type, const EmscriptenMouseEvent* __unused e, void* data) {
6871
EMSCRIPTEN_WEBAUDIO_T ctx = VOIDP_2_WA(data);
6972
if (emscripten_audio_context_state(ctx) != AUDIO_CONTEXT_STATE_RUNNING) {
70-
printf("Resuming playback\n");
73+
emscripten_out("Resuming playback");
7174
emscripten_resume_audio_context_sync(ctx);
7275
}
73-
printf("Toggling audio playback\n");
76+
emscripten_out("Toggling audio playback");
7477
toggleTrack(beatID);
7578
toggleTrack(bassID);
7679
return false;
@@ -82,10 +85,10 @@ void processorCreated(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* data);
8285
// Worklet thread inited, now create the audio processor
8386
void initialised(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* __unused data) {
8487
if (!success) {
85-
printf("Audio worklet failed to initialise\n");
88+
assert("Audio worklet failed in initialised()" && success);
8689
return;
8790
}
88-
printf("Audio worklet initialised\n");
91+
emscripten_out("Audio worklet initialised");
8992

9093
WebAudioWorkletProcessorCreateOptions opts = {
9194
.name = "mixer"
@@ -99,16 +102,16 @@ EmscriptenStartWebAudioWorkletCallback getStartCallback(void);
99102
// Common entry point for the mixer tests
100103
int main(void) {
101104
char* const workletStack = memalign(16, AUDIO_STACK_SIZE);
102-
printf("Audio worklet stack at 0x%p\n", workletStack);
105+
emscripten_outf("Audio worklet stack at 0x%p", workletStack);
103106
assert(workletStack);
104107

105108
EMSCRIPTEN_WEBAUDIO_T context = emscripten_create_audio_context(NULL);
106109
emscripten_start_wasm_audio_worklet_thread_async(context, workletStack, AUDIO_STACK_SIZE, getStartCallback(), NULL);
107110

108-
#ifndef BROWSER_TEST
109-
// Special case: browser tests need to exit instantly, interactive tests need to wait
110-
emscripten_runtime_keepalive_push();
111-
#endif
111+
#ifdef TEST_AND_EXIT
112+
// We're in the test harness and exiting is via playedAndMixed()
113+
emscripten_exit_with_live_runtime();
114+
#endif
112115

113116
return EXIT_SUCCESS;
114117
}

0 commit comments

Comments
 (0)