Skip to content

Commit 99b77d0

Browse files
authored
[AUDIO_WORKLET] Use meaningful/unquoted properties messages. NFC (#24229)
Now that audio worklet code is part of the main JS it all gets compiled together so this minification and quoting to make closure happy is no longer needed.
1 parent 2b9753f commit 99b77d0

File tree

4 files changed

+50
-50
lines changed

4 files changed

+50
-50
lines changed

src/audio_worklet.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ function createWasmAudioWorkletProcessor(audioParams) {
2121

2222
// Capture the Wasm function callback to invoke.
2323
let opts = args.processorOptions;
24-
this.callbackFunction = wasmTable.get(opts['cb']);
25-
this.userData = opts['ud'];
24+
#if ASSERTIONS
25+
assert(opts.callback)
26+
assert(opts.samplesPerChannel)
27+
#endif
28+
this.callback = wasmTable.get(opts.callback);
29+
this.userData = opts.userData;
2630
// Then the samples per channel to process, fixed for the lifetime of the
2731
// context that created this processor. Note for when moving to Web Audio
2832
// 1.1: the typed array passed to process() should be the same size as this
2933
// 'render quantum size', and this exercise of passing in the value
30-
// shouldn't be required (to be verified).
31-
this.samplesPerChannel = opts['sc'];
34+
// shouldn't be required (to be verified)
35+
this.samplesPerChannel = opts.samplesPerChannel;
3236
}
3337

3438
static get parameterDescriptors() {
@@ -106,7 +110,7 @@ function createWasmAudioWorkletProcessor(audioParams) {
106110
}
107111

108112
// Call out to Wasm callback to perform audio processing
109-
if (didProduceAudio = this.callbackFunction(numInputs, inputsPtr, numOutputs, outputsPtr, numParams, paramsPtr, this.userData)) {
113+
if (didProduceAudio = this.callback(numInputs, inputsPtr, numOutputs, outputsPtr, numParams, paramsPtr, this.userData)) {
110114
// Read back the produced audio data to all outputs and their channels.
111115
// (A garbage-free function TypedArray.copy(dstTypedArray, dstOffset,
112116
// srcTypedArray, srcOffset, count) would sure be handy.. but web does
@@ -138,7 +142,7 @@ var messagePort;
138142
class BootstrapMessages extends AudioWorkletProcessor {
139143
constructor(arg) {
140144
super();
141-
startWasmWorker(arg['processorOptions'])
145+
startWasmWorker(arg.processorOptions)
142146
#if WEBAUDIO_DEBUG
143147
console.log('AudioWorklet global scope looks like this:');
144148
console.dir(globalThis);
@@ -154,28 +158,24 @@ class BootstrapMessages extends AudioWorkletProcessor {
154158
// '_wpn' is short for 'Worklet Processor Node', using an identifier
155159
// that will never conflict with user messages
156160
// Register a real AudioWorkletProcessor that will actually do audio processing.
157-
// 'ap' being the audio params
158-
registerProcessor(d['_wpn'], createWasmAudioWorkletProcessor(d['ap']));
161+
registerProcessor(d['_wpn'], createWasmAudioWorkletProcessor(d.audioParams));
159162
#if WEBAUDIO_DEBUG
160-
console.log(`Registered a new WasmAudioWorkletProcessor "${d['_wpn']}" with AudioParams: ${d['ap']}`);
163+
console.log(`Registered a new WasmAudioWorkletProcessor "${d['_wpn']}" with AudioParams: ${d.audioParams}`);
161164
#endif
162165
// Post a Wasm Call message back telling that we have now registered the
163166
// AudioWorkletProcessor, and should trigger the user onSuccess callback
164167
// of the emscripten_create_wasm_audio_worklet_processor_async() call.
165168
//
166169
// '_wsc' is short for 'wasm call', using an identifier that will never
167170
// conflict with user messages
168-
// 'cb' the callback function
169-
// 'ch' the context handle
170-
// 'ud' the passed user data
171-
messagePort.postMessage({'_wsc': d['cb'], 'x': [d['ch'], 1/*EM_TRUE*/, d['ud']] });
171+
messagePort.postMessage({'_wsc': d.callback, args: [d.contextHandle, 1/*EM_TRUE*/, d.userData] });
172172
} else if (d['_wsc']) {
173173
#if MEMORY64
174174
var ptr = BigInt(d['_wsc']);
175175
#else
176176
var ptr = d['_wsc'];
177177
#endif
178-
wasmTable.get(ptr)(...d['x']);
178+
wasmTable.get(ptr)(...d.args);
179179
};
180180
}
181181
}

src/lib/libwebaudio.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ let LibraryWebAudio = {
211211
// '_wsc' is short for 'wasm call', trying to use an identifier name that
212212
// will never conflict with user code
213213
let wasmCall = data['_wsc'];
214-
wasmCall && getWasmTableEntry(wasmCall)(...data['x']);
214+
wasmCall && getWasmTableEntry(wasmCall)(...data.args);
215215
},
216216

217217
emscripten_create_wasm_audio_worklet_processor_async: (contextHandle, options, callback, userData) => {
@@ -247,10 +247,10 @@ let LibraryWebAudio = {
247247
// not get accidentally mixed with user submitted messages, the remainder
248248
// for space saving reasons, abbreviated from their variable names).
249249
'_wpn': UTF8ToString(HEAPU32[options]),
250-
'ap': audioParams,
251-
'ch': contextHandle,
252-
'cb': callback,
253-
'ud': userData
250+
audioParams,
251+
contextHandle,
252+
callback,
253+
userData,
254254
});
255255
},
256256

@@ -274,9 +274,9 @@ let LibraryWebAudio = {
274274
numberOfOutputs: HEAP32[options+1],
275275
outputChannelCount: HEAPU32[options+2] ? readChannelCountArray(HEAPU32[options+2]>>2, HEAP32[options+1]) : void 0,
276276
processorOptions: {
277-
'cb': callback,
278-
'ud': userData,
279-
'sc': emscriptenGetContextQuantumSize(contextHandle)
277+
callback,
278+
userData,
279+
samplesPerChannel: emscriptenGetContextQuantumSize(contextHandle),
280280
}
281281
} : void 0;
282282

@@ -315,11 +315,11 @@ let LibraryWebAudio = {
315315
emscripten_current_thread_is_audio_worklet: () => typeof AudioWorkletGlobalScope !== 'undefined',
316316

317317
emscripten_audio_worklet_post_function_v: (audioContext, funcPtr) => {
318-
(audioContext ? EmAudio[audioContext].audioWorklet.bootstrapMessage.port : messagePort).postMessage({'_wsc': funcPtr, 'x': [] }); // "WaSm Call"
318+
(audioContext ? EmAudio[audioContext].audioWorklet.bootstrapMessage.port : messagePort).postMessage({'_wsc': funcPtr, args: [] }); // "WaSm Call"
319319
},
320320

321321
$emscripten_audio_worklet_post_function_1: (audioContext, funcPtr, arg0) => {
322-
(audioContext ? EmAudio[audioContext].audioWorklet.bootstrapMessage.port : messagePort).postMessage({'_wsc': funcPtr, 'x': [arg0] }); // "WaSm Call"
322+
(audioContext ? EmAudio[audioContext].audioWorklet.bootstrapMessage.port : messagePort).postMessage({'_wsc': funcPtr, args: [arg0] }); // "WaSm Call"
323323
},
324324

325325
emscripten_audio_worklet_post_function_vi__deps: ['$emscripten_audio_worklet_post_function_1'],
@@ -333,7 +333,7 @@ let LibraryWebAudio = {
333333
},
334334

335335
$emscripten_audio_worklet_post_function_2: (audioContext, funcPtr, arg0, arg1) => {
336-
(audioContext ? EmAudio[audioContext].audioWorklet.bootstrapMessage.port : messagePort).postMessage({'_wsc': funcPtr, 'x': [arg0, arg1] }); // "WaSm Call"
336+
(audioContext ? EmAudio[audioContext].audioWorklet.bootstrapMessage.port : messagePort).postMessage({'_wsc': funcPtr, args: [arg0, arg1] }); // "WaSm Call"
337337
},
338338

339339
emscripten_audio_worklet_post_function_vii__deps: ['$emscripten_audio_worklet_post_function_2'],
@@ -347,7 +347,7 @@ let LibraryWebAudio = {
347347
},
348348

349349
$emscripten_audio_worklet_post_function_3: (audioContext, funcPtr, arg0, arg1, arg2) => {
350-
(audioContext ? EmAudio[audioContext].audioWorklet.bootstrapMessage.port : messagePort).postMessage({'_wsc': funcPtr, 'x': [arg0, arg1, arg2] }); // "WaSm Call"
350+
(audioContext ? EmAudio[audioContext].audioWorklet.bootstrapMessage.port : messagePort).postMessage({'_wsc': funcPtr, args: [arg0, arg1, arg2] }); // "WaSm Call"
351351
},
352352
emscripten_audio_worklet_post_function_viii__deps: ['$emscripten_audio_worklet_post_function_3'],
353353
emscripten_audio_worklet_post_function_viii: (audioContext, funcPtr, arg0, arg1, arg2) => {
@@ -367,7 +367,7 @@ let LibraryWebAudio = {
367367
assert(UTF8ToString(sigPtr)[0] != 'v', 'Do NOT specify the return argument in the signature string for a call to emscripten_audio_worklet_post_function_sig(), just pass the function arguments.');
368368
assert(varargs);
369369
#endif
370-
(audioContext ? EmAudio[audioContext].audioWorklet.bootstrapMessage.port : messagePort).postMessage({'_wsc': funcPtr, 'x': readEmAsmArgs(sigPtr, varargs) });
370+
(audioContext ? EmAudio[audioContext].audioWorklet.bootstrapMessage.port : messagePort).postMessage({'_wsc': funcPtr, args: readEmAsmArgs(sigPtr, varargs) });
371371
}
372372
};
373373

test/code_size/audio_worklet_wasm.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ if (q) {
2222
constructor(d) {
2323
super();
2424
d = d.processorOptions;
25-
this.v = H.get(d.cb);
26-
this.A = d.ud;
27-
this.s = d.sc;
25+
this.u = H.get(d.u);
26+
this.v = d.v;
27+
this.s = d.s;
2828
}
2929
static get parameterDescriptors() {
3030
return c;
@@ -53,7 +53,7 @@ if (q) {
5353
n += 8 * E;
5454
for (l = 0; B = f[l++]; ) v[g] = B.length, v[g + 1] = n, g += 2, x.set(B, n >> 2),
5555
n += 4 * B.length;
56-
if (f = this.v(m, A, w, G, E, u, this.A)) for (l of k) for (z of l) for (g = 0; g < this.s; ++g) z[g] = x[d++];
56+
if (f = this.u(m, A, w, G, E, u, this.v)) for (l of k) for (z of l) for (g = 0; g < this.s; ++g) z[g] = x[d++];
5757
K(V);
5858
return !!f;
5959
}
@@ -68,10 +68,10 @@ if (q) {
6868
L = this.port;
6969
L.onmessage = async e => {
7070
e = e.data;
71-
e._wpn ? (registerProcessor(e._wpn, a(e.ap)), L.postMessage({
72-
_wsc: e.cb,
73-
x: [ e.ch, 1, e.ud ]
74-
})) : e._wsc && H.get(e._wsc)(...e.x);
71+
e._wpn ? (registerProcessor(e._wpn, a(e.C)), L.postMessage({
72+
_wsc: e.u,
73+
A: [ e.D, 1, e.v ]
74+
})) : e._wsc && H.get(e._wsc)(...e.A);
7575
};
7676
}
7777
process() {}
@@ -143,9 +143,9 @@ var M = [], N = a => {
143143
numberOfOutputs: f,
144144
outputChannelCount: m,
145145
processorOptions: {
146-
cb: e,
147-
ud: d,
148-
sc: 128
146+
u: e,
147+
v: d,
148+
s: 128
149149
}
150150
};
151151
} else e = void 0;
@@ -162,27 +162,27 @@ var M = [], N = a => {
162162
maxValue: x[f++],
163163
automationRate: [ "a", "k" ][v[f++]] + "-rate"
164164
});
165-
k = R[a].audioWorklet.u.port;
165+
k = R[a].audioWorklet.B.port;
166166
f = k.postMessage;
167167
b = (b = v[b]) ? W(b) : "";
168168
f.call(k, {
169169
_wpn: b,
170-
ap: d,
171-
ch: a,
172-
cb: c,
173-
ud: e
170+
C: d,
171+
D: a,
172+
u: c,
173+
v: e
174174
});
175175
}, da = () => !1, ea = 1, fa = a => {
176176
a = a.data;
177177
let b = a._wsc;
178-
b && H.get(b)(...a.x);
178+
b && H.get(b)(...a.A);
179179
}, ha = a => J(a), ia = (a, b, c, e, d) => {
180180
let k = R[a], f = k.audioWorklet, m = () => {
181181
H.get(e)(a, 0, d);
182182
};
183183
if (!f) return m();
184184
f.addModule(h.js).then((() => {
185-
f.u = new AudioWorkletNode(k, "em-bootstrap", {
185+
f.B = new AudioWorkletNode(k, "em-bootstrap", {
186186
processorOptions: {
187187
$ww: ea++,
188188
wasm: h.wasm,
@@ -191,7 +191,7 @@ var M = [], N = a => {
191191
sz: c
192192
}
193193
});
194-
f.u.port.onmessage = fa;
194+
f.B.port.onmessage = fa;
195195
H.get(e)(a, 1, d);
196196
})).catch(m);
197197
};
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 519,
33
"a.html.gz": 364,
4-
"a.js": 3886,
5-
"a.js.gz": 2070,
4+
"a.js": 3872,
5+
"a.js.gz": 2067,
66
"a.wasm": 1287,
77
"a.wasm.gz": 859,
8-
"total": 5692,
9-
"total_gz": 3293
8+
"total": 5678,
9+
"total_gz": 3290
1010
}

0 commit comments

Comments
 (0)