|
5 | 5 | // and the Audio Worklet thread using the
|
6 | 6 | // emscripten_audio_worklet_post_function_*() API.
|
7 | 7 |
|
8 |
| -// This event will fire on the main thread. |
9 |
| -void MessageReceivedOnMainThread(int d, int e, int f) { |
10 |
| - emscripten_outf("MessageReceivedOnMainThread: d=%d, e=%d, f=%d", d, e, f); |
11 |
| - assert(!emscripten_current_thread_is_audio_worklet()); |
12 |
| - assert(d == 1 && e == 2 && f == 3); |
| 8 | +// This test consists of two steps |
| 9 | +// 1. post function from main thread to audio worklet thread, with onAudioWorkletThread = true |
| 10 | +// 2. post function from audio worklet thread to main thread, with onAudioWorkletThread = false |
| 11 | +_Atomic bool onAudioWorkletThread = true; |
| 12 | +_Atomic uint32_t callbackCount = 0; |
13 | 13 |
|
14 |
| - // test succeeded, were able to post a message from main thread to audio thread and back! |
15 |
| - emscripten_force_exit(0); |
| 14 | +// v, vi, vii, viii, vd, vdd, vddd, viiiiiidddddd |
| 15 | +// 8 callbacks be invoked twice, once with audio worklet thread, once with main thread. |
| 16 | +// Each callbacks check the correctivity of argument and running thread. |
| 17 | +void v() { |
| 18 | + assert(onAudioWorkletThread == emscripten_current_thread_is_audio_worklet()); |
| 19 | + emscripten_out("v"); |
| 20 | + ++callbackCount; |
16 | 21 | }
|
17 | 22 |
|
18 |
| -// This event will fire on the audio worklet thread. |
19 |
| -void MessageReceivedInAudioWorkletThread(int a, int b) { |
20 |
| - emscripten_outf("MessageReceivedInAudioWorkletThread: a=%d, b=%d", a, b); |
21 |
| - assert(emscripten_current_thread_is_audio_worklet()); |
22 |
| - assert(a == 42 && b == 9000); |
23 |
| - emscripten_audio_worklet_post_function_viii(EMSCRIPTEN_AUDIO_MAIN_THREAD, MessageReceivedOnMainThread, /*d=*/1, /*e=*/2, /*f=*/3); |
| 23 | +void vi(int i) { |
| 24 | + assert(onAudioWorkletThread == emscripten_current_thread_is_audio_worklet()); |
| 25 | + emscripten_out("vi"); |
| 26 | + assert(i == 1); |
| 27 | + ++callbackCount; |
| 28 | +} |
| 29 | + |
| 30 | +void vii(int i, int j) { |
| 31 | + assert(onAudioWorkletThread == emscripten_current_thread_is_audio_worklet()); |
| 32 | + emscripten_out("vii"); |
| 33 | + assert(i == 2); |
| 34 | + assert(j == 3); |
| 35 | + ++callbackCount; |
| 36 | +} |
| 37 | + |
| 38 | +void viii(int i, int j, int k) { |
| 39 | + assert(onAudioWorkletThread == emscripten_current_thread_is_audio_worklet()); |
| 40 | + emscripten_out("viii"); |
| 41 | + assert(i == 4); |
| 42 | + assert(j == 5); |
| 43 | + assert(k == 6); |
| 44 | + ++callbackCount; |
| 45 | +} |
| 46 | + |
| 47 | +void vd(double i) { |
| 48 | + assert(onAudioWorkletThread == emscripten_current_thread_is_audio_worklet()); |
| 49 | + emscripten_out("vd"); |
| 50 | + assert(i == 1.5); |
| 51 | + ++callbackCount; |
| 52 | +} |
| 53 | + |
| 54 | +void vdd(double i, double j) { |
| 55 | + assert(onAudioWorkletThread == emscripten_current_thread_is_audio_worklet()); |
| 56 | + emscripten_out("vdd"); |
| 57 | + assert(i == 2.5); |
| 58 | + assert(j == 3.5); |
| 59 | + ++callbackCount; |
| 60 | +} |
| 61 | + |
| 62 | +void vddd(double i, double j, double k) { |
| 63 | + assert(onAudioWorkletThread == emscripten_current_thread_is_audio_worklet()); |
| 64 | + emscripten_out("vddd"); |
| 65 | + assert(i == 4.5); |
| 66 | + assert(j == 5.5); |
| 67 | + assert(k == 6.5); |
| 68 | + ++callbackCount; |
| 69 | +} |
| 70 | + |
| 71 | +void viiiiiidddddd(int a, int b, int c, int d, int e, int f, double g, double h, double i, double j, double k, double l) { |
| 72 | + assert(onAudioWorkletThread == emscripten_current_thread_is_audio_worklet()); |
| 73 | + emscripten_out("viiiiiidddddd"); |
| 74 | + assert(a == 10); |
| 75 | + assert(b == 11); |
| 76 | + assert(c == 12); |
| 77 | + assert(d == 13); |
| 78 | + assert(e == 14); |
| 79 | + assert(f == 15); |
| 80 | + assert(g == 16.5); |
| 81 | + assert(h == 17.5); |
| 82 | + assert(i == 18.5); |
| 83 | + assert(j == 19.5); |
| 84 | + assert(k == 20.5); |
| 85 | + assert(l == 21.5); |
| 86 | + ++callbackCount; |
| 87 | +} |
| 88 | + |
| 89 | +void sided_test_finished() { |
| 90 | + assert(onAudioWorkletThread == emscripten_current_thread_is_audio_worklet()); |
| 91 | + |
| 92 | + if (onAudioWorkletThread) { // for the first call, finishing checks for main -> audio worklet |
| 93 | + onAudioWorkletThread = false; |
| 94 | + |
| 95 | + // These event will fire callbacks on main thread. |
| 96 | + emscripten_audio_worklet_post_function_v(EMSCRIPTEN_AUDIO_MAIN_THREAD, v); |
| 97 | + emscripten_audio_worklet_post_function_vi(EMSCRIPTEN_AUDIO_MAIN_THREAD, vi, 1); |
| 98 | + emscripten_audio_worklet_post_function_vii(EMSCRIPTEN_AUDIO_MAIN_THREAD, vii, 2, 3); |
| 99 | + emscripten_audio_worklet_post_function_viii(EMSCRIPTEN_AUDIO_MAIN_THREAD, viii, 4, 5, 6); |
| 100 | + emscripten_audio_worklet_post_function_vd(EMSCRIPTEN_AUDIO_MAIN_THREAD, vd, 1.5); |
| 101 | + emscripten_audio_worklet_post_function_vdd(EMSCRIPTEN_AUDIO_MAIN_THREAD, vdd, 2.5, 3.5); |
| 102 | + emscripten_audio_worklet_post_function_vddd(EMSCRIPTEN_AUDIO_MAIN_THREAD, vddd, 4.5, 5.5, 6.5); |
| 103 | + emscripten_audio_worklet_post_function_sig(EMSCRIPTEN_AUDIO_MAIN_THREAD, viiiiiidddddd, "iiiiiidddddd", 10, 11, 12, 13, 14, 15, 16.5, 17.5, 18.5, 19.5, 20.5, 21.5); |
| 104 | + emscripten_audio_worklet_post_function_v(EMSCRIPTEN_AUDIO_MAIN_THREAD, sided_test_finished); |
| 105 | + } else { // for the second call, finishing checks for audio worklet -> main |
| 106 | + assert(callbackCount == 16); |
| 107 | + emscripten_force_exit(0); |
| 108 | + } |
24 | 109 | }
|
25 | 110 |
|
26 | 111 | // This callback will fire when the audio worklet thread has been initialized.
|
27 | 112 | void WebAudioWorkletThreadInitialized(EMSCRIPTEN_WEBAUDIO_T audioContext, bool success, void *userData) {
|
28 | 113 | emscripten_out("WebAudioWorkletThreadInitialized");
|
29 |
| - emscripten_audio_worklet_post_function_vii(audioContext, MessageReceivedInAudioWorkletThread, /*a=*/42, /*b=*/9000); |
| 114 | + |
| 115 | + // These event will fire callbacks on audio worklet thread. |
| 116 | + emscripten_audio_worklet_post_function_v(audioContext, v); |
| 117 | + emscripten_audio_worklet_post_function_vi(audioContext, vi, 1); |
| 118 | + emscripten_audio_worklet_post_function_vii(audioContext, vii, 2, 3); |
| 119 | + emscripten_audio_worklet_post_function_viii(audioContext, viii, 4, 5, 6); |
| 120 | + emscripten_audio_worklet_post_function_vd(audioContext, vd, 1.5); |
| 121 | + emscripten_audio_worklet_post_function_vdd(audioContext, vdd, 2.5, 3.5); |
| 122 | + emscripten_audio_worklet_post_function_vddd(audioContext, vddd, 4.5, 5.5, 6.5); |
| 123 | + emscripten_audio_worklet_post_function_sig(audioContext, viiiiiidddddd, "iiiiiidddddd", 10, 11, 12, 13, 14, 15, 16.5, 17.5, 18.5, 19.5, 20.5, 21.5); |
| 124 | + emscripten_audio_worklet_post_function_v(audioContext, sided_test_finished); |
30 | 125 | }
|
31 | 126 |
|
32 | 127 | uint8_t wasmAudioWorkletStack[4096];
|
|
0 commit comments