AudioAnalyser

Create a AudioAnalyser object, which uses an AnalyserNode to analyse audio data.

This uses the Web Audio API.

Example

webaudio / sandbox
webaudio / visualizer

// create an AudioListener and add it to the camera var listener = new v3d.AudioListener(); camera.add(listener); // create an Audio source var sound = new v3d.Audio(listener); // load a sound and set it as the Audio object's buffer var audioLoader = new v3d.AudioLoader(); audioLoader.load('sounds/ambient.ogg', function(buffer) { sound.setBuffer(buffer); sound.setLoop(true); sound.setVolume(0.5); sound.play(); }); // create an AudioAnalyser, passing in the sound and desired fftSize var analyser = new v3d.AudioAnalyser(sound, 32); // get the average frequency of the sound var data = analyser.getAverageFrequency();

Constructor

AudioAnalyser(audio, fftSize)

Create a new AudioAnalyser.

Properties

.analyser : AnalyserNode

An AnalyserNode used to analyze audio.

.fftSize : Integer

A non-zero power of two up to 2048, representing the size of the FFT (Fast Fourier Transform) to be used to determine the frequency domain. See this page for details.

.data : Uint8Array

A Uint8Array with size determined by analyser.frequencyBinCount used to hold analysis data.

Methods

.getFrequencyData () : Uint8Array

Uses the Web Audio's getByteFrequencyData method. See that page.

.getAverageFrequency () : Number

Get the average of the frequencies returned by the getFrequencyData method.

Source

For more info on how to obtain the source code of this module see this page.