Skip to content

Removing AudioWorkletNode from the AudioContext graph does not stop it from being executed #2658

@juj

Description

@juj

Describe the issue

Something I notice taking place in both Firefox and Chrome, which seems like a spec issue rather than an individual implementation issue(?):

If one creates an AudioWorkletNode, and adds it to the graph, then, the process() function will start to be called on the node periodically as the graph is being rendered.

However, if one then .disconnect()s the node from the graph, the process() function will still keep calling, as if the node would still be rendering.

This seems like a computational resource leak? When an AudioWorkletNode is no longer part of the graph, then it won't have inputs flowing to it, and all output generated by calling the node's process() function will be discarded?

Is there a design rationale for why removing an AudioWorkletNode from the graph does not stop it from being rendered in this kind of a "dummy"/detached manner? Would it not be most sensible to treat a disconnected node as being inactive, since there is no actual rendering that flows through it, as far as I can understand?

Here is a small repro:

audioworklet.js

class Processor extends AudioWorkletProcessor {
  process(inputs, outputs) {
    console.log('process');
    for(var o of outputs) {
      for(var data of o) {
        for(var i = 0; i < data.length; ++i) {
          data[i] = (Math.random()*2-1)*0.05;
        }
      }
    }
    return true;
  }
}
registerProcessor('processor', Processor);

audioworklet.html

<html><body>
<button onclick="audioContext.resume();">audioContext.resume();</button>
<button onclick="audioWorkletNode.disconnect();">audioWorkletNode.disconnect();</button>
<script>
var audioContext = new AudioContext(), audioWorkletNode;
audioContext.audioWorklet.addModule('audioworklet.js').then(() => {
  audioWorkletNode = new AudioWorkletNode(audioContext, 'processor');
  audioWorkletNode.connect(audioContext.destination);
});
</script>
</body></html>

The message process will keep being logged in the browser after clicking on the resume() and disconnect() buttons once.

I.e. the AudioWorkletNode is still processing in real time, even when it is no longer part of the graph.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Agenda+Should be discussed at the next WG meeting. https://speced.github.io/spec-maintenance/about/Needs DiscussionThe issue needs more discussion before it can be fixed.category: enhancementSubstantive changes that do not add new features. https://www.w3.org/policies/process/#class-3

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions