JSFiddle - React, Tailwind, and code Playground
JavaScript
var context = new webkitAudioContext();
var request = new XMLHttpRequest();
request.open("GET", "http://freesound.org/data/previews/40/40770_12368-lq.ogg", true);
request.responseType = "arraybuffer";
request.onload = function () {
context.decodeAudioData(request.response, function (buffer) {
// "buffer" here is a pretty simple 4x4 house beat at 127bpm
// with a strong kick drum and a glitchy hi-hat pattdrn
var sound = context.createOscillator();
sound.frequency.value = 440;
var sidechain = context.createBufferSource();
sidechain.buffer = buffer;
var gain = context.createGainNode();
gain.gain.value = 0.0;
// The sound source connects into a gain node which will be
// modulated by the sidechain node's output
sound.connect(gain);
gain.connect(context.destination);
// Here the sidechain outputs directly into the gain node's
// gain AudioParam for real time sidechaining
sidechain.connect(gain.gain);
// Turn them both on, and you can still hear the buffer source node
sound.noteOn(0);
sidechain.noteOn(0);
});
};
request.send();