audioContext.decodeAudioData(audioData)
.then(function(decoded) {
// just get the left ear, it's fine ;)
let data = decoded.getChannelData(0);
for (let i = 0; i < data.length; i += 1) {
// convert raw sample to within 0-255 range
let hue = Math.ceil((data[i] + 1) * 255 / 2);
// convert HSL to an RGB array
let rgb = hslToRgb(hue, 200, 150);
// create the pixel
imgData.data[i*4] = rgb[0];
imgData.data[i*4+1] = rgb[1];
imgData.data[i*4+2] = rgb[2];
imgData.data[i*4+3] = rgb[3];
}
// put the pixels on a canvas element
canvas.putImageData(imgData, 0, 0);
});