|
5 | 5 | #include <emscripten/webaudio.h> |
6 | 6 |
|
7 | 7 | // Tests processing two stereo audio inputs being mixed to a single stereo audio |
8 | | -// output in process(), then applying a fade from the parameters. |
| 8 | +// output in process(), then applying a fade from the parameters. Since this can |
| 9 | +// create variable parameter data sizes, depending on the browser, it's also the |
| 10 | +// ideal to test audio worklets don't corrupt TLS variables. |
9 | 11 |
|
10 | 12 | // This needs to be big enough for the stereo output, 2x inputs, 2x params and |
11 | 13 | // the worker stack. To note that different browsers have different stack size |
|
15 | 17 | // Shared file playback and bootstrap |
16 | 18 | #include "audioworklet_test_shared.inc" |
17 | 19 |
|
| 20 | +// TLS test value to verify the JS-side stays within its stack frame (this is |
| 21 | +// zeroed in the *main* thread on startup). |
| 22 | +__thread int tlsTest = 0x1337D00D; |
| 23 | + |
18 | 24 | // Callback to process and mix the audio tracks |
19 | 25 | bool process(int numInputs, const AudioSampleFrame* inputs, int numOutputs, AudioSampleFrame* outputs, int numParams, const AudioParamFrame* params, void* data) { |
20 | 26 | #ifdef TEST_AND_EXIT |
21 | 27 | audioProcessedCount++; |
22 | 28 | #endif |
23 | 29 |
|
| 30 | + // JS-setup code shouldn't stomp on this, plus the main thread didn't clear it |
| 31 | + assert(tlsTest == 0x1337D00D); |
24 | 32 | // Single stereo output |
25 | 33 | assert(numOutputs == 1); |
26 | 34 | assert(outputs[0].numberOfChannels == 2); |
@@ -145,6 +153,8 @@ void initialisedWithParams(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* da |
145 | 153 | assert(success && "Audio worklet failed initialised()"); |
146 | 154 | emscripten_out("Audio worklet initialised"); |
147 | 155 |
|
| 156 | + // Clear the TLS variable (from the main thread) |
| 157 | + tlsTest = 0; |
148 | 158 | // Custom audio params we'll use as a fader |
149 | 159 | WebAudioParamDescriptor faderParam[] = { |
150 | 160 | { |
|
0 commit comments