New games every week!
Getting the ConvolverNode to Work Blog
29th June 2021
Beep!!

-=beep=-

-=-=-

I was aiming to do a bunch of my todo list, yesterday, but oddly found myself looking into ConvolverNode

From the Mozilla Docs
The ConvolverNode interface is an AudioNode that performs a Linear Convolution on a given AudioBuffer, often used to achieve a reverb effect. A ConvolverNode always has exactly one input and one output.


"A ConvolverNode always has EXACTLY One Input and One Output.."
Sound goes in one end, and echoed sound comes out the other.
EXACTLY ONE input, and ONE output.

So I did what it said and added the ConvolverNode between the SoundBuffer and the GainNode.

Nothing.
No sound.
I checked and double checked my code. Everything seemed to be in order, but no audio was coming out of the browser when I linked the Convolver into the mix.

I spent ages hunting for examples all over the net with absolutely nothing fruitful coming up, because everyone gives the exact same solution. Take the ConvolverNode and add it to the GainNode. *simples*

But no. It wasn't working. No matter how much I tried, adding the ConvolverNode stopped all audio.

Hours later, literally HOURS later, I realised why nothing was working.
Everybody.. Literally EVERY example I found online, was missing one vital part of information.

It takes TWO inputs..


One is the sound you want echoed, and the other is an audio form of the echo you want it to use. An "Impulse" waveform.

You have to load the Impulse Waveform into the ConvolverNode's Buffer, and THEN it'll do what you want it to.

var request = new XMLHttpRequest();
  request.open("GET", "echo_multitap2.wav");
  request.responseType = "arraybuffer";
  request.onload = function() {
    audioContext.decodeAudioData(request.response, function(buffer) {
      EchoImpulse = buffer;
      ConvolverNode.buffer=EchoImpulse;
      (success || (function(){ }))()
    }, err || function(msg) {console.error(msg)});
  }
request.send();


Load the impulse waveform in, import it into the buffer, THEN connect the Sound to the ConvolverNode and the ConvolverNode to the GainNode.

Once I finally figured this out, I did a few quick tests and indeed everything seems to be working great.

An example Echo Multitap impulse wave.

Today I need to figure out how/if I can create a single waveform full of impulses, so that I can let the coder switch between different echo types without reloading things, or if I'm finally going to have to add caching into the mix to help store it all.
Hmmm..
Views 59, Upvotes 2  
Daily Blog
New games every week!
Site credits : PHP script, Blog posts, Games, Music, Pixelart, Poems and More : Jayenkai
(c) Jayenkai 2023 and onwards, RSS feed

Blog - Getting the ConvolverNode to Work - AGameAWeek