Skip to main content

Object3D

AudioListener

The AudioListener represents a virtual listener of the all positional and non- positional audio effects in the scene.
A three.js application usually creates a single instance of AudioListener. It is a mandatory constructor parameter for audios entities like Audio and PositionalAudio.
In most cases, the listener object is a child of the camera. So the 3D transformation of the camera represents the 3D transformation of the listener.

Code Example

// create an AudioListener and add it to the camera const listener = new
THREE.AudioListener(); camera.add( listener ); // create a global 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(); });

Examples

[example:webaudio_sandbox webaudio / sandbox ]
[example:webaudio_timing webaudio / timing ]
[example:webaudio_visualizer webaudio / visualizer ]

Constructor

AudioListener

function AudioListener( ): void;  

Create a new AudioListener.

Properties

context

context: AudioContext;  

The AudioContext of the listener given in the constructor.

gain

gain: GainNode;  

A GainNode created using AudioContext.createGain().

filter

filter: AudioNode;  

Default is null.

timeDelta

timeDelta: Number;  

Time delta value for audio entities. Use in context of AudioParam.linearRampToValueAtTimeDefault(). Default is .

Methods

getInput

function getInput( ): GainNode;  

Return the gainNode.

removeFilter

function removeFilter( ): this;  

Set the filter property to null.

getFilter

function getFilter( ): AudioNode;  

Returns the value of the filter property.

setFilter

function setFilter( value: AudioNode ): this;  

Set the filter property to value.

getMasterVolume

function getMasterVolume( ): Float;  

Return the volume.

setMasterVolume

function setMasterVolume( value: Number ): this;  

Set the volume.

Source

src/audio/AudioListener.js