if (! window.AudioContext) {
if (! window.webkitAudioContext) {
alert('no audiocontext found');
window.AudioContext = window.webkitAudioContext;
var audioContext, analyserNode, javascriptNode, sourceNode;
var frequencies = new Array();
var tracks = new Array();
String musicUrl, artistName, musicName, info;
ctx.fillStyle = "rgba(75, 147, 210, .8)";
ctx.strokeStyle = "rgba(253, 245, 237, 0.07)";
c = color('hsba(160, 100%, 30%, 0.5)');
echelle = width/bufferSize;
ellipse(width/2, height/2, 150, 150);
width/2 - 40, height/2 - 60,
width/2 - 40, height/2 + 60,
else if(frameCount%3==0){
if(frameCount>6) ctx.drawImage(img, 0, -2);
ctx.moveTo(0,Y+frequencies[0]*sensib);
for(var i=step;i<bufferSize;i+=step){
ctx.lineTo(i*echelle,Y+frequencies[i]*sensib);
for(var i=1; i<bufferSize-step; i+=step){
ctx.moveTo(i*echelle, Y+frequencies[i]*sensib);
ctx.lineTo(i+step, Y+frequencies[i+step]*sensib);
img.src = document.getElementById("pjsCanvas").toDataURL("image/png");
loadSound("https://openprocessing.org/sketch/1583090/files/01%20What%20A%20Wonderful%20World.mp3");
audioContext = new AudioContext();
javascriptNode = audioContext.createScriptProcessor(2048, 1, 1);
javascriptNode.connect(audioContext.destination);
javascriptNode.onaudioprocess = function() {
var array = new Uint8Array(analyserNode.frequencyBinCount);
analyserNode.getByteTimeDomainData(array);
analyserNode = audioContext.createAnalyser();
analyserNode.smoothingTimeConstant = 0.3;
analyserNode.fftSize = bufferSize * 2;
sourceNode = audioContext.createBufferSource();
sourceNode.connect(analyserNode);
analyserNode.connect(javascriptNode);
sourceNode.connect(audioContext.destination);
function loadSound(url) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.responseType = 'arraybuffer';
request.onload = function() {
audioContext.decodeAudioData(request.response, function(buffer) {
function playSound(buffer) {
sourceNode.buffer = buffer;