AnalyserNode

La interfaz AnalyserNode representa un nodo habilitado para proveer frecuencia en tiempo real y analisis de tiempo-dominio. Es un AudioNode que pasa el flujo de audio sin modificación desde el origen de entrada a la salida, pero, te permite obtener los datos generados, procesarlos, y crear visualizaciones de audio.

Un AnalyzerNode tiene exactamente una entrada y una salida. El nodo trabaja incluso si la salida no se encuentra conectada.

Without modifying the audio stream, the node allows to get the frequency and time-domain data associated to it, using a FFT.

Numero de entradas 1
Numero de salidas 1 (puede estar desconectada)
Modo de conteo de canal "explicit"
Conteo de cana 1
Interpretación de canal "speakers"

Herencia

Esta interfaz hereda de las siguientes interfaces padre:

EventTarget AudioNode AnalyserNode

Propiedades

Inherits properties from its parent, AudioNode.

AnalyserNode.fftSize (en-US)

Is an unsigned long value representing the size of the FFT (Fast Fourier Transform) to be used to determine the frequency domain.

AnalyserNode.frequencyBinCount (en-US) Read only

Is an unsigned long value half that of the FFT size. This generally equates to the number of data values you will have to play with for the visualization.

AnalyserNode.minDecibels (en-US)

Is a double value representing the minimum power value in the scaling range for the FFT analysis data, for conversion to unsigned byte values — basically, this specifies the minimum value for the range of results when using getByteFrequencyData().

AnalyserNode.maxDecibels (en-US)

Is a double value representing the maximum power value in the scaling range for the FFT analysis data, for conversion to unsigned byte values — basically, this specifies the maximum value for the range of results when using getByteFrequencyData().

AnalyserNode.smoothingTimeConstant (en-US)

Is a double value representing the averaging constant with the last analysis frame — basically, it makes the transition between values over time smoother.

Methods

Inherits methods from its parent, AudioNode.

AnalyserNode.getFloatFrequencyData() (en-US)

Copies the current frequency data into a Float32Array (en-US) array passed into it.

AnalyserNode.getByteFrequencyData() (en-US)

Copies the current frequency data into a Uint8Array (en-US) (unsigned byte array) passed into it.

AnalyserNode.getFloatTimeDomainData() (en-US)

Copies the current waveform, or time-domain, data into a Float32Array (en-US) array passed into it.

AnalyserNode.getByteTimeDomainData() (en-US)

Copies the current waveform, or time-domain, data into a Uint8Array (en-US) (unsigned byte array) passed into it.

Examples

Nota: See the guide Visualizations with Web Audio API (en-US) for more information on creating audio visualizations.

Basic usage

The following example shows basic usage of an AudioContext (en-US) to create an AnalyserNode, then requestAnimationFrame and <canvas> to collect time domain data repeatedly and draw an "oscilloscope style" output of the current audio input. For more complete applied examples/information, check out our Voice-change-O-matic demo (see app.js lines 128–205 for relevant code).

js
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var analyser = audioCtx.createAnalyser();

  ...

analyser.fftSize = 2048;
var bufferLength = analyser.frequencyBinCount;
var dataArray = new Uint8Array(bufferLength);
analyser.getByteTimeDomainData(dataArray);

// draw an oscilloscope of the current audio source

function draw() {

      drawVisual = requestAnimationFrame(draw);

      analyser.getByteTimeDomainData(dataArray);

      canvasCtx.fillStyle = 'rgb(200, 200, 200)';
      canvasCtx.fillRect(0, 0, WIDTH, HEIGHT);

      canvasCtx.lineWidth = 2;
      canvasCtx.strokeStyle = 'rgb(0, 0, 0)';

      canvasCtx.beginPath();

      var sliceWidth = WIDTH * 1.0 / bufferLength;
      var x = 0;

      for(var i = 0; i < bufferLength; i++) {

        var v = dataArray[i] / 128.0;
        var y = v * HEIGHT/2;

        if(i === 0) {
          canvasCtx.moveTo(x, y);
        } else {
          canvasCtx.lineTo(x, y);
        }

        x += sliceWidth;
      }

      canvasCtx.lineTo(canvas.width, canvas.height/2);
      canvasCtx.stroke();
    };

    draw();

Especificaciones

Specification
Web Audio API
# AnalyserNode

Compatibilidad con navegadores

BCD tables only load in the browser

See also