|
1 | 1 | // Shared code for the audio worklet mixer tests.
|
2 | 2 |
|
| 3 | +// Defines an offset in GB from where to start the stack (for testing >2GB and |
| 4 | +// >4GB heaps). See _main_(). |
| 5 | +#ifndef TEST_OFFSET_GB |
| 6 | +#define TEST_OFFSET_GB 0 |
| 7 | +#endif |
| 8 | + |
3 | 9 | // Helper for MEMORY64 to cast an audio context or type to a void*
|
4 | 10 | #define WA_2_VOIDP(ctx) ((void*) (intptr_t) ctx)
|
5 | 11 | // Helper for MEMORY64 to cast a void* to an audio context or type
|
@@ -28,10 +34,10 @@ EM_JS(EMSCRIPTEN_WEBAUDIO_T, createTrack, (EMSCRIPTEN_WEBAUDIO_T ctxID, const ch
|
28 | 34 | var context = emscriptenGetAudioObject(ctxID);
|
29 | 35 | if (context) {
|
30 | 36 | var audio = document.createElement('audio');
|
31 |
| - |
32 |
| - // Workaround for UTF8ToString() needing a JS number |
33 |
| - url = Number(BigInt.asUintN(53, url)); |
34 |
| - |
| 37 | +#if __wasm64__ |
| 38 | + // Workaround for UTF8ToString() needing a JS number and from64() not working in EM_JS |
| 39 | + url = Number(url); |
| 40 | +#endif |
35 | 41 | audio.src = UTF8ToString(url);
|
36 | 42 | audio.loop = looping;
|
37 | 43 | var track = context.createMediaElementSource(audio);
|
@@ -86,18 +92,43 @@ void initialised(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* data) {
|
86 | 92 | emscripten_create_wasm_audio_worklet_processor_async(context, &opts, &processorCreated, NULL);
|
87 | 93 | }
|
88 | 94 |
|
89 |
| - |
90 | 95 | // Common entry point for the mixer tests
|
91 |
| -int main() { |
92 |
| - char* const emptySpace = malloc(2147483648); |
93 |
| - (void) emptySpace; |
94 |
| - char* const workletStack = malloc(AUDIO_STACK_SIZE); |
95 |
| - //static char workletStack[AUDIO_STACK_SIZE]; |
| 96 | +// stackSize - audio worklet stack size in bytes |
| 97 | +// return true if the requested memory could be allocated |
| 98 | +bool _main_(int stackSize) { |
| 99 | + // Optional empty space before the audio worklet's stack |
| 100 | +#if TEST_OFFSET_GB > 0 |
| 101 | + char* const emptySpace = malloc(1073741824L * TEST_OFFSET_GB); |
| 102 | + if (emptySpace) { |
| 103 | + printf("Empty space allocated (%dGB)\n", TEST_OFFSET_GB); |
| 104 | + } else { |
| 105 | + printf("Failed to allocate the required memory offset\n"); |
| 106 | + return false; |
| 107 | + } |
| 108 | +#endif |
| 109 | + |
| 110 | + char* const workletStack = memalign(16, stackSize); |
| 111 | + if (!workletStack) { |
| 112 | + printf("Failed to allocate the required worklet stack\n"); |
| 113 | + return false; |
| 114 | + } |
| 115 | + |
| 116 | +#if TEST_OFFSET_GB > 0 |
| 117 | + free(emptySpace); |
| 118 | +#endif |
| 119 | + |
96 | 120 | EMSCRIPTEN_WEBAUDIO_T context = emscripten_create_audio_context(NULL);
|
97 |
| - emscripten_start_wasm_audio_worklet_thread_async(context, workletStack, AUDIO_STACK_SIZE, &initialised, NULL); |
| 121 | + emscripten_start_wasm_audio_worklet_thread_async(context, workletStack, stackSize, &initialised, NULL); |
98 | 122 | #ifndef BROWSER_TEST
|
99 | 123 | // Special case: browser tests need to exit instantly, interactive tests need to wait
|
100 | 124 | emscripten_runtime_keepalive_push();
|
101 | 125 | #endif
|
102 |
| - return 0; |
| 126 | + return true; |
| 127 | +} |
| 128 | + |
| 129 | +int main() { |
| 130 | + if (_main_(AUDIO_STACK_SIZE)) { |
| 131 | + return EXIT_SUCCESS; |
| 132 | + } |
| 133 | + return EXIT_FAILURE; |
103 | 134 | }
|
0 commit comments