Skip to content

Commit 9e5c73b

Browse files
committed
Added more assertions, minor docs
The assertions should now cover all cases of changes in address and size of the output views.
1 parent 3d55267 commit 9e5c73b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/audio_worklet.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function createWasmAudioWorkletProcessor(audioParams) {
135135
dataPtr += paramArray.length*4;
136136
}
137137

138-
// Copy output audio descriptor structs to Wasm (not that dataPtr after
138+
// Copy output audio descriptor structs to Wasm (note that dataPtr after
139139
// the struct offsets should now be 16-byte aligned).
140140
outputsPtr = dataPtr;
141141
dataPtr += numOutputs * {{{ C_STRUCTS.AudioSampleFrame.__size__ }}};
@@ -153,13 +153,22 @@ function createWasmAudioWorkletProcessor(audioParams) {
153153
#if ASSERTIONS
154154
// If all the maths worked out, we arrived at the original stack address
155155
console.assert(dataPtr == oldStackPtr, `AudioWorklet stack missmatch (audio data finishes at ${dataPtr} instead of ${oldStackPtr})`);
156-
// Sanity check the output view addresses
156+
157+
// Sanity checks. If these trip the most likely cause, beyond unforeseen
158+
// stack shenanigans, is that the 'render quantum size' changed.
157159
if (numOutputs) {
160+
// First that the output view addresses match the stack positions.
158161
k = dataPtr - bytesPerChannel;
159162
for (i = 0; i < outputViewsNeeded; i++) {
160163
console.assert(k == this.outputViews[i].byteOffset, 'AudioWorklet internal error in addresses of the output array views');
161164
k -= bytesPerChannel;
162165
}
166+
// And that the views' size match the passed in output buffers
167+
for (i of outputList) {
168+
for (j of i) {
169+
console.assert(j.byteLength == bytesPerChannel, `AudioWorklet unexpected output buffer size (expected ${bytesPerChannel} got ${j.byteLength})`);
170+
}
171+
}
163172
}
164173
#endif
165174

0 commit comments

Comments
 (0)