-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[AUDIO_WORKLET] Add support for MEMORY64 with 2GB and 4GB heap #24732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8153141
cb5f217
3d3d0e2
0804e5f
8872c6a
986ee87
bc161b5
5fe41a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,7 +78,7 @@ let LibraryWebAudio = { | |
#if WEBAUDIO_DEBUG | ||
console.log(`emscripten_resume_audio_context_async() callback: New audio state="${EmAudio[contextHandle].state}", ID=${state}`); | ||
#endif | ||
{{{ makeDynCall('viii', 'callback') }}}(contextHandle, state, userData); | ||
{{{ makeDynCall('viip', 'callback') }}}(contextHandle, state, userData); | ||
} | ||
#if WEBAUDIO_DEBUG | ||
console.log(`emscripten_resume_audio_context_async() resuming...`); | ||
|
@@ -202,7 +202,7 @@ let LibraryWebAudio = { | |
} | ||
}); | ||
audioWorklet.bootstrapMessage.port.onmessage = _EmAudioDispatchProcessorCallback; | ||
{{{ makeDynCall('viii', 'callback') }}}(contextHandle, 1/*EM_TRUE*/, userData); | ||
{{{ makeDynCall('viip', 'callback') }}}(contextHandle, 1/*EM_TRUE*/, userData); | ||
}).catch(audioWorkletCreationFailed); | ||
}, | ||
|
||
|
@@ -222,32 +222,33 @@ let LibraryWebAudio = { | |
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]}`); | ||
#endif | ||
|
||
options >>= 2; | ||
let audioParams = [], | ||
numAudioParams = HEAPU32[options+1], | ||
audioParamDescriptors = HEAPU32[options+2] >> 2, | ||
var audioParams = [], | ||
processorName = UTF8ToString({{{ makeGetValue('options', C_STRUCTS.WebAudioWorkletProcessorCreateOptions.name, '*') }}}), | ||
cwoffenden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
numAudioParams = {{{ makeGetValue('options', C_STRUCTS.WebAudioWorkletProcessorCreateOptions.numAudioParams, 'i32') }}}, | ||
audioParamDescriptors = {{{ makeGetValue('options', C_STRUCTS.WebAudioWorkletProcessorCreateOptions.audioParamDescriptors, '*') }}}, | ||
i = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we convert to one-line-per-declaration here? I think it would help make this more readable, and should not effect minified code size. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happily - I just followed the original style. |
||
|
||
while (numAudioParams--) { | ||
audioParams.push({ | ||
name: i++, | ||
defaultValue: HEAPF32[audioParamDescriptors++], | ||
minValue: HEAPF32[audioParamDescriptors++], | ||
maxValue: HEAPF32[audioParamDescriptors++], | ||
automationRate: ['a','k'][HEAPU32[audioParamDescriptors++]] + '-rate', | ||
defaultValue: {{{ makeGetValue('audioParamDescriptors', C_STRUCTS.WebAudioParamDescriptor.defaultValue, 'float') }}}, | ||
minValue: {{{ makeGetValue('audioParamDescriptors', C_STRUCTS.WebAudioParamDescriptor.minValue, 'float') }}}, | ||
maxValue: {{{ makeGetValue('audioParamDescriptors', C_STRUCTS.WebAudioParamDescriptor.maxValue, 'float') }}}, | ||
automationRate: ({{{ makeGetValue('audioParamDescriptors', C_STRUCTS.WebAudioParamDescriptor.automationRate, 'i32') }}} ? 'k' : 'a') + '-rate', | ||
}); | ||
audioParamDescriptors += {{{ C_STRUCTS.WebAudioParamDescriptor.__size__ }}}; | ||
} | ||
|
||
#if WEBAUDIO_DEBUG | ||
console.log(`emscripten_create_wasm_audio_worklet_processor_async() creating a new AudioWorklet processor with name ${UTF8ToString(HEAPU32[options])}`); | ||
console.log(`emscripten_create_wasm_audio_worklet_processor_async() creating a new AudioWorklet processor with name ${processorName}`); | ||
#endif | ||
|
||
EmAudio[contextHandle].audioWorklet.bootstrapMessage.port.postMessage({ | ||
// Deliberately mangled and short names used here ('_wpn', the 'Worklet | ||
// Processor Name' used as a 'key' to verify the message type so as to | ||
// not get accidentally mixed with user submitted messages, the remainder | ||
// for space saving reasons, abbreviated from their variable names). | ||
'_wpn': UTF8ToString(HEAPU32[options]), | ||
'_wpn': processorName, | ||
audioParams, | ||
contextHandle, | ||
callback, | ||
|
@@ -262,18 +263,20 @@ let LibraryWebAudio = { | |
assert(EmAudio[contextHandle], `Called emscripten_create_wasm_audio_worklet_node() with a nonexisting/already freed Web Audio Context handle ${contextHandle}!`); | ||
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]}`); | ||
#endif | ||
options >>= 2; | ||
|
||
function readChannelCountArray(heapIndex, numOutputs) { | ||
if (!heapIndex) return void 0; | ||
cwoffenden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
heapIndex = {{{ getHeapOffset('heapIndex', 'i32') }}}; | ||
let channelCounts = []; | ||
while (numOutputs--) channelCounts.push(HEAPU32[heapIndex++]); | ||
return channelCounts; | ||
} | ||
|
||
let optionsOutputs = options ? {{{ makeGetValue('options', C_STRUCTS.EmscriptenAudioWorkletNodeCreateOptions.numberOfOutputs, 'i32') }}} : 0; | ||
cwoffenden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let opts = options ? { | ||
numberOfInputs: HEAP32[options], | ||
numberOfOutputs: HEAP32[options+1], | ||
outputChannelCount: HEAPU32[options+2] ? readChannelCountArray(HEAPU32[options+2]>>2, HEAP32[options+1]) : void 0, | ||
numberOfInputs: {{{ makeGetValue('options', C_STRUCTS.EmscriptenAudioWorkletNodeCreateOptions.numberOfInputs, 'i32') }}}, | ||
numberOfOutputs: optionsOutputs, | ||
outputChannelCount: readChannelCountArray({{{ makeGetValue('options', C_STRUCTS.EmscriptenAudioWorkletNodeCreateOptions.outputChannelCounts, 'i32*') }}}, optionsOutputs), | ||
processorOptions: { | ||
callback, | ||
userData, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This second line doesn't look quite right to me.
userData I assume is a pointer, which means it should be Number and not a bigint (it should be converted to a Number when it first arrived on the JS side).
If it needs to be converted back to a pointer (i64) when
this.callback
then you should be usingto64
at the callback call side, and not here.toIndexType
should only be used for places where you are direclty accessing the table, or the memory bounds.Can you test with
-sMEMORY64=2
as well perhaps to catch these cases where there is difference betweento64
andtoIndexType
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's to convert it back to a pointer. It's constant, so I removed the need to keep doing the conversion.
I can test with
-sMEMORY64=2
and put the conversions near the call.