7

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).

Echo Node

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

4

2 回答 2

8

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.

于 2012-12-05T22:28:28.747 回答
3

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).

于 2012-12-05T09:41:10.083 回答