GoogleChrome/audion

Audio is confused with CompositeAudioNodes and connect/disconnect redefined using prototypes

micbuffa opened this issue · 1 comments

Hi ! We developed the WebAudioPlugin initiative, in which we create plugins made of an entire graph of WebAudio nodes. In order to be able to use connect/disconnect like with regular WebAudio nodes, we used prototypes to redefine the connect/disconnect methods. In earlier versions of Audio this was fine, but since an update I could not identify, audio checks if source and destination nodes are well known WebAudio nodes, in the tracing.js/connectDecorator, this test breaks the thing:

if (!sourceResourceId) {
        console.warn(
            'Audion could not identify the object calling "connect": ', this);
      }

Result : some nodes are not displayed in the debugger and the error message above appears in the console.

How to try this behavior : go to https://output.jsbin.com/xevahu open the console

The error can be traced back in the plugin SDK, line 65 👍 the line causing the error is the last one with the call to connect.


AudioNode.prototype.connect = function (that) {
  var args = Array.prototype.slice.call(arguments);
  if (args[0]._isCompositeAudioNode && !args[2] && !args[1]) {
    args[0] = args[0]._input;
    args[1] = that._output;
  }
  else if (args[0]._isCompositeAudioNode) args[0] = args[2];
  this._connect.apply(this, args);
};

Should that warning message be showing up when using a ConstantSourceNode? Or is what I'm seeing a new/different issue?

If you put this snippet into https://hoch.github.io/canopy/, open chrome dev tools console, and press play, you'll see that warning message:

// 1. Check the tutorial in the main menu.
// 2. Then press ARROW button on the tool bar left.
// 3. Have some WebAudio fun!
//
// @channels 1
// @duration 1.0
// @sampleRate 44100

const constantSourceNode = context.createConstantSource()

var osc = new OscillatorNode(context);
var gain = context.createGain();

constantSourceNode.connect(osc.frequency);

osc.frequency.setValueAtTime(261.6, 0.0);
gain.gain.value = 0.5;

osc.connect(gain).connect(context.destination);

osc.start();

If you comment out the line that calls connect on the constantSourceNode, then the warning is not logged.