Skip to content

Commit fa97e7d

Browse files
committed
Work in progress: WA creation now works (roughly) with addresses over 2GB
1 parent 68cdb19 commit fa97e7d

File tree

5 files changed

+51
-13
lines changed

5 files changed

+51
-13
lines changed

src/lib/libwebaudio.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,13 @@ 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 >>= 2;
248+
//options = {{{ getHeapOffset('options', 'u32') }}};
249249
let audioParams = [],
250-
numAudioParams = HEAPU32[options+1],
251-
audioParamDescriptors = HEAPU32[options+2] >> 2,
250+
numAudioParams = {{{ makeGetValue('options', C_STRUCTS.WebAudioWorkletProcessorCreateOptions.numAudioParams, 'i32') }}},
251+
audioParamDescriptors = {{{ makeGetValue('options', C_STRUCTS.WebAudioWorkletProcessorCreateOptions.audioParamDescriptors, '*') }}},
252252
i = 0;
253253

254+
// TODO: wrong and currently not running (since no param descriptors are tested)
254255
while (numAudioParams--) {
255256
audioParams.push({
256257
name: i++,
@@ -261,8 +262,9 @@ let LibraryWebAudio = {
261262
});
262263
}
263264

265+
let name = UTF8ToString({{{ makeGetValue('options', C_STRUCTS.WebAudioWorkletProcessorCreateOptions.name, '*') }}});
264266
#if WEBAUDIO_DEBUG
265-
console.log(`emscripten_create_wasm_audio_worklet_processor_async() creating a new AudioWorklet processor with name ${UTF8ToString(HEAPU32[options])}`);
267+
console.log(`emscripten_create_wasm_audio_worklet_processor_async() creating a new AudioWorklet processor with name ${name}`);
266268
#endif
267269

268270
EmAudio[contextHandle].audioWorklet.bootstrapMessage.port.postMessage({
@@ -272,7 +274,7 @@ let LibraryWebAudio = {
272274
// for space saving reasons, abbreviated from their variable names).
273275
// Note: we can only pass clonable object, so need to pass the function
274276
// pointer and not the wasm function object.
275-
'_wpn': UTF8ToString(HEAPU32[options]),
277+
'_wpn': name,
276278
'ap': audioParams,
277279
'ch': contextHandle,
278280
'cb': {{{ toIndexType('callback') }}},
@@ -287,18 +289,20 @@ let LibraryWebAudio = {
287289
assert(EmAudio[contextHandle], `Called emscripten_create_wasm_audio_worklet_node() with a nonexisting/already freed Web Audio Context handle ${contextHandle}!`);
288290
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]}`);
289291
#endif
290-
options >>= 2;
291292

292293
function readChannelCountArray(heapIndex, numOutputs) {
294+
if (!heapIndex) return void 0;
295+
heapIndex = {{{ getHeapOffset('heapIndex', 'i32') }}};
293296
let channelCounts = [];
294297
while (numOutputs--) channelCounts.push(HEAPU32[heapIndex++]);
295298
return channelCounts;
296299
}
297300

301+
let optionsOutputs = options ? {{{ makeGetValue('options', C_STRUCTS.EmscriptenAudioWorkletNodeCreateOptions.numberOfOutputs, 'i32') }}} : 0;
298302
let opts = options ? {
299-
numberOfInputs: HEAP32[options],
300-
numberOfOutputs: HEAP32[options+1],
301-
outputChannelCount: HEAPU32[options+2] ? readChannelCountArray(HEAPU32[options+2]>>2, HEAP32[options+1]) : void 0,
303+
numberOfInputs: {{{ makeGetValue('options', C_STRUCTS.EmscriptenAudioWorkletNodeCreateOptions.numberOfInputs, 'i32') }}},
304+
numberOfOutputs: optionsOutputs,
305+
outputChannelCount: readChannelCountArray({{{ makeGetValue('options', C_STRUCTS.EmscriptenAudioWorkletNodeCreateOptions.outputChannelCounts, 'i32*') }}}, optionsOutputs),
302306
processorOptions: {
303307
'cb': {{{ toIndexType('callback') }}},
304308
'ud': {{{ toIndexType('userData') }}},

src/struct_info.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,11 @@
12641264
{
12651265
"file": "emscripten/webaudio.h",
12661266
"structs": {
1267+
"WebAudioWorkletProcessorCreateOptions": [
1268+
"name",
1269+
"numAudioParams",
1270+
"audioParamDescriptors"
1271+
],
12671272
"AudioSampleFrame": [
12681273
"numberOfChannels",
12691274
"samplesPerChannel",
@@ -1272,6 +1277,11 @@
12721277
"AudioParamFrame": [
12731278
"length",
12741279
"data"
1280+
],
1281+
"EmscriptenAudioWorkletNodeCreateOptions": [
1282+
"numberOfInputs",
1283+
"numberOfOutputs",
1284+
"outputChannelCounts"
12751285
]
12761286
}
12771287
},

src/struct_info_generated.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,12 @@
529529
"numberOfChannels": 0,
530530
"samplesPerChannel": 4
531531
},
532+
"EmscriptenAudioWorkletNodeCreateOptions": {
533+
"__size__": 12,
534+
"numberOfInputs": 0,
535+
"numberOfOutputs": 4,
536+
"outputChannelCounts": 8
537+
},
532538
"EmscriptenBatteryEvent": {
533539
"__size__": 32,
534540
"charging": 24,
@@ -1474,6 +1480,12 @@
14741480
"module": 4,
14751481
"nextInChain": 0
14761482
},
1483+
"WebAudioWorkletProcessorCreateOptions": {
1484+
"__size__": 12,
1485+
"audioParamDescriptors": 8,
1486+
"name": 0,
1487+
"numAudioParams": 4
1488+
},
14771489
"__cxa_exception": {
14781490
"__size__": 24,
14791491
"adjustedPtr": 16,

src/struct_info_generated_wasm64.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,12 @@
529529
"numberOfChannels": 0,
530530
"samplesPerChannel": 4
531531
},
532+
"EmscriptenAudioWorkletNodeCreateOptions": {
533+
"__size__": 16,
534+
"numberOfInputs": 0,
535+
"numberOfOutputs": 4,
536+
"outputChannelCounts": 8
537+
},
532538
"EmscriptenBatteryEvent": {
533539
"__size__": 32,
534540
"charging": 24,
@@ -1474,6 +1480,12 @@
14741480
"module": 8,
14751481
"nextInChain": 0
14761482
},
1483+
"WebAudioWorkletProcessorCreateOptions": {
1484+
"__size__": 24,
1485+
"audioParamDescriptors": 16,
1486+
"name": 0,
1487+
"numAudioParams": 8
1488+
},
14771489
"__cxa_exception": {
14781490
"__size__": 48,
14791491
"adjustedPtr": 32,

test/test_interactive.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,19 +334,19 @@ def test_audio_worklet_2x_hard_pan_io(self):
334334
shutil.copy(test_file('webaudio/audio_files/emscripten-bass-mono.mp3'), 'audio_files/')
335335
self.btest_exit('webaudio/audioworklet_2x_in_hard_pan.c', args=['-sAUDIO_WORKLET', '-sWASM_WORKERS'])
336336

337-
# Same as 'test_audio_worklet_2x_stereo_io' but as wasm64 with the worklet stack starting 2GB in (tests for unsigned shifts in the memory offsets)
337+
# Same as 'test_audio_worklet_2x_stereo_io' but with the worklet stack starting 2GB in (tests for unsigned shifts in the memory offsets)
338338
def test_audio_worklet_stereo_io_2gb(self):
339339
os.mkdir('audio_files')
340340
shutil.copy(test_file('webaudio/audio_files/emscripten-beat.mp3'), 'audio_files/')
341341
shutil.copy(test_file('webaudio/audio_files/emscripten-bass.mp3'), 'audio_files/')
342-
self.btest_exit('webaudio/audioworklet_in_out_stereo.c', args=['-sAUDIO_WORKLET', '-sWASM_WORKERS', '-sMEMORY64', '-sINITIAL_MEMORY=4200mb', '-DTEST_OFFSET_GB=2'])
342+
self.btest_exit('webaudio/audioworklet_in_out_stereo.c', args=['-sAUDIO_WORKLET', '-sWASM_WORKERS', '-sINITIAL_MEMORY=2200mb', '-sGLOBAL_BASE=2gb'])
343343

344-
# Same as 'test_audio_worklet_stereo_io_2gb' but with a 4GB offset
344+
# Same as 'test_audio_worklet_stereo_io_2gb' but built for wasm64 with the worklet stack starting at 4GB
345345
def test_audio_worklet_stereo_io_4gb(self):
346346
os.mkdir('audio_files')
347347
shutil.copy(test_file('webaudio/audio_files/emscripten-beat.mp3'), 'audio_files/')
348348
shutil.copy(test_file('webaudio/audio_files/emscripten-bass.mp3'), 'audio_files/')
349-
self.btest_exit('webaudio/audioworklet_in_out_stereo.c', args=['-sAUDIO_WORKLET', '-sWASM_WORKERS', '-sMEMORY64', '-sINITIAL_MEMORY=4200mb', '-DTEST_OFFSET_GB=4'])
349+
self.btest_exit('webaudio/audioworklet_in_out_stereo.c', args=['-sAUDIO_WORKLET', '-sWASM_WORKERS', '-sMEMORY64', '-sINITIAL_MEMORY=4200mb', '-sGLOBAL_BASE=4gb'])
350350

351351

352352
class interactive64(interactive):

0 commit comments

Comments
 (0)