fix(noise-suppression) exit out early if no input data to Worklet

Disconnecting the input node to the worklet causes the worklet to crash. Adding a guard clause for empty input prevents this.
This commit is contained in:
Armel Chesnais 2022-10-25 15:55:47 -04:00 committed by GitHub
parent a915238b49
commit 51ac3ef64a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 0 deletions

View File

@ -106,6 +106,12 @@ class NoiseSuppressorWorklet extends AudioWorkletProcessor {
const inData = inputs[0][0]; const inData = inputs[0][0];
const outData = outputs[0][0]; const outData = outputs[0][0];
// Exit out early if there is no input data (input node not connected/disconnected)
// as rest of worklet will crash otherwise
if (!inData) {
return true;
}
// Append new raw PCM sample. // Append new raw PCM sample.
this._circularBuffer.set(inData, this._inputBufferLength); this._circularBuffer.set(inData, this._inputBufferLength);
this._inputBufferLength += inData.length; this._inputBufferLength += inData.length;