File: Audio.html

package info (click to toggle)
three.js 111%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 15,184 kB
  • sloc: javascript: 133,174; makefile: 24; sh: 1
file content (238 lines) | stat: -rw-r--r-- 8,017 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<base href="../../../" />
		<script src="list.js"></script>
		<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>Example</h2>

		<p>
			[example:webaudio_sandbox webaudio / sandbox ]<br />
			[example:webaudio_visualizer webaudio / visualizer ]
		</p>

		<code>
		// create an AudioListener and add it to the camera
		var listener = new THREE.AudioListener();
		camera.add( listener );

		// create a global audio source
		var sound = new THREE.Audio( listener );

		// load a sound and set it as the Audio object's buffer
		var 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>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/BiquadFilterNode BiquadFilterNodes]. Can be used to apply a variety of low-order filters to create more complex sound effects. 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:String 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:Audio connect]()</h3>
		<p>
		Connect to the [page:Audio.source]. This is used internally on initialisation and when
		setting / removing filters.
		</p>

		<h3>[method:Audio disconnect]()</h3>
		<p>
		Disconnect from the [page:Audio.source]. This is used internally when
		setting / removing filters.
		</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]( value )</h3>
		<p>
		Return the current volume.
		</p>

		<h3>[method:Audio play]( delay )</h3>
		<p>
		If [page:Audio.hasPlaybackControl hasPlaybackControl] is true, starts playback.
		</p>

		<h3>[method:Audio pause]()</h3>
		<p>
		If [page:Audio.hasPlaybackControl hasPlaybackControl] is true, pauses playback.
		</p>

		<h3>[method:null onEnded]()</h3>
		<p>
		Called automatically when playback finished.
		</p>

		<h3>[method:Audio 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:Audio setFilter]( filter )</h3>
		<p>
		Applies a single [link:https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode BiquadFilterNode] to the audio.
		</p>

		<h3>[method:Audio setFilters]( [param:Array value] )</h3>
		<p>
		value - arrays of filters.<br />
		Applies an array of [link:https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode BiquadFilterNodes] to the audio.
		</p>

		<h3>[method:Audio 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:Audio 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:Audio 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:Audio 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:Audio 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:Audio 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:Audio setPlaybackRate]( [param:Float value] )</h3>
		<p>
		If [page:Audio.hasPlaybackControl hasPlaybackControl] is enabled, set the [page:Audio.playbackRate playbackRate] to *value*.
		</p>

		<h3>[method:Audio setVolume]( [param:Float value] )</h3>
		<p>
		Set the volume.
		</p>

		<h3>[method:Audio stop]()</h3>
		<p>
		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>