Creating a custom echo node with web-audio

浪子不回头ぞ 提交于 2019-12-07 01:21:32

问题


I'm playing with the webkit Audio API and I'm trying to create an Echo effect, to accomplish that I've connected a DelayNode with a GainNode in a loop (The output of one is the input of the other, and viceversa).

The effect works fine, but now I want to create an EchoNode Object that I can just plug-in and connect with the other AudioNode objects.

Something like:

myEchoNode = new EchoNode(); 
myConvolverNode = context.createConvolver();
myConvolverNode.connect(myEchoNode);

I think that I should make my EchoNode inherit from AudioNode, so that the connect function of every other AudioNode would work, but I don't know how to do that in Javascript with the web Audio API.

Can anyone give me a hint, or if you think that there is a better way to accomplish that I would greatly appreciate it.

Thanks


回答1:


Have a look at this article I wrote, it might give you some ideas: http://www.html5rocks.com/en/tutorials/casestudies/jamwithchrome-audio/ (which explains the basic idea behind tuna.js that Taoist recommended).




回答2:


Oskar's solution should do the trick, but I want to point out that it will require you to connect to your EchoNode in a nonstandard way (using EchoNode.input rather than simply connecting to the EchoNode itself). For simple effects such as feedback delay, this can be avoided by creating the EchoNode via a factory function that returns a native DelayNode mixed with some extra properties. Here's an example from SynthJS:

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);
};

As you can see, the result is a native DelayNode that can be connected to other nodes in the standard fashion, but it has an attached gain node that provides the feedback effect.



来源:https://stackoverflow.com/questions/13702733/creating-a-custom-echo-node-with-web-audio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!