Skip to content

Commit 568a86f

Browse files
committed
More work in progress
Removed magic numbers from emscripten_create_wasm_audio_worklet_processor_async().
1 parent ccb12a0 commit 568a86f

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

src/lib/libwebaudio.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,26 +245,25 @@ let LibraryWebAudio = {
245245
assert(EmAudio[contextHandle] instanceof (window.AudioContext || window.webkitAudioContext), `Called emscripten_create_wasm_audio_worklet_processor_async() on a context handle ${contextHandle} that is not an AudioContext, but of type ${typeof EmAudio[contextHandle]}`);
246246
#endif
247247

248-
//options = {{{ getHeapOffset('options', 'u32') }}};
249248
let audioParams = [],
249+
processorName = UTF8ToString({{{ makeGetValue('options', C_STRUCTS.WebAudioWorkletProcessorCreateOptions.name, '*') }}}),
250250
numAudioParams = {{{ makeGetValue('options', C_STRUCTS.WebAudioWorkletProcessorCreateOptions.numAudioParams, 'i32') }}},
251251
audioParamDescriptors = {{{ makeGetValue('options', C_STRUCTS.WebAudioWorkletProcessorCreateOptions.audioParamDescriptors, '*') }}},
252252
i = 0;
253253

254-
// TODO: wrong and currently not running (since no param descriptors are tested)
254+
// TODO: add tests and wire this up
255255
while (numAudioParams--) {
256256
audioParams.push({
257257
name: i++,
258-
defaultValue: HEAPF32[audioParamDescriptors++],
259-
minValue: HEAPF32[audioParamDescriptors++],
260-
maxValue: HEAPF32[audioParamDescriptors++],
261-
automationRate: ['a','k'][HEAPU32[audioParamDescriptors++]] + '-rate',
258+
defaultValue: {{{ makeGetValue('audioParamDescriptors++', C_STRUCTS.WebAudioParamDescriptor.defaultValue, 'float') }}},
259+
minValue: {{{ makeGetValue('audioParamDescriptors++', C_STRUCTS.WebAudioParamDescriptor.minValue, 'float') }}},
260+
maxValue: {{{ makeGetValue('audioParamDescriptors++', C_STRUCTS.WebAudioParamDescriptor.maxValue, 'float') }}},
261+
automationRate: ({{{ makeGetValue('audioParamDescriptors++', C_STRUCTS.WebAudioParamDescriptor.maxValue, 'i32') }}} ? 'a' : 'k') + '-rate'
262262
});
263263
}
264264

265-
let name = UTF8ToString({{{ makeGetValue('options', C_STRUCTS.WebAudioWorkletProcessorCreateOptions.name, '*') }}});
266265
#if WEBAUDIO_DEBUG
267-
console.log(`emscripten_create_wasm_audio_worklet_processor_async() creating a new AudioWorklet processor with name ${name}`);
266+
console.log(`emscripten_create_wasm_audio_worklet_processor_async() creating a new AudioWorklet processor with name ${processorName}`);
268267
#endif
269268

270269
EmAudio[contextHandle].audioWorklet.bootstrapMessage.port.postMessage({
@@ -274,7 +273,7 @@ let LibraryWebAudio = {
274273
// for space saving reasons, abbreviated from their variable names).
275274
// Note: we can only pass clonable object, so need to pass the function
276275
// pointer and not the wasm function object.
277-
'_wpn': name,
276+
'_wpn': processorName,
278277
'ap': audioParams,
279278
'ch': contextHandle,
280279
'cb': {{{ toIndexType('callback') }}},
@@ -290,6 +289,7 @@ 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

292+
// TODO: this next
293293
function readChannelCountArray(heapIndex, numOutputs) {
294294
if (!heapIndex) return void 0;
295295
heapIndex = {{{ getHeapOffset('heapIndex', 'i32') }}};

src/struct_info.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,12 @@
12641264
{
12651265
"file": "emscripten/webaudio.h",
12661266
"structs": {
1267+
"WebAudioParamDescriptor": [
1268+
"defaultValue",
1269+
"minValue",
1270+
"maxValue",
1271+
"automationRate"
1272+
],
12671273
"WebAudioWorkletProcessorCreateOptions": [
12681274
"name",
12691275
"numAudioParams",

src/struct_info_generated.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,13 @@
14801480
"module": 4,
14811481
"nextInChain": 0
14821482
},
1483+
"WebAudioParamDescriptor": {
1484+
"__size__": 16,
1485+
"automationRate": 12,
1486+
"defaultValue": 0,
1487+
"maxValue": 8,
1488+
"minValue": 4
1489+
},
14831490
"WebAudioWorkletProcessorCreateOptions": {
14841491
"__size__": 12,
14851492
"audioParamDescriptors": 8,

src/struct_info_generated_wasm64.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,13 @@
14801480
"module": 8,
14811481
"nextInChain": 0
14821482
},
1483+
"WebAudioParamDescriptor": {
1484+
"__size__": 16,
1485+
"automationRate": 12,
1486+
"defaultValue": 0,
1487+
"maxValue": 8,
1488+
"minValue": 4
1489+
},
14831490
"WebAudioWorkletProcessorCreateOptions": {
14841491
"__size__": 24,
14851492
"audioParamDescriptors": 16,

0 commit comments

Comments
 (0)