Skip to content

Commit 85e2276

Browse files
authored
[AUDIO_WORKLET] Add TLS variable test NFC (#25024)
As per @juj's suggestion, this extends one of the audio playback tests to also verify the JS set-up code doesn't stomp on the TLS section. This mixer test is idea since the param data can grow and shrink during playback.
1 parent 21b8f91 commit 85e2276

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

test/webaudio/audioworklet_params_mixing.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
#include <emscripten/webaudio.h>
66

77
// 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.
911

1012
// This needs to be big enough for the stereo output, 2x inputs, 2x params and
1113
// the worker stack. To note that different browsers have different stack size
@@ -15,12 +17,18 @@
1517
// Shared file playback and bootstrap
1618
#include "audioworklet_test_shared.inc"
1719

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+
1824
// Callback to process and mix the audio tracks
1925
bool process(int numInputs, const AudioSampleFrame* inputs, int numOutputs, AudioSampleFrame* outputs, int numParams, const AudioParamFrame* params, void* data) {
2026
#ifdef TEST_AND_EXIT
2127
audioProcessedCount++;
2228
#endif
2329

30+
// JS-setup code shouldn't stomp on this, plus the main thread didn't clear it
31+
assert(tlsTest == 0x1337D00D);
2432
// Single stereo output
2533
assert(numOutputs == 1);
2634
assert(outputs[0].numberOfChannels == 2);
@@ -145,6 +153,8 @@ void initialisedWithParams(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* da
145153
assert(success && "Audio worklet failed initialised()");
146154
emscripten_out("Audio worklet initialised");
147155

156+
// Clear the TLS variable (from the main thread)
157+
tlsTest = 0;
148158
// Custom audio params we'll use as a fader
149159
WebAudioParamDescriptor faderParam[] = {
150160
{

0 commit comments

Comments
 (0)