Reputation: 3
I wrote this code to control a web application through a Midi controller. A button on the web interface plays a sample. A reverb (created with .createConvolver() method) is added to the sound of the sample; a slider on the web interface controls the gain of the reverb (gainNode11).
function onMIDIMessage (message) {
console.log(message.data);
......
// Creating the convolution reverb node
var impulseResponseBuffer;
var getSound = new XMLHttpRequest ();
getSound.open("get", "circular.wav", true);
getSound.responseType = "arraybuffer";
const gainNode11 = audioContext.createGain();
getSound.onload = function () {
audioContext.decodeAudioData(getSound.response, function(buffer) {
impulseResponseBuffer = buffer;
});
};
getSound.send();
//Routing
var convolver = audioContext.createConvolver();
convolver.buffer = impulseResponseBuffer;
track11.connect(convolver);
convolver.connect(gainNode11);
gainNode11.connect(checkbox);
track11.connect(checkbox);
// Reverb gain Midi control
if (message.data[0] === 176 && message.data[1] === 50) {
if (audioContext.state === 'suspended') {
audioContext.resume();
}
// Conversion of the reverb range value
var volumeMidi11 = convertRange(message.data[2],[0,127],[0.000,2.000]);
gainNode11.gain.value = volumeMidi11;
volumeControl11.value = volumeMidi11;
console.log(gainNode11.gain.value);
}
//Triggering of the sample by Midi controller
//If the slider/knob is moved
if (message.data[0] === 176 && message.data[1] === 51 && message.data[2] === 127) {
if (audioContext.state === 'suspended') {
audioContext.resume();
}
audioElement11.currentTime = 0;
audioElement11.play();
playButton11.style.background = "#fc61c9";
audioElement11.loop = 'true';
playButton11.playing = 'true';
sub11.innerHTML = "Son déclenché";
}
//if the slider/knob is not moved
if (message.data[0] === 176 && message.data[1] === 51 && message.data[2] < 127) {
audioElement11.pause();
playButton11.style = "bg-warning";
playButton11.playing = 'false';
sub11.innerHTML = "Son arrêté";
}
The controller Midi knob who triggers the sample works fine, but when I rotate the knob who is supposed to control the gain of the reverb, the slider on the web interface moves but no reverb is added to the sound.
Do you have any suggestions?
Thanks in advance.
Upvotes: 0
Views: 28