Skip to content

Commit 3073806

Browse files
authored
Fix automatic run of interactive web audio tests. (#22509)
Audio contexts cannot start until human interacts with the page, e.g. by clicking a button. Therefore interactive audioworklet tests require user to press a button. However, after clicking a button, all later interactive tests will have the audio context access already unlocked, so user does not need to click a button on each test when running multiple audio worklet tests, only the first one. In such scenario, there was a bug that nothing played back from speakers on later tests, because the audio worklet was not connected to output on those later tests until user clicks a button. But since this button click was not needed, the subsequent interactive tests would surprisingly pass without actually playing back any audio.
1 parent 8969fd2 commit 3073806

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

test/webaudio/audio_worklet_tone_generator.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ void AudioWorkletProcessorCreated(EMSCRIPTEN_WEBAUDIO_T audioContext, EM_BOOL su
8484

8585
EM_ASM({
8686
let audioContext = emscriptenGetAudioObject($0);
87+
let audioWorkletNode = emscriptenGetAudioObject($1);
88+
// Connect the audio worklet node to the graph.
89+
audioWorkletNode.connect(audioContext.destination);
8790

8891
// Add a button on the page to toggle playback as a response to user click.
8992
let startButton = document.createElement('button');
@@ -93,10 +96,6 @@ void AudioWorkletProcessorCreated(EMSCRIPTEN_WEBAUDIO_T audioContext, EM_BOOL su
9396
startButton.onclick = () => {
9497
if (audioContext.state != 'running') {
9598
audioContext.resume();
96-
let audioWorkletNode = emscriptenGetAudioObject($1);
97-
98-
// Connect the audio worklet node to the graph.
99-
audioWorkletNode.connect(audioContext.destination);
10099
} else {
101100
audioContext.suspend();
102101
}

test/webaudio/audioworklet.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ EM_BOOL ProcessAudio(int numInputs, const AudioSampleFrame *inputs, int numOutpu
5050
EM_JS(void, InitHtmlUi, (EMSCRIPTEN_WEBAUDIO_T audioContext, EMSCRIPTEN_AUDIO_WORKLET_NODE_T audioWorkletNode), {
5151
audioContext = emscriptenGetAudioObject(audioContext);
5252
audioWorkletNode = emscriptenGetAudioObject(audioWorkletNode);
53+
// Connect the audio worklet node to the graph.
54+
audioWorkletNode.connect(audioContext.destination);
5355

5456
// Add a button on the page to toggle playback as a response to user click.
5557
let startButton = document.createElement('button');
@@ -59,8 +61,6 @@ EM_JS(void, InitHtmlUi, (EMSCRIPTEN_WEBAUDIO_T audioContext, EMSCRIPTEN_AUDIO_WO
5961
startButton.onclick = () => {
6062
if (audioContext.state != 'running') {
6163
audioContext.resume();
62-
// Connect the audio worklet node to the graph.
63-
audioWorkletNode.connect(audioContext.destination);
6464
} else {
6565
audioContext.suspend();
6666
}

test/webaudio/audioworklet_emscripten_futex_wake.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ EM_BOOL ProcessAudio(int numInputs, const AudioSampleFrame *inputs, int numOutpu
2929
EM_JS(void, InitHtmlUi, (EMSCRIPTEN_WEBAUDIO_T audioContext, EMSCRIPTEN_AUDIO_WORKLET_NODE_T audioWorkletNode), {
3030
audioContext = emscriptenGetAudioObject(audioContext);
3131
audioWorkletNode = emscriptenGetAudioObject(audioWorkletNode);
32+
audioWorkletNode.connect(audioContext.destination);
3233
let startButton = document.createElement('button');
3334
startButton.innerHTML = 'Start playback';
3435
document.body.appendChild(startButton);
3536

3637
startButton.onclick = () => {
37-
audioWorkletNode.connect(audioContext.destination);
3838
audioContext.resume();
3939
};
4040
});

0 commit comments

Comments
 (0)