Ver Mensaje Individual
  #4 (permalink)  
Antiguo 13/02/2014, 11:10
Avatar de jonni09lo
jonni09lo
Colaborador
 
Fecha de Ingreso: septiembre-2011
Ubicación: Estigia
Mensajes: 1.471
Antigüedad: 13 años, 5 meses
Puntos: 397
Respuesta: Web audio Api

Si revisas este código:

Código Javascript:
Ver original
  1. var gradient = ctx.createLinearGradient(0,0,0,300);
  2. gradient.addColorStop(1,'#000000');
  3. gradient.addColorStop(0.75,'#ff0000');
  4. gradient.addColorStop(0.25,'#ffff00');
  5. gradient.addColorStop(0,'#ffffff');
  6.  
  7. // when the javascript node is called
  8. // we use information from the analyzer node
  9. // to draw the volume
  10. javascriptNode.onaudioprocess = function() {
  11.  
  12.     // get the average for the first channel
  13.     var array =  new Uint8Array(analyser.frequencyBinCount);
  14.     analyser.getByteFrequencyData(array);
  15.  
  16.     // clear the current state
  17.     ctx.clearRect(0, 0, 1000, 325);
  18.  
  19.     // set the fill style
  20.     ctx.fillStyle=gradient;
  21.     drawSpectrum(array);
  22.  
  23. }
  24. function drawSpectrum(array) {
  25. for ( var i = 0; i < (array.length); i++ ){
  26.         var value = array[i];
  27.         ctx.fillRect(i*5,325-value,3,325);
  28.     }
  29. };

Notarás que lo que se usa para dibujar el espectro es el array generado por new Uint8Array(analyser.frequencyBinCount) y si revisas la función drawSpectrum verás de que es el encargado de dibujar las lineas.

Saludos
__________________
Haz preguntas inteligentes-Como ser Hacker
No hacer preguntas por mensaje privado. No sólo no es inteligente sino que es egoísta.