W3C home > Mailing lists > Public > public-audio@w3.org > January to March 2012

Re: Advice on the convolver node

From: Raymond Toy <rtoy@google.com>
Date: Tue, 20 Mar 2012 10:18:25 -0700
Message-ID: <CAE3TgXHBu=sM=V6cXTiuY=YBLQ3FuiYdy6TB5DSURr0QyRh1cg@mail.gmail.com>
To: Chris Lowis <chris.lowis@bbc.co.uk>
Cc: public-audio@w3.org
On Tue, Mar 20, 2012 at 9:30 AM, Chris Lowis <chris.lowis@bbc.co.uk> wrote:

>
> My question - is it possible to set the convolver buffer from a regular
> javascript array? For example to generate the impulse response using
> Math.sin()?
>
>
Yes, you can do this.  Something like the following should work:

    var convolver = context.createConvolver();

    convolver.buffer = myImpulseResponse();

where myImpulseResponse can be something like:

function myImpulseResponse() {
    var audioBuffer = context.createBuffer(1, sampleFrameLength,
context.sampleRate);

    var n = audioBuffer.length;
    var data = audioBuffer.getChannelData(0);

    <fill data array with your desired impulse response>

   return audioBuffer;
}

Ray
Received on Tuesday, 20 March 2012 17:18:57 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 20 March 2012 17:19:01 GMT