Create a non-positional (global) 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 a global audio source
const sound = new v3d.Audio(listener);
// load a sound and set it as the Audio object's buffer
const audioLoader = new v3d.AudioLoader();
audioLoader.load('sounds/ambient.ogg', function(buffer) {
sound.setBuffer(buffer);
sound.setLoop(true);
sound.setVolume(0.5);
sound.play();
});
listener — (required) AudioListener instance.
Whether to start playback automatically. Default is false
.
The AudioContext of the listener given in the constructor.
Modify pitch, measured in cents. +/- 100 is a semitone. +/- 1200 is an octave. Default is 0
.
Represents an array of AudioNodes. Can be used to apply a variety of low-order filters to create more complex sound effects. In most cases, the array contains instances of BiquadFilterNodes. Filters are set via Audio.setFilter or Audio.setFilters.
A GainNode created using AudioContext.createGain().
Whether playback can be controlled using the play(),
pause() etc. methods. Default is true
.
Whether the audio is currently playing.
A reference to the listener object of this audio.
Speed of playback. Default is 1
.
An offset to the time within the audio buffer that playback should begin. Same as the offset
parameter of AudioBufferSourceNode.start(). Default is 0
.
Overrides the duration of the audio. Same as the duration
parameter of AudioBufferSourceNode.start(). Default is undefined
to play the whole buffer.
An AudioBufferSourceNode created using AudioContext.createBufferSource().
Type of the audio source. Default is string 'empty'.
String denoting the type, set to 'Audio'.
Connect to the Audio.source. This is used internally on initialisation and when setting / removing filters.
Disconnect from the Audio.source. This is used internally when setting / removing filters.
Returns the detuning of oscillation in cents.
Returns the first element of the filters array.
Returns the filters array.
Return the value of source.loop (whether playback should loop).
Return the gainNode.
Return the value of playbackRate.
Return the current volume.
If hasPlaybackControl is true, starts playback.
If hasPlaybackControl is true, pauses playback.
Called automatically when playback finished.
Setup the source to the audioBuffer, and sets sourceType to 'buffer'.
If autoplay, also starts playback.
Defines the detuning of oscillation in cents.
Applies a single filter node to the audio.
value - arrays of filters.
Applies an array of filter nodes to the audio.
Set source.loop to value
(whether playback should loop).
Set source.loopStart to value
.
Set source.loopEnd to value
.
Applies the given object of type HTMLMediaElement as the source of this audio.
Also sets hasPlaybackControl to false.
Applies the given object of type MediaStream as the source of this audio.
Also sets hasPlaybackControl to false.
Setup the source to the audioBuffer, and sets sourceType to 'audioNode'.
Also sets hasPlaybackControl to false.
If hasPlaybackControl is enabled, set the playbackRate to value
.
Set the volume.
If hasPlaybackControl is enabled, stops playback.
Verge3D offers audio puzzles to simplify work with sounds and music.
For more info on how to obtain the source code of this module see this page.