Capítulo 300 de 859

Chapter 300: AudioAnalyser

Core Idea

This class can be used to analyse audio data.

Key Concepts

  • analyser : AnalyserNode: The global audio listener.
  • data : Uint8Array: Holds the analyzed data.

Code Examples

// create an AudioListener and add it to the camera
const listener = new THREE.AudioListener();
camera.add( listener );
// create an Audio source
const sound = new THREE.Audio( listener );
// load a sound and set it as the Audio object's buffer
const audioLoader = new THREE.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
const analyser = new THREE.AudioAnalyser( sound, 32 );
// get the average frequency of the sound
const data = analyser.getAverageFrequency();
  • What it demonstrates: Typical usage of AudioAnalyser.

Reference Tables

Constructor

Signature
new AudioAnalyser( audio : Audio, fftSize : number )

Properties

PropertyDescription
.analyser : AnalyserNodeThe global audio listener.
.data : Uint8ArrayHolds the analyzed data.

Methods

MethodDescription
.getAverageFrequency() : numberReturns the average of the frequencies returned by AudioAnalyser#getFrequencyData.
.getFrequencyData() : Uint8ArrayReturns an array with frequency data of the audio.

Key Takeaways

  1. Most relevant properties: analyser, data.
  2. Key methods: getAverageFrequency, getFrequencyData.

Connects To