@@ -46,15 +46,19 @@ function createWasmAudioWorkletProcessor(audioParams) {
46
46
// stops STACK_OVERFLOW_CHECK failing (since the stack will be full, and
47
47
// 16 being the minimum allocation size due to alignments) and leaves room
48
48
// for a single AudioSampleFrame as a minumum.
49
+ // Note: here and in the rest of the code the natural '>>> 2' unsigned
50
+ // shifts for bytes to HEAPU32 offsets have been replaced with '/ 4',
51
+ // otherwise the values are truncated to 32-bit addresses, which fails
52
+ // when compiling with MEMORY64.
49
53
this . maxBuffers = Math . min ( ( ( Module [ 'sz' ] - /*minimum alloc*/ 16 ) / ( this . samplesPerChannel * 4 ) ) | 0 , /*sensible limit*/ 10 ) ;
50
54
#if ASSERTIONS
51
55
console . assert ( this . maxBuffers > 0 , `AudioWorklet needs more stack allocating (at least ${ this . samplesPerChannel * 4 } )` ) ;
52
56
#endif
53
57
// These are still alloc'd to take advantage of the overflow checks, etc.
54
58
var oldStackPtr = stackSave ( ) ;
55
- var viewDataIdx = stackAlloc ( this . maxBuffers * this . samplesPerChannel * 4 ) >> 2 ;
59
+ var viewDataIdx = stackAlloc ( this . maxBuffers * this . samplesPerChannel * 4 ) / 4 ;
56
60
#if WEBAUDIO_DEBUG
57
- console . log ( `AudioWorklet creating ${ this . maxBuffers } buffer one-time views (for a stack size of ${ Module [ 'sz' ] } )` ) ;
61
+ console . log ( `AudioWorklet creating ${ this . maxBuffers } buffer one-time views (for a stack size of ${ Module [ 'sz' ] } at address 0x ${ ( viewDataIdx * 4 ) . toString ( 16 ) } )` ) ;
58
62
#endif
59
63
this . outputViews = [ ] ;
60
64
for ( var i = this . maxBuffers ; i > 0 ; i -- ) {
@@ -112,45 +116,55 @@ function createWasmAudioWorkletProcessor(audioParams) {
112
116
113
117
// Copy input audio descriptor structs and data to Wasm
114
118
inputsPtr = dataPtr ;
115
- k = inputsPtr >>> 2 ;
119
+ k = inputsPtr / 4 ;
116
120
dataPtr += numInputs * { { { C_STRUCTS . AudioSampleFrame . __size__ } } } ;
117
121
for ( i of inputList ) {
118
122
// Write the AudioSampleFrame struct instance
119
123
HEAPU32 [ k + { { { C_STRUCTS . AudioSampleFrame . numberOfChannels / 4 } } } ] = i . length ;
120
124
HEAPU32 [ k + { { { C_STRUCTS . AudioSampleFrame . samplesPerChannel / 4 } } } ] = this . samplesPerChannel ;
121
125
HEAPU32 [ k + { { { C_STRUCTS . AudioSampleFrame . data / 4 } } } ] = dataPtr ;
126
+ #if MEMORY64
127
+ // See the note in the constructor for dealing with 64-bit addresses
128
+ HEAPU32 [ k + { { { C_STRUCTS . AudioSampleFrame . data / 4 + 1 } } } ] = dataPtr / 0x100000000 ;
129
+ #endif
122
130
k += { { { C_STRUCTS . AudioSampleFrame . __size__ / 4 } } } ;
123
131
// Marshal the input audio sample data for each audio channel of this input
124
132
for ( j of i ) {
125
- HEAPF32 . set ( j , dataPtr >>> 2 ) ;
133
+ HEAPF32 . set ( j , dataPtr / 4 ) ;
126
134
dataPtr += bytesPerChannel ;
127
135
}
128
136
}
129
137
130
138
// Copy parameters descriptor structs and data to Wasm
131
139
paramsPtr = dataPtr ;
132
- k = paramsPtr >>> 2 ;
140
+ k = paramsPtr / 4 ;
133
141
dataPtr += numParams * { { { C_STRUCTS . AudioParamFrame . __size__ } } } ;
134
142
for ( i = 0 ; paramArray = parameters [ i ++ ] ; ) {
135
143
// Write the AudioParamFrame struct instance
136
144
HEAPU32 [ k + { { { C_STRUCTS . AudioParamFrame . length / 4 } } } ] = paramArray . length ;
137
145
HEAPU32 [ k + { { { C_STRUCTS . AudioParamFrame . data / 4 } } } ] = dataPtr ;
146
+ #if MEMORY64
147
+ HEAPU32 [ k + { { { C_STRUCTS . AudioSampleFrame . data / 4 + 1 } } } ] = dataPtr / 0x100000000 ;
148
+ #endif
138
149
k += { { { C_STRUCTS . AudioParamFrame . __size__ / 4 } } } ;
139
150
// Marshal the audio parameters array
140
- HEAPF32 . set ( paramArray , dataPtr >> 2 ) ;
141
- dataPtr += paramArray . length * 4 ;
151
+ HEAPF32 . set ( paramArray , dataPtr / 4 ) ;
152
+ dataPtr += paramArray . length * 4 ;
142
153
}
143
154
144
155
// Copy output audio descriptor structs to Wasm (note that dataPtr after
145
156
// the struct offsets should now be 16-byte aligned).
146
157
outputsPtr = dataPtr ;
147
- k = outputsPtr >>> 2 ;
158
+ k = outputsPtr / 4 ;
148
159
dataPtr += numOutputs * { { { C_STRUCTS . AudioSampleFrame . __size__ } } } ;
149
160
for ( i of outputList ) {
150
161
// Write the AudioSampleFrame struct instance
151
162
HEAPU32 [ k + { { { C_STRUCTS . AudioSampleFrame . numberOfChannels / 4 } } } ] = i . length ;
152
163
HEAPU32 [ k + { { { C_STRUCTS . AudioSampleFrame . samplesPerChannel / 4 } } } ] = this . samplesPerChannel ;
153
164
HEAPU32 [ k + { { { C_STRUCTS . AudioSampleFrame . data / 4 } } } ] = dataPtr ;
165
+ #if MEMORY64
166
+ HEAPU32 [ k + { { { C_STRUCTS . AudioSampleFrame . data / 4 + 1 } } } ] = dataPtr / 0x100000000 ;
167
+ #endif
154
168
k += { { { C_STRUCTS . AudioSampleFrame . __size__ / 4 } } } ;
155
169
// Advance the output pointer to the next output (matching the pre-allocated views)
156
170
dataPtr += bytesPerChannel * i . length ;
@@ -179,7 +193,7 @@ function createWasmAudioWorkletProcessor(audioParams) {
179
193
#endif
180
194
181
195
// Call out to Wasm callback to perform audio processing
182
- if ( didProduceAudio = this . callbackFunction ( numInputs , BigInt ( inputsPtr ) , numOutputs , BigInt ( outputsPtr ) , numParams , BigInt ( paramsPtr ) , this . userData ) ) {
196
+ if ( didProduceAudio = this . callbackFunction ( numInputs , { { { toIndexType ( ' inputsPtr' ) } } } , numOutputs , { { { toIndexType ( ' outputsPtr' ) } } } , numParams , { { { toIndexType ( ' paramsPtr' ) } } } , this . userData ) ) {
183
197
// Read back the produced audio data to all outputs and their channels.
184
198
// The preallocated 'outputViews' already have the correct offsets and
185
199
// sizes into the stack (recall from the ctor that they run backwards).
@@ -262,12 +276,7 @@ class BootstrapMessages extends AudioWorkletProcessor {
262
276
// 'ud' the passed user data
263
277
p . postMessage ( { '_wsc' : d [ 'cb' ] , 'x' : [ d [ 'ch' ] , 1 /*EM_TRUE*/ , d [ 'ud' ] ] } ) ;
264
278
} else if ( d [ '_wsc' ] ) {
265
- #if MEMORY64
266
- var ptr = BigInt ( d [ '_wsc' ] ) ;
267
- #else
268
- var ptr = d [ '_wsc' ] ;
269
- #endif
270
- Module [ 'wasmTable' ] . get ( ptr ) ( ...d [ 'x' ] ) ;
279
+ Module [ 'wasmTable' ] . get ( { { { toIndexType ( 'd[\'_wsc\']' ) } } } ) ( ...d [ 'x' ] ) ;
271
280
} ;
272
281
}
273
282
}
0 commit comments