Skip to content

Commit

Permalink
Added more assertions, minor docs
Browse files Browse the repository at this point in the history
The assertions should now cover all cases of changes in address and size of the output views.
  • Loading branch information
cwoffenden committed Oct 31, 2024
1 parent 3d55267 commit 9e5c73b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/audio_worklet.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function createWasmAudioWorkletProcessor(audioParams) {
dataPtr += paramArray.length*4;
}

// Copy output audio descriptor structs to Wasm (not that dataPtr after
// Copy output audio descriptor structs to Wasm (note that dataPtr after
// the struct offsets should now be 16-byte aligned).
outputsPtr = dataPtr;
dataPtr += numOutputs * {{{ C_STRUCTS.AudioSampleFrame.__size__ }}};
Expand All @@ -153,13 +153,22 @@ function createWasmAudioWorkletProcessor(audioParams) {
#if ASSERTIONS
// If all the maths worked out, we arrived at the original stack address
console.assert(dataPtr == oldStackPtr, `AudioWorklet stack missmatch (audio data finishes at ${dataPtr} instead of ${oldStackPtr})`);
// Sanity check the output view addresses

// Sanity checks. If these trip the most likely cause, beyond unforeseen
// stack shenanigans, is that the 'render quantum size' changed.
if (numOutputs) {
// First that the output view addresses match the stack positions.
k = dataPtr - bytesPerChannel;
for (i = 0; i < outputViewsNeeded; i++) {
console.assert(k == this.outputViews[i].byteOffset, 'AudioWorklet internal error in addresses of the output array views');
k -= bytesPerChannel;
}
// And that the views' size match the passed in output buffers
for (i of outputList) {
for (j of i) {
console.assert(j.byteLength == bytesPerChannel, `AudioWorklet unexpected output buffer size (expected ${bytesPerChannel} got ${j.byteLength})`);
}
}
}
#endif

Expand Down

0 comments on commit 9e5c73b

Please sign in to comment.