Search code examples
javascriptweb-audio-apiaudioworkletprocessor

Why might the outputs passed to AudioWorkletProcessor's process() method contain an empty array?


Background: In the WebAudio API, an implementation of an AudioWorkletProcessor must provide a process(inputs, outputs, parameters) method that gets called by the system, with the system constructing the arrays being passed in depending on what is connected to the processor's AudioWorkletNode. This documentation lives here: https://developer.mozilla.org/en-US/docs/Web/API/AudioWorkletProcessor/process

Question: Why might the outputs parameter contain nothing but an empty array? In my process() method, I have code that looks like this:

process(inputs, outputs, parameters) {
    this.inputs = inputs;
    this.parameters = parameters;
    this.bufferLength = outputs[0][0].length;
    this.checkTimer();
    return this._process(outputs);
}

I'm getting an error that the browser can't read length of undefined, and looking closer, it's because outputs[0] is an array that contains 0 elements, so outputs[0][0] is undefined. As far as I know, the audio node is hooked up to a destination node, so data ought to be flowing here. But if I can better understand why outputs[0] is empty, I can better find the true source of the problem.

Note: I know that I don't actually need to get the buffer length here because it's always 128 anyway, but the _process(outputs) method does, obviously, need to fill this array eventually.

Thank you!


Solution

  • I guess you ran into this bug/fix that recently landed in Chromium based browsers. There is also a related spec discussion.

    Please note that a render quantum may have more or less than 128 frames in the future.

    https://github.com/WebAudio/web-audio-api/issues/2450