Skip to content

Commit dff172c

Browse files
committed
Migrated the interactive tests to btest_exit
1 parent b14084f commit dff172c

File tree

4 files changed

+45
-44
lines changed

4 files changed

+45
-44
lines changed

test/webaudio/audioworklet_2x_in_hard_pan.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@
1616
// Helper for MEMORY64 to cast a void* to an audio context or type
1717
#define VOIDP_2_WA(ptr) ((EMSCRIPTEN_WEBAUDIO_T) (intptr_t) ptr)
1818

19-
// REPORT_RESULT is defined when running in Emscripten test harness.
20-
#ifdef REPORT_RESULT
21-
// Count the mixed frames and return after 375 frames (1 second with the default 128 size)
19+
20+
// Count the audio callbacks and return after 375 frames (1 second with the default 128 size)
21+
//
22+
// *** Remove this in your own code ***
23+
//
2224
volatile int audioProcessedCount = 0;
2325
bool playedAndMixed(double time, void* data) {
2426
if (audioProcessedCount >= 375) {
25-
REPORT_RESULT(0);
27+
emscripten_force_exit(0);
2628
return false;
2729
}
2830
return true;
2931
}
30-
#endif
3132

3233
// ID to the beat and bass loops
3334
EMSCRIPTEN_WEBAUDIO_T beatID = 0;
@@ -65,9 +66,8 @@ EM_JS(void, toggleTrack, (EMSCRIPTEN_WEBAUDIO_T srcID), {
6566

6667
// Callback to process and copy the audio tracks
6768
bool process(int numInputs, const AudioSampleFrame* inputs, int numOutputs, AudioSampleFrame* outputs, int numParams, const AudioParamFrame* params, void* data) {
68-
#ifdef REPORT_RESULT
6969
audioProcessedCount++;
70-
#endif
70+
7171
// Twin mono in, single stereo out
7272
assert(numInputs == 2 && numOutputs == 1);
7373
assert(inputs[0].numberOfChannels == 1 && inputs[1].numberOfChannels == 1);
@@ -121,12 +121,12 @@ void processorCreated(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* data) {
121121
if (bassID) {
122122
emscripten_audio_node_connect(bassID, worklet, 0, 1);
123123
}
124-
124+
125+
// Register a click to start playback
125126
emscripten_set_click_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, WA_2_VOIDP(context), false, &onClick);
126-
127-
#ifdef REPORT_RESULT
127+
128+
// Register the counter that exits the test after one second of mixing
128129
emscripten_set_timeout_loop(&playedAndMixed, 16, NULL);
129-
#endif
130130
} else {
131131
printf("Audio worklet node creation failed\n");
132132
}
@@ -150,5 +150,6 @@ int main() {
150150
static char workletStack[AUDIO_STACK_SIZE];
151151
EMSCRIPTEN_WEBAUDIO_T context = emscripten_create_audio_context(NULL);
152152
emscripten_start_wasm_audio_worklet_thread_async(context, workletStack, sizeof workletStack, &initialised, NULL);
153+
emscripten_runtime_keepalive_push();
153154
return 0;
154155
}

test/webaudio/audioworklet_2x_in_out_stereo.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
// Helper for MEMORY64 to cast a void* to an audio context or type
1616
#define VOIDP_2_WA(ptr) ((EMSCRIPTEN_WEBAUDIO_T) (intptr_t) ptr)
1717

18-
// REPORT_RESULT is defined when running in Emscripten test harness.
19-
#ifdef REPORT_RESULT
20-
// Count the mixed frames and return after 375 frames (1 second with the default 128 size)
18+
// Count the audio callbacks and return after 375 frames (1 second with the default 128 size)
19+
//
20+
// *** Remove this in your own code ***
21+
//
2122
volatile int audioProcessedCount = 0;
2223
bool playedAndMixed(double time, void* data) {
2324
if (audioProcessedCount >= 375) {
24-
REPORT_RESULT(0);
25+
emscripten_force_exit(0);
2526
return false;
2627
}
2728
return true;
2829
}
29-
#endif
3030

3131
// ID to the beat and bass loops
3232
EMSCRIPTEN_WEBAUDIO_T beatID = 0;
@@ -64,9 +64,8 @@ EM_JS(void, toggleTrack, (EMSCRIPTEN_WEBAUDIO_T srcID), {
6464

6565
// Callback to process and copy the audio tracks
6666
bool process(int numInputs, const AudioSampleFrame* inputs, int numOutputs, AudioSampleFrame* outputs, int numParams, const AudioParamFrame* params, void* data) {
67-
#ifdef REPORT_RESULT
6867
audioProcessedCount++;
69-
#endif
68+
7069
// Twin stereo in and out
7170
assert(numInputs == 2 && numOutputs == 2);
7271
assert(inputs[0].numberOfChannels == 2 && inputs[1].numberOfChannels == 2);
@@ -123,12 +122,12 @@ void processorCreated(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* data) {
123122
if (bassID) {
124123
emscripten_audio_node_connect(bassID, worklet, 0, 1);
125124
}
126-
125+
126+
// Register a click to start playback
127127
emscripten_set_click_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, WA_2_VOIDP(context), false, &onClick);
128-
129-
#ifdef REPORT_RESULT
128+
129+
// Register the counter that exits the test after one second of mixing
130130
emscripten_set_timeout_loop(&playedAndMixed, 16, NULL);
131-
#endif
132131
} else {
133132
printf("Audio worklet node creation failed\n");
134133
}
@@ -152,5 +151,6 @@ int main() {
152151
static char workletStack[AUDIO_STACK_SIZE];
153152
EMSCRIPTEN_WEBAUDIO_T context = emscripten_create_audio_context(NULL);
154153
emscripten_start_wasm_audio_worklet_thread_async(context, workletStack, sizeof workletStack, &initialised, NULL);
154+
emscripten_runtime_keepalive_push();
155155
return 0;
156156
}

test/webaudio/audioworklet_in_out_mono.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616
// Helper for MEMORY64 to cast a void* to an audio context or type
1717
#define VOIDP_2_WA(ptr) ((EMSCRIPTEN_WEBAUDIO_T) (intptr_t) ptr)
1818

19-
// REPORT_RESULT is defined when running in Emscripten test harness.
20-
#ifdef REPORT_RESULT
21-
// Count the mixed frames and return after 375 frames (1 second with the default 128 size)
19+
// Count the audio callbacks and return after 375 frames (1 second with the default 128 size)
20+
//
21+
// *** Remove this in your own code ***
22+
//
2223
volatile int audioProcessedCount = 0;
2324
bool playedAndMixed(double time, void* data) {
2425
if (audioProcessedCount >= 375) {
25-
REPORT_RESULT(0);
26+
emscripten_force_exit(0);
2627
return false;
2728
}
2829
return true;
2930
}
30-
#endif
3131

3232
// ID to the beat and bass loops
3333
EMSCRIPTEN_WEBAUDIO_T beatID = 0;
@@ -65,9 +65,8 @@ EM_JS(void, toggleTrack, (EMSCRIPTEN_WEBAUDIO_T srcID), {
6565

6666
// Callback to process and mix the audio tracks
6767
bool process(int numInputs, const AudioSampleFrame* inputs, int numOutputs, AudioSampleFrame* outputs, int numParams, const AudioParamFrame* params, void* data) {
68-
#ifdef REPORT_RESULT
6968
audioProcessedCount++;
70-
#endif
69+
7170
// Single mono output
7271
assert(numOutputs == 1 && outputs[0].numberOfChannels == 1);
7372
for (int n = 0; n < numInputs; n++) {
@@ -133,12 +132,12 @@ void processorCreated(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* data) {
133132
if (bassID) {
134133
emscripten_audio_node_connect(bassID, worklet, 0, 1);
135134
}
136-
135+
136+
// Register a click to start playback
137137
emscripten_set_click_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, WA_2_VOIDP(context), false, &onClick);
138-
139-
#ifdef REPORT_RESULT
138+
139+
// Register the counter that exits the test after one second of mixing
140140
emscripten_set_timeout_loop(&playedAndMixed, 16, NULL);
141-
#endif
142141
} else {
143142
printf("Audio worklet node creation failed\n");
144143
}
@@ -162,5 +161,6 @@ int main() {
162161
static char workletStack[AUDIO_STACK_SIZE];
163162
EMSCRIPTEN_WEBAUDIO_T context = emscripten_create_audio_context(NULL);
164163
emscripten_start_wasm_audio_worklet_thread_async(context, workletStack, sizeof workletStack, &initialised, NULL);
164+
emscripten_runtime_keepalive_push();
165165
return 0;
166166
}

test/webaudio/audioworklet_in_out_stereo.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616
// Helper for MEMORY64 to cast a void* to an audio context or type
1717
#define VOIDP_2_WA(ptr) ((EMSCRIPTEN_WEBAUDIO_T) (intptr_t) ptr)
1818

19-
// REPORT_RESULT is defined when running in Emscripten test harness.
20-
#ifdef REPORT_RESULT
21-
// Count the mixed frames and return after 375 frames (1 second with the default 128 size)
19+
// Count the audio callbacks and return after 375 frames (1 second with the default 128 size)
20+
//
21+
// *** Remove this in your own code ***
22+
//
2223
volatile int audioProcessedCount = 0;
2324
bool playedAndMixed(double time, void* data) {
2425
if (audioProcessedCount >= 375) {
25-
REPORT_RESULT(0);
26+
emscripten_force_exit(0);
2627
return false;
2728
}
2829
return true;
2930
}
30-
#endif
3131

3232
// ID to the beat and bass loops
3333
EMSCRIPTEN_WEBAUDIO_T beatID = 0;
@@ -65,9 +65,8 @@ EM_JS(void, toggleTrack, (EMSCRIPTEN_WEBAUDIO_T srcID), {
6565

6666
// Callback to process and mix the audio tracks
6767
bool process(int numInputs, const AudioSampleFrame* inputs, int numOutputs, AudioSampleFrame* outputs, int numParams, const AudioParamFrame* params, void* data) {
68-
#ifdef REPORT_RESULT
6968
audioProcessedCount++;
70-
#endif
69+
7170
// Single stereo output
7271
assert(numOutputs == 1 && outputs[0].numberOfChannels == 2);
7372
for (int n = 0; n < numInputs; n++) {
@@ -133,12 +132,12 @@ void processorCreated(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* data) {
133132
if (bassID) {
134133
emscripten_audio_node_connect(bassID, worklet, 0, 1);
135134
}
136-
135+
136+
// Register a click to start playback
137137
emscripten_set_click_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, WA_2_VOIDP(context), false, &onClick);
138-
139-
#ifdef REPORT_RESULT
138+
139+
// Register the counter that exits the test after one second of mixing
140140
emscripten_set_timeout_loop(&playedAndMixed, 16, NULL);
141-
#endif
142141
} else {
143142
printf("Audio worklet node creation failed\n");
144143
}
@@ -162,5 +161,6 @@ int main() {
162161
static char workletStack[AUDIO_STACK_SIZE];
163162
EMSCRIPTEN_WEBAUDIO_T context = emscripten_create_audio_context(NULL);
164163
emscripten_start_wasm_audio_worklet_thread_async(context, workletStack, sizeof workletStack, &initialised, NULL);
164+
emscripten_runtime_keepalive_push();
165165
return 0;
166166
}

0 commit comments

Comments
 (0)