Skip to content

Commit 92dc53e

Browse files
committed
Moved toIndex() helpers to the worklet
1 parent b0268c7 commit 92dc53e

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/audio_worklet.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ function createWasmAudioWorkletProcessor(audioParams) {
2929

3030
// Capture the Wasm function callback to invoke.
3131
let opts = args.processorOptions;
32-
this.callbackFunction = Module['wasmTable'].get(opts['cb']);
33-
this.userData = opts['ud'];
32+
this.callbackFunction = Module['wasmTable'].get({{{ toIndexType("opts['cb']") }}});
33+
this.userData = {{{ toIndexType("opts['ud']") }}};
3434

3535
// Then the samples per channel to process, fixed for the lifetime of the
3636
// context that created this processor. Even though this 'render quantum
@@ -273,9 +273,9 @@ class BootstrapMessages extends AudioWorkletProcessor {
273273
// 'cb' the callback function
274274
// 'ch' the context handle
275275
// 'ud' the passed user data
276-
p.postMessage({'_wsc': d['cb'], 'x': [d['ch'], 1/*EM_TRUE*/, d['ud']] });
276+
p.postMessage({'_wsc': {{{ toIndexType("d['cb']") }}}, 'x': [d['ch'], 1/*EM_TRUE*/, {{{ toIndexType("d['ud']") }}}] });
277277
} else if (d['_wsc']) {
278-
Module['wasmTable'].get({{{ toIndexType('d[\'_wsc\']') }}})(...d['x']);
278+
Module['wasmTable'].get({{{ toIndexType("d['_wsc']") }}})(...d['x']);
279279
};
280280
}
281281
}

src/lib/libwebaudio.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ let LibraryWebAudio = {
251251
audioParamDescriptors = {{{ makeGetValue('options', C_STRUCTS.WebAudioWorkletProcessorCreateOptions.audioParamDescriptors, '*') }}},
252252
i = 0;
253253

254-
// TODO: add tests and wire this up
255254
while (numAudioParams--) {
256255
audioParams.push({
257256
name: i++,
@@ -277,8 +276,8 @@ let LibraryWebAudio = {
277276
'_wpn': processorName,
278277
'ap': audioParams,
279278
'ch': contextHandle,
280-
'cb': {{{ toIndexType('callback') }}},
281-
'ud': {{{ toIndexType('userData') }}}
279+
'cb': callback,
280+
'ud': userData
282281
});
283282
},
284283

@@ -290,7 +289,6 @@ let LibraryWebAudio = {
290289
assert(EmAudio[contextHandle] instanceof (window.AudioContext || window.webkitAudioContext), `Called emscripten_create_wasm_audio_worklet_node() on a context handle ${contextHandle} that is not an AudioContext, but of type ${typeof EmAudio[contextHandle]}`);
291290
#endif
292291

293-
// TODO: this next
294292
function readChannelCountArray(heapIndex, numOutputs) {
295293
if (!heapIndex) return void 0;
296294
heapIndex = {{{ getHeapOffset('heapIndex', 'i32') }}};
@@ -305,8 +303,8 @@ let LibraryWebAudio = {
305303
numberOfOutputs: optionsOutputs,
306304
outputChannelCount: readChannelCountArray({{{ makeGetValue('options', C_STRUCTS.EmscriptenAudioWorkletNodeCreateOptions.outputChannelCounts, 'i32*') }}}, optionsOutputs),
307305
processorOptions: {
308-
'cb': {{{ toIndexType('callback') }}},
309-
'ud': {{{ toIndexType('userData') }}},
306+
'cb': callback,
307+
'ud': userData,
310308
'sc': emscriptenGetContextQuantumSize(contextHandle)
311309
}
312310
} : void 0;

0 commit comments

Comments
 (0)