简体   繁体   English

Web Audio API:发现节点的连接

[英]Web Audio API: discover a node's connections

With the Web Audio API, is there a way to discover a node's connections? 使用Web Audio API,是否可以发现节点的连接?

For example, given 例如,给定

ctx = new AudioContext();
g1 = ctx.createGain();
g2 = ctx.createGain();
g1.connect(g2);

is there a method I can call on g1 that will return [g2] ? 我可以在g1上调用一个返回[g2]吗?

I'm interested in writing a javascript library to visualize the current audio graph, similar to the Firefox Web Audio Editor . 我有兴趣编写一个类似于Firefox Web Audio Editor的JavaScript库以可视化当前音频图。

The short answer is no - there is no such method. 简短的答案是“否”-没有这种方法。 You'll have to keep track of your connections yourself. 您必须自己跟踪连接。

You could potentially do something like this: 您可能会做这样的事情:

var connect = AudioNode.prototype.connect;
var disconnect = AudioNode.prototype.disconnect;

AudioNode.prototype.connect = function( dest ) {
  this._connections || ( this._connections = [] );
  if ( this._connections.indexOf( dest ) === -1 ) {
    this._connections.push( dest );
  }
  return connect.apply( this, arguments );
};

AudioNode.prototype.disconnect = function() {
  this._connections = [];
  return disconnect.apply( this, arguments );
};

This is a quick example, and it doesn't account for disconnect arguments. 这是一个简单的示例,它不考虑disconnect参数。 But something along those lines could work, I think. 但是,我认为,遵循这些原则可以起作用。

There are good reasons not to do something like this. 有充分的理由这样做。 But it would allow you to keep the application code generic, which is really what you need if you want to be able to visualize arbitrary audio graphs. 但是, 将使您可以保持应用程序代码的通用性,如果您希望能够可视化任意音频图,那么这确实是您所需要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM