Create a positional audio object.
This uses the [link:https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API Web Audio API].
[example:webaudio_orientation webaudio / orientation]
[example:webaudio_sandbox webaudio / sandbox]
[example:webaudio_timing webaudio / timing]
// create an AudioListener and add it to the camera
var listener = new v3d.AudioListener();
camera.add(listener);
// create the PositionalAudio object (passing in the listener)
var sound = new v3d.PositionalAudio(listener);
// load a sound and set it as the PositionalAudio object's buffer
var 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
var sphere = new v3d.SphereGeometry(20, 32, 16);
var material = new v3d.MeshPhongMaterial({ color: 0xff2200 });
var mesh = new v3d.Mesh(sphere, material);
scene.add(mesh);
// finally add the sound to the mesh
mesh.add(sound);
listener — (required) [page:AudioListener AudioListener] instance.
See the [page:Audio Audio] class for inherited properties.
The PositionalAudio's [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode PannerNode].
See the [page:Audio Audio] class for inherited methods.
Returns the [page:PositionalAudio.panner panner].
Returns the value of [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/refDistance panner.refDistance].
Sets the value of [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/refDistance panner.refDistance].
Returns the value of [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/rolloffFactor panner.rolloffFactor].
Sets the value of [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/rolloffFactor panner.rolloffFactor].
Returns the value of [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/distanceModel panner.distanceModel].
Sets the value of [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/distanceModel panner.distanceModel].
Returns the value of [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/maxDistance panner.maxDistance].
Sets the value of [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/maxDistance panner.maxDistance].
This method can be used in order to transform an omnidirectional sound into a [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode directional sound].
[sourceHint]