What I am trying to learn / do: How to set up a simple working convolver (reverb) into my code sandbox below using an impulse response. I thought it was similar to setting a filter but things seem quite different.
What I tried: As with all new technologies things change at a fast pace making it difficult to know which implementation is correct and what is not. I looked at countless WebAudio Api Convolver Tutorials, many were old and others were working but far too "bloated" making it hard to understand what is going on. I tried to implement some of the examples from the mozilla documentation:
I already had a look at: https://developer.mozilla.org/en-US/docs/Web/API/ConvolverNode/buffer
My question: How do I integrate a convolver properly in the context below? As you can see I tried but cant figure this out.
window.addEventListener('load', init, false);
function init() {
setupWebAudio();
}
function setupWebAudio() {
var audio = document.getElementById('music');
var context = new AudioContext();
var source = context.createMediaElementSource(audio);
var filter = context.createBiquadFilter();
var convolver = context.createConvolver();
var inpulseRes = "hall.mp3";
var hallBuffer = inpulseRes;
soundSource = context.createBufferSource();
soundSource.buffer = hallBuffer;
convolver.buffer = hallBuffer;
filter.type = 'lowpass';
filter.frequency.value = 400;
var theParent = document.getElementById("test");
theParent.addEventListener("mousedown", doSomething, false);
function doSomething(e) {
if (e.target !== e.currentTarget) {
if(e.target == theParent.children[0]){
filter.frequency.value += 200;
}
else if(e.target == theParent.children[1]){
filter.frequency.value -= 200;
}
else if(e.target == theParent.children[2]){
filter.type = 'highpass';
}
}
e.stopPropagation();
}
source.connect(filter);
source.connect(convolver);
filter.connect(context.destination);
audio.play();
}