fork(2) download
  1. var canvas = document.getElementById('canvas');
  2. var ctx = canvas.getContext('2d');
  3. var width = canvas.width = window.innerWidth;
  4. var height = canvas.height = window.innerHeight;
  5.  
  6. var audio = new Audio();
  7. audio.src = '1.mp3';
  8. audio.play();
  9.  
  10. var audCtx = new AudioContext(),
  11.  
  12. analyser = audCtx.createAnalyser(),
  13.  
  14. src = audCtx.createMediaElementSource(audio);
  15.  
  16. src.connect(analyser);
  17. analyser.connect(audCtx.destination);
  18.  
  19. var rectX; // represents the rectangle X on the canvas
  20. var arr; // the array which we will use to store the frequencies
  21.  
  22. function draw(){
  23.  
  24. ctx.clearRect(0, 0, width, height);
  25.  
  26. arr = new Uint8Array(analyser.frequencyBinCount);
  27.  
  28. analyser.getByteFrequencyData(arr);
  29.  
  30. for(var i = 0; i < 200; i++){
  31.  
  32. barX = (width/2 - 300) + 3 * i;
  33.  
  34. ctx.fillRect(barX, height/2, 2, -arr[i]);
  35.  
  36. }
  37.  
  38. window.requestAnimationFrame(draw);
  39.  
  40. }
  41.  
  42. draw();
Runtime error #stdin #stdout #stderr 0.01s 30424KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog.js:1:0 ReferenceError: document is not defined