You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

262 lines
8.3 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<base href="../../../" />
<script src="page.js"></script>
<link type="text/css" rel="stylesheet" href="page.css" />
</head>
<body>
[page:Object3D] &rarr;
<h1>[name]</h1>
<p class="desc">
Create a non-positional ( global ) audio object.<br /><br />
This uses the
[link:https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API Web Audio API].
</p>
<h2>Code Example</h2>
<code>
// 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();
});
</code>
<h2>Examples</h2>
<p>
[example:webaudio_sandbox webaudio / sandbox ]<br />
[example:webaudio_visualizer webaudio / visualizer ]
</p>
<h2>Constructor</h2>
<h3>[name]( [param:AudioListener listener] )</h3>
<p>listener — (required) [page:AudioListener AudioListener] instance.</p>
<h2>Properties</h2>
<h3>[property:Boolean autoplay]</h3>
<p>Whether to start playback automatically. Default is `false`.</p>
<h3>[property:AudioContext context]</h3>
<p>
The [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioContext AudioContext] of the [page:AudioListener listener] given in the
constructor.
</p>
<h3>[property:Number detune]</h3>
<p>
Modify pitch, measured in cents. +/- 100 is a semitone. +/- 1200 is an
octave. Default is `0`.
</p>
<h3>[property:Array filters]</h3>
<p>
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].
</p>
<h3>[property:GainNode gain]</h3>
<p>
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]().
</p>
<h3>[property:Boolean hasPlaybackControl]</h3>
<p>
Whether playback can be controlled using the [page:Audio.play play](),
[page:Audio.pause pause]() etc. methods. Default is `true`.
</p>
<h3>[property:Boolean isPlaying]</h3>
<p>Whether the audio is currently playing.</p>
<h3>[property:AudioListener listener]</h3>
<p>A reference to the listener object of this audio.</p>
<h3>[property:Number playbackRate]</h3>
<p>Speed of playback. Default is `1`.</p>
<h3>[property:Number offset]</h3>
<p>
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`.
</p>
<h3>[property:Number duration]</h3>
<p>
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.
</p>
<h3>[property:AudioNode source]</h3>
<p>
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]().
</p>
<h3>[property:String sourceType]</h3>
<p>Type of the audio source. Default is string 'empty'.</p>
<h3>[property:String type]</h3>
<p>String denoting the type, set to 'Audio'.</p>
<h2>Methods</h2>
<h3>[method:this connect]()</h3>
<p>
Connect to the [page:Audio.source]. This is used internally on
initialisation and when setting / removing filters.
</p>
<h3>[method:this disconnect]()</h3>
<p>
Disconnect from the [page:Audio.source]. This is used internally when
setting / removing filters.
</p>
<h3>[method:Float getDetune]()</h3>
<p>Returns the detuning of oscillation in cents.</p>
<h3>[method:BiquadFilterNode getFilter]()</h3>
<p>Returns the first element of the [page:Audio.filters filters] array.</p>
<h3>[method:Array getFilters]()</h3>
<p>Returns the [page:Audio.filters filters] array.</p>
<h3>[method:Boolean getLoop]()</h3>
<p>
Return the value of
[link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/loop source.loop] (whether playback should loop).
</p>
<h3>[method:GainNode getOutput]()</h3>
<p>Return the [page:Audio.gain gainNode].</p>
<h3>[method:Float getPlaybackRate]()</h3>
<p>Return the value of [page:Audio.playbackRate playbackRate].</p>
<h3>[method:Float getVolume]()</h3>
<p>Return the current volume.</p>
<h3>[method:this play]( delay )</h3>
<p>
delay (optional) - The delay, in seconds, at which the audio should start playing.<br />
If [page:Audio.hasPlaybackControl hasPlaybackControl] is true, starts
playback.
</p>
<h3>[method:this pause]()</h3>
<p>
If [page:Audio.hasPlaybackControl hasPlaybackControl] is true, pauses
playback.
</p>
<h3>[method:undefined onEnded]()</h3>
<p>Called automatically when playback finished.</p>
<h3>[method:this setBuffer]( audioBuffer )</h3>
<p>
Setup the [page:Audio.source source] to the audioBuffer, and sets
[page:Audio.sourceType sourceType] to 'buffer'.<br />
If [page:Audio.autoplay autoplay], also starts playback.
</p>
<h3>[method:this setDetune]( [param:Float value] )</h3>
<p>Defines the detuning of oscillation in cents.</p>
<h3>[method:this setFilter]( filter )</h3>
<p>Applies a single filter node to the audio.</p>
<h3>[method:this setFilters]( [param:Array value] )</h3>
<p>
value - arrays of filters.<br />
Applies an array of filter nodes to the audio.
</p>
<h3>[method:this setLoop]( [param:Boolean value] )</h3>
<p>
Set
[link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/loop source.loop] to `value` (whether playback should loop).
</p>
<h3>[method:this setLoopStart]( [param:Float value] )</h3>
<p>
Set
[link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/loopStart source.loopStart] to `value`.
</p>
<h3>[method:this setLoopEnd]( [param:Float value] )</h3>
<p>
Set
[link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/loopEnd source.loopEnd] to `value`.
</p>
<h3>[method:this setMediaElementSource]( mediaElement )</h3>
<p>
Applies the given object of type
[link:https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement HTMLMediaElement] as the source of this audio.<br />
Also sets [page:Audio.hasPlaybackControl hasPlaybackControl] to false.
</p>
<h3>[method:this setMediaStreamSource]( mediaStream )</h3>
<p>
Applies the given object of type
[link:https://developer.mozilla.org/en-US/docs/Web/API/MediaStream MediaStream] as the source of this audio.<br />
Also sets [page:Audio.hasPlaybackControl hasPlaybackControl] to false.
</p>
<h3>[method:this setNodeSource]( audioNode )</h3>
<p>
Setup the [page:Audio.source source] to the audioBuffer, and sets
[page:Audio.sourceType sourceType] to 'audioNode'.<br />
Also sets [page:Audio.hasPlaybackControl hasPlaybackControl] to false.
</p>
<h3>[method:this setPlaybackRate]( [param:Float value] )</h3>
<p>
If [page:Audio.hasPlaybackControl hasPlaybackControl] is enabled, set the
[page:Audio.playbackRate playbackRate] to `value`.
</p>
<h3>[method:this setVolume]( [param:Float value] )</h3>
<p>Set the volume.</p>
<h3>[method:this stop]( delay )</h3>
<p>
delay (optional) - The delay, in seconds, at which the audio should stop playing.<br />
If [page:Audio.hasPlaybackControl hasPlaybackControl] is enabled, stops
playback.
</p>
<h2>Source</h2>
<p>
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
</p>
</body>
</html>