Create a positional audio object.
This uses the Web Audio API.
// create an AudioListener and add it to the camera
const listener = new v3d.AudioListener();
camera.add(listener);
// create the PositionalAudio object (passing in the listener)
const sound = new v3d.PositionalAudio(listener);
// load a sound and set it as the PositionalAudio object's buffer
const audioLoader = new v3d.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 v3d.SphereGeometry(20, 32, 16);
const material = new v3d.MeshLambertMaterial({ color: 0xff2200 });
const mesh = new v3d.Mesh(sphere, material);
app.scene.add(mesh);
// finally add the sound to the mesh
mesh.add(sound);
listener — (required) AudioListener instance.
See the Audio class for inherited properties.
The PositionalAudio's PannerNode.
See the Audio class for inherited methods.
Returns the panner.
Returns the value of panner.refDistance.
Sets the value of panner.refDistance.
Returns the value of panner.rolloffFactor.
Sets the value of panner.rolloffFactor.
Returns the value of panner.distanceModel.
Sets the value of panner.distanceModel.
Returns the value of panner.maxDistance.
Sets the value of panner.maxDistance.
This method can be used in order to transform an omnidirectional sound into a directional sound.
For more info on how to obtain the source code of this module see this page.