@@ -31,6 +31,12 @@ function createWasmAudioWorkletProcessor(audioParams) {
3131 let opts = args . processorOptions ;
3232 this . callbackFunction = Module [ 'wasmTable' ] . get ( opts [ 'cb' ] ) ;
3333 this . userData = opts [ 'ud' ] ;
34+ // Plus the number of samples to process, fixed for the lifetime of the
35+ // context that created this processor. Note for when moving to Web Audio
36+ // 1.1: the typed array passed to process() should be the same size as the
37+ // the quantum size, and this exercise of passing in the value shouldn't
38+ // be required (to be verified).
39+ this . quantumSize = opts [ 'qs' ] ;
3440 }
3541
3642 static get parameterDescriptors ( ) {
@@ -45,53 +51,59 @@ function createWasmAudioWorkletProcessor(audioParams) {
4551 let numInputs = inputList . length ,
4652 numOutputs = outputList . length ,
4753 numParams = 0 , i , j , k , dataPtr ,
48- stackMemoryNeeded = ( numInputs + numOutputs ) * 8 ,
54+ quantumBytes = this . quantumSize * 4 ,
55+ stackMemoryNeeded = ( numInputs + numOutputs ) * { { { C_STRUCTS . AudioSampleFrame . __size__ } } } ,
4956 oldStackPtr = stackSave ( ) ,
5057 inputsPtr , outputsPtr , outputDataPtr , paramsPtr ,
5158 didProduceAudio , paramArray ;
5259
5360 // Calculate how much stack space is needed.
54- for ( i of inputList ) stackMemoryNeeded += i . length * 512 ;
55- for ( i of outputList ) stackMemoryNeeded += i . length * 512 ;
56- for ( i in parameters ) stackMemoryNeeded += parameters [ i ] . byteLength + 8 , ++ numParams ;
61+ for ( i of inputList ) stackMemoryNeeded += i . length * quantumBytes ;
62+ for ( i of outputList ) stackMemoryNeeded += i . length * quantumBytes ;
63+ for ( i in parameters ) stackMemoryNeeded += parameters [ i ] . byteLength + { { { C_STRUCTS . AudioParamFrame . __size__ } } } , ++ numParams ;
5764
5865 // Allocate the necessary stack space.
5966 inputsPtr = stackAlloc ( stackMemoryNeeded ) ;
6067
6168 // Copy input audio descriptor structs and data to Wasm
6269 k = inputsPtr >> 2 ;
63- dataPtr = inputsPtr + numInputs * 8 ;
70+ dataPtr = inputsPtr + numInputs * { { { C_STRUCTS . AudioSampleFrame . __size__ } } } ;
6471 for ( i of inputList ) {
6572 // Write the AudioSampleFrame struct instance
66- HEAPU32 [ k ++ ] = i . length ;
67- HEAPU32 [ k ++ ] = dataPtr ;
73+ HEAPU32 [ k + { { { C_STRUCTS . AudioSampleFrame . numberOfChannels / 4 } } } ] = i . length ;
74+ HEAPU32 [ k + { { { C_STRUCTS . AudioSampleFrame . quantumSize / 4 } } } ] = this . quantumSize ;
75+ HEAPU32 [ k + { { { C_STRUCTS . AudioSampleFrame . data / 4 } } } ] = dataPtr ;
76+ k += { { { C_STRUCTS . AudioSampleFrame . __size__ / 4 } } } ;
6877 // Marshal the input audio sample data for each audio channel of this input
6978 for ( j of i ) {
7079 HEAPF32 . set ( j , dataPtr >> 2 ) ;
71- dataPtr += 512 ;
80+ dataPtr += quantumBytes ;
7281 }
7382 }
7483
7584 // Copy output audio descriptor structs to Wasm
7685 outputsPtr = dataPtr ;
7786 k = outputsPtr >> 2 ;
78- outputDataPtr = ( dataPtr += numOutputs * 8 ) >> 2 ;
87+ outputDataPtr = ( dataPtr += numOutputs * { { { C_STRUCTS . AudioSampleFrame . __size__ } } } ) >> 2 ;
7988 for ( i of outputList ) {
8089 // Write the AudioSampleFrame struct instance
81- HEAPU32 [ k ++ ] = i . length ;
82- HEAPU32 [ k ++ ] = dataPtr ;
90+ HEAPU32 [ k + { { { C_STRUCTS . AudioSampleFrame . numberOfChannels / 4 } } } ] = i . length ;
91+ HEAPU32 [ k + { { { C_STRUCTS . AudioSampleFrame . quantumSize / 4 } } } ] = this . quantumSize ;
92+ HEAPU32 [ k + { { { C_STRUCTS . AudioSampleFrame . data / 4 } } } ] = dataPtr ;
93+ k += { { { C_STRUCTS . AudioSampleFrame . __size__ / 4 } } } ;
8394 // Reserve space for the output data
84- dataPtr += 512 * i . length ;
95+ dataPtr += quantumBytes * i . length ;
8596 }
8697
8798 // Copy parameters descriptor structs and data to Wasm
8899 paramsPtr = dataPtr ;
89100 k = paramsPtr >> 2 ;
90- dataPtr += numParams * 8 ;
101+ dataPtr += numParams * { { { C_STRUCTS . AudioParamFrame . __size__ } } } ;
91102 for ( i = 0 ; paramArray = parameters [ i ++ ] ; ) {
92103 // Write the AudioParamFrame struct instance
93- HEAPU32 [ k ++ ] = paramArray . length ;
94- HEAPU32 [ k ++ ] = dataPtr ;
104+ HEAPU32 [ k + { { { C_STRUCTS . AudioParamFrame . length / 4 } } } ] = paramArray . length ;
105+ HEAPU32 [ k + { { { C_STRUCTS . AudioParamFrame . data / 4 } } } ] = dataPtr ;
106+ k += { { { C_STRUCTS . AudioParamFrame . __size__ / 4 } } } ;
95107 // Marshal the audio parameters array
96108 HEAPF32 . set ( paramArray , dataPtr >> 2 ) ;
97109 dataPtr += paramArray . length * 4 ;
@@ -105,7 +117,7 @@ function createWasmAudioWorkletProcessor(audioParams) {
105117 // not have one, so manually copy all bytes in)
106118 for ( i of outputList ) {
107119 for ( j of i ) {
108- for ( k = 0 ; k < 128 ; ++ k ) {
120+ for ( k = 0 ; k < this . quantumSize ; ++ k ) {
109121 j [ k ] = HEAPF32 [ outputDataPtr ++ ] ;
110122 }
111123 }
@@ -138,8 +150,7 @@ class BootstrapMessages extends AudioWorkletProcessor {
138150 // initialize the Wasm Module.
139151 globalThis . Module [ 'instantiateWasm' ] = ( info , receiveInstance ) => {
140152 var instance = new WebAssembly . Instance ( Module [ 'wasm' ] , info ) ;
141- receiveInstance ( instance , Module [ 'wasm' ] ) ;
142- return instance . exports ;
153+ return receiveInstance ( instance , Module [ 'wasm' ] ) ;
143154 } ;
144155#endif
145156#if WEBAUDIO_DEBUG
@@ -184,7 +195,12 @@ class BootstrapMessages extends AudioWorkletProcessor {
184195 // 'ud' the passed user data
185196 p . postMessage ( { '_wsc' : d [ 'cb' ] , 'x' : [ d [ 'ch' ] , 1 /*EM_TRUE*/ , d [ 'ud' ] ] } ) ;
186197 } else if ( d [ '_wsc' ] ) {
187- Module [ 'wasmTable' ] . get ( d [ '_wsc' ] ) ( ...d [ 'x' ] ) ;
198+ #if MEMORY64
199+ var ptr = BigInt ( d [ '_wsc' ] ) ;
200+ #else
201+ var ptr = d [ '_wsc' ] ;
202+ #endif
203+ Module [ 'wasmTable' ] . get ( ptr ) ( ...d [ 'x' ] ) ;
188204 } ;
189205 }
190206 }
0 commit comments