Skip to main content

Object3DAudio

PositionalAudio

Create a positional audio object.

This uses the Web Audio API.

Code Example

// create an AudioListener and add it to the camera const listener = new
THREE.AudioListener(); camera.add( listener ); // create the PositionalAudio
object (passing in the listener) const sound = new THREE.PositionalAudio(
listener ); // load a sound and set it as the PositionalAudio object's buffer
const audioLoader = new THREE.AudioLoader(); audioLoader.load(
'sounds/song.ogg', function( buffer ) { sound.setBuffer( buffer );
sound.setRefDistance( 20 ); sound.play(); }); // create an object for the
sound to play from const sphere = new THREE.SphereGeometry( 20, 32, 16 );
const material = new THREE.MeshPhongMaterial( { color: 0xff2200 } ); const
mesh = new THREE.Mesh( sphere, material ); scene.add( mesh ); // finally add
the sound to the mesh mesh.add( sound );

Examples

[example:webaudio_orientation webaudio / orientation ]
[example:webaudio_sandbox webaudio / sandbox ]
[example:webaudio_timing webaudio / timing ]

Constructor

PositionalAudio

function PositionalAudio( listener: AudioListener ): void;  

listener — (required) AudioListener instance.

Properties

See the Audio class for inherited properties.

panner

panner: PannerNode;  

The PositionalAudio's PannerNode.

Methods

See the Audio class for inherited methods.

getOutput

function getOutput( ): PannerNode;  

Returns the panner.

getRefDistance

function getRefDistance( ): Float;  

Returns the value of panner.refDistance.

setRefDistance

function setRefDistance( value: Float ): this;  

Sets the value of panner.refDistance.

getRolloffFactor

function getRolloffFactor( ): Float;  

Returns the value of panner.rolloffFactor.

setRolloffFactor

function setRolloffFactor( value: Float ): this;  

Sets the value of panner.rolloffFactor.

getDistanceModel

function getDistanceModel( ): String;  

Returns the value of panner.distanceModel.

setDistanceModel

function setDistanceModel( value: String ): this;  

Sets the value of panner.distanceModel.

getMaxDistance

function getMaxDistance( ): Float;  

Returns the value of panner.maxDistance.

setMaxDistance

function setMaxDistance( value: Float ): this;  

Sets the value of panner.maxDistance.

setDirectionalCone

function setDirectionalCone( coneInnerAngle: Float, coneOuterAngle: Float,
coneOuterGain: Float ): this;

This method can be used in order to transform an omnidirectional sound into a directional sound.

Source

src/audio/PositionalAudio.js