这篇文章似乎有一种方法可以做你正在寻找的东西。
基本前提:
function MyCustomNode(){
this.input = audioContext.createGainNode();
var output = audioContext.createGainNode();
this.connect = function(target){
output.connect(target);
};
}
例子:
function AudioBus(){
this.input = audioContext.createGainNode();
var output = audioContext.createGainNode();
var custom = new MyCustomNode();
this.input.connect(custom);
custom.connect(output);
this.connect = function(target){
output.connect(target);
};
}
//create some native oscillators and our custom audio bus
var bus = new AudioBus(),
instrument1 = audioContext.createOscillator(),
instrument2 = audioContext.createOscillator(),
instrument3 = audioContext.createOscillator();
//connect our instruments to the same bus
instrument1.connect(bus.input);
instrument2.connect(bus.input);
instrument3.connect(bus.input);
bus.connect(audioContext.destination);
编辑:这个问题可能与使用 web-audio 创建自定义回声节点可能重复,但我相信您正在寻找的答案是来自 @MattDiamond的答案。这不是一个很好的解决方案,但它似乎完成了工作:
function FeedbackDelayNode(context, delay, feedback){
this.delayTime.value = delay;
this.gainNode = context.createGainNode();
this.gainNode.gain.value = feedback;
this.connect(this.gainNode);
this.gainNode.connect(this);
}
function FeedbackDelayFactory(context, delayTime, feedback){
var delay = context.createDelayNode(delayTime + 1);
FeedbackDelayNode.call(delay, context, delayTime, feedback);
return delay;
}
AudioContext.prototype.createFeedbackDelay = function(delay, feedback){
return FeedbackDelayFactory(this, delay, feedback);
};