Skip to content

Commit 72a18eb

Browse files
authored
[AUDIO_WORKLET] fix emscripten_create_audio_context for wasm64 (#24866)
I spotted there was no coverage for `emscripten_create_audio_context()` and then that it fails with wasm64 (it accesses the heap directly). This is a minor fix with an addition to the test. Note: the code is slightly smaller than the original but still performs the same (omitting `latencyHint` or `sampleRate` results in `undefined`).
1 parent 6e482b5 commit 72a18eb

7 files changed

+30
-13
lines changed

src/lib/libwebaudio.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,10 @@ var LibraryWebAudio = {
5858
#if ASSERTIONS
5959
if (!ctx) console.error('emscripten_create_audio_context failed! Web Audio is not supported.');
6060
#endif
61-
options >>= 2;
6261

6362
var opts = options ? {
64-
latencyHint: HEAPU32[options] ? UTF8ToString(HEAPU32[options]) : undefined,
65-
sampleRate: HEAP32[options+1] || undefined
63+
latencyHint: UTF8ToString({{{ makeGetValue('options', C_STRUCTS.EmscriptenWebAudioCreateAttributes.latencyHint, '*') }}}) || undefined,
64+
sampleRate: {{{ makeGetValue('options', C_STRUCTS.EmscriptenWebAudioCreateAttributes.sampleRate, 'u32') }}} || undefined
6665
} : undefined;
6766

6867
#if WEBAUDIO_DEBUG

src/struct_info.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,11 @@
12661266
{
12671267
"file": "emscripten/webaudio.h",
12681268
"structs": {
1269-
"WebAudioParamDescriptor": [
1269+
"EmscriptenWebAudioCreateAttributes": [
1270+
"latencyHint",
1271+
"sampleRate"
1272+
],
1273+
"WebAudioParamDescriptor": [
12701274
"defaultValue",
12711275
"minValue",
12721276
"maxValue",

src/struct_info_generated.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,11 @@
695695
"hidden": 0,
696696
"visibilityState": 4
697697
},
698+
"EmscriptenWebAudioCreateAttributes": {
699+
"__size__": 8,
700+
"latencyHint": 0,
701+
"sampleRate": 4
702+
},
698703
"EmscriptenWebGLContextAttributes": {
699704
"__size__": 36,
700705
"alpha": 0,

src/struct_info_generated_wasm64.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,11 @@
695695
"hidden": 0,
696696
"visibilityState": 4
697697
},
698+
"EmscriptenWebAudioCreateAttributes": {
699+
"__size__": 16,
700+
"latencyHint": 0,
701+
"sampleRate": 8
702+
},
698703
"EmscriptenWebGLContextAttributes": {
699704
"__size__": 36,
700705
"alpha": 0,

test/code_size/audio_worklet_wasm.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ var M = [], N = a => {
121121
return e;
122122
}, ba = a => {
123123
var b = window.AudioContext || window.webkitAudioContext;
124-
if (a >>= 2) {
125-
var c = F[a] ? (c = F[a]) ? V(c) : "" : void 0;
124+
if (a) {
125+
var c = F[a >> 2];
126126
a = {
127-
latencyHint: c,
128-
sampleRate: L[a + 1] || void 0
127+
latencyHint: (c ? V(c) : "") || void 0,
128+
sampleRate: F[a + 4 >> 2] || void 0
129129
};
130130
} else a = void 0;
131131
if (c = b) b = new b(a), S[++T] = b, c = T;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 519,
33
"a.html.gz": 357,
4-
"a.js": 3875,
5-
"a.js.gz": 2040,
4+
"a.js": 3871,
5+
"a.js.gz": 2036,
66
"a.wasm": 1288,
77
"a.wasm.gz": 860,
8-
"total": 5682,
9-
"total_gz": 3257
8+
"total": 5678,
9+
"total_gz": 3253
1010
}

test/webaudio/audioworklet_test_shared.inc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ int main(void) {
9494
emscripten_outf("Audio worklet stack at 0x%p", workletStack);
9595
assert(workletStack);
9696

97-
EMSCRIPTEN_WEBAUDIO_T context = emscripten_create_audio_context(NULL);
97+
// Set at least the latency hint to test the attribute setting
98+
EmscriptenWebAudioCreateAttributes attrs = {
99+
.latencyHint = "balanced"
100+
};
101+
EMSCRIPTEN_WEBAUDIO_T context = emscripten_create_audio_context(&attrs);
98102
emscripten_start_wasm_audio_worklet_thread_async(context, workletStack, AUDIO_STACK_SIZE, getStartCallback(), NULL);
99103

100104
#ifdef TEST_AND_EXIT

0 commit comments

Comments
 (0)