Create a non-positional ( global ) audio object.
This uses the [link:https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API Web Audio API].
// 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();
});
[example:webaudio_sandbox webaudio / sandbox ]
[example:webaudio_visualizer webaudio / visualizer ]
listener — (required) [page:AudioListener AudioListener] instance.
Whether to start playback automatically. Default is `false`.
The [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioContext AudioContext] of the [page:AudioListener 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 [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioNode 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 [link:https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode BiquadFilterNodes]. Filters are set via [page:Audio.setFilter] or [page:Audio.setFilters].
A [link:https://developer.mozilla.org/en-US/docs/Web/API/GainNode GainNode] created using [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createGain AudioContext.createGain]().
Whether playback can be controlled using the [page:Audio.play play](), [page:Audio.pause 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 [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/start AudioBufferSourceNode.start](). Default is `0`.
Overrides the duration of the audio. Same as the `duration` parameter of [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/start AudioBufferSourceNode.start](). Default is `undefined` to play the whole buffer.
An [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode AudioBufferSourceNode] created using [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createBufferSource AudioContext.createBufferSource]().
Type of the audio source. Default is string 'empty'.
String denoting the type, set to 'Audio'.
Connect to the [page:Audio.source]. This is used internally on initialisation and when setting / removing filters.
Disconnect from the [page:Audio.source]. This is used internally when setting / removing filters.
Returns the detuning of oscillation in cents.
Returns the first element of the [page:Audio.filters filters] array.
Returns the [page:Audio.filters filters] array.
Return the value of [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/loop source.loop] (whether playback should loop).
Return the [page:Audio.gain gainNode].
Return the value of [page:Audio.playbackRate playbackRate].
Return the current volume.
If [page:Audio.hasPlaybackControl hasPlaybackControl] is true, starts playback.
If [page:Audio.hasPlaybackControl hasPlaybackControl] is true, pauses playback.
Called automatically when playback finished.
Setup the [page:Audio.source source] to the audioBuffer, and sets [page:Audio.sourceType sourceType] to 'buffer'.
If [page:Audio.autoplay 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 [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/loop source.loop] to `value` (whether playback should loop).
Set [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/loopStart source.loopStart] to `value`.
Set [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/loopEnd source.loopEnd] to `value`.
Applies the given object of type [link:https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement HTMLMediaElement] as the source of this audio.
Also sets [page:Audio.hasPlaybackControl hasPlaybackControl] to false.
Applies the given object of type [link:https://developer.mozilla.org/en-US/docs/Web/API/MediaStream MediaStream] as the source of this audio.
Also sets [page:Audio.hasPlaybackControl hasPlaybackControl] to false.
Setup the [page:Audio.source source] to the audioBuffer, and sets [page:Audio.sourceType sourceType] to 'audioNode'.
Also sets [page:Audio.hasPlaybackControl hasPlaybackControl] to false.
If [page:Audio.hasPlaybackControl hasPlaybackControl] is enabled, set the [page:Audio.playbackRate playbackRate] to `value`.
Set the volume.
If [page:Audio.hasPlaybackControl hasPlaybackControl] is enabled, stops playback.
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]