@@ -38,8 +38,8 @@ function createWasmAudioWorkletProcessor(audioParams) {
38
38
// shouldn't be required (to be verified).
39
39
this . samplesPerChannel = opts [ 'sc' ] ;
40
40
// Typed views of the output buffers on the worklet's stack, which after
41
- // creation should not change (since the stack is passed externally once) .
42
- this . outputViews = null ;
41
+ // creation should only change if the audio chain changes .
42
+ this . outputViews = [ ] ;
43
43
}
44
44
45
45
static get parameterDescriptors ( ) {
@@ -57,7 +57,7 @@ function createWasmAudioWorkletProcessor(audioParams) {
57
57
bytesPerChannel = this . samplesPerChannel * 4 ,
58
58
stackMemoryNeeded = ( numInputs + numOutputs ) * { { { C_STRUCTS . AudioSampleFrame . __size__ } } } ,
59
59
oldStackPtr = stackSave ( ) ,
60
- inputsPtr , outputsPtr , outputDataPtr , paramsPtr ,
60
+ inputsPtr , outputsPtr , outputDataPtr , paramsPtr , requiredViews = 0 ,
61
61
didProduceAudio , paramArray ;
62
62
63
63
// Calculate how much stack space is needed.
@@ -96,18 +96,22 @@ function createWasmAudioWorkletProcessor(audioParams) {
96
96
k += { { { C_STRUCTS . AudioSampleFrame . __size__ / 4 } } } ;
97
97
// Reserve space for the output data
98
98
dataPtr += bytesPerChannel * i . length ;
99
+ // How many output views are needed in total?
100
+ requiredViews += i . length ;
99
101
}
100
- if ( ! this . outputViews ) {
102
+
103
+ // Verify we have enough views (it doesn't matter if we have too many, any
104
+ // excess won't be accessed) then also verify the views' start address
105
+ // hasn't changed.
106
+ // TODO: allocate space for outputDataPtr before any inputs?
107
+ k = outputDataPtr ;
108
+ if ( this . outputViews . length < requiredViews || ( this . outputViews . length && this . outputViews [ 0 ] . byteOffset != k << 2 ) ) {
101
109
this . outputViews = [ ] ;
102
- k = outputDataPtr ;
103
110
for ( /*which output*/ i of outputList ) {
104
111
for ( /*which channel*/ j of i ) {
105
- this . outputViews . push ( {
106
- // dataPtr is the sanity check (to be implemented)
107
- // dataSub is the one-time subarray into the heap
108
- dataPtr : k ,
109
- dataSub : HEAPF32 . subarray ( k , k += this . samplesPerChannel )
110
- } ) ;
112
+ this . outputViews . push (
113
+ HEAPF32 . subarray ( k , k += this . samplesPerChannel )
114
+ ) ;
111
115
}
112
116
}
113
117
}
@@ -134,7 +138,7 @@ function createWasmAudioWorkletProcessor(audioParams) {
134
138
k = 0 ;
135
139
for ( i of outputList ) {
136
140
for ( j of i ) {
137
- j . set ( this . outputViews [ k ++ ] . dataSub ) ;
141
+ j . set ( this . outputViews [ k ++ ] ) ;
138
142
}
139
143
}
140
144
}
0 commit comments