Audio.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. [page:Object3D] &rarr;
  12. <h1>[name]</h1>
  13. <p class="desc">
  14. Create a non-positional ( global ) audio object.<br /><br />
  15. This uses the [link:https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API Web Audio API].
  16. </p>
  17. <h2>Example</h2>
  18. <p>
  19. [example:webaudio_sandbox webaudio / sandbox ]<br />
  20. [example:webaudio_visualizer webaudio / visualizer ]
  21. </p>
  22. <code>
  23. // create an AudioListener and add it to the camera
  24. var listener = new THREE.AudioListener();
  25. camera.add( listener );
  26. // create a global audio source
  27. var sound = new THREE.Audio( listener );
  28. // load a sound and set it as the Audio object's buffer
  29. var audioLoader = new THREE.AudioLoader();
  30. audioLoader.load( 'sounds/ambient.ogg', function( buffer ) {
  31. sound.setBuffer( buffer );
  32. sound.setLoop( true );
  33. sound.setVolume( 0.5 );
  34. sound.play();
  35. });
  36. </code>
  37. <h2>Constructor</h2>
  38. <h3>[name]( [param:AudioListener listener] )</h3>
  39. <p>
  40. listener — (required) [page:AudioListener AudioListener] instance.
  41. </p>
  42. <h2>Properties</h2>
  43. <h3>[property:Boolean autoplay]</h3>
  44. <p>Whether to start playback automatically. Default is *false*.</p>
  45. <h3>[property:AudioContext context]</h3>
  46. <p>The [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioContext AudioContext] of the [page:AudioListener listener] given in the constructor.</p>
  47. <h3>[property:Number detune]</h3>
  48. <p>Modify pitch, measured in cents. +/- 100 is a semitone. +/- 1200 is an octave. Default is *0*.</p>
  49. <h3>[property:Array filters]</h3>
  50. <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>
  51. <h3>[property:GainNode gain]</h3>
  52. <p>A [link:https://developer.mozilla.org/en-US/docs/Web/API/GainNode GainNode] created
  53. using [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createGain AudioContext.createGain]().</p>
  54. <h3>[property:Boolean hasPlaybackControl]</h3>
  55. <p>Whether playback can be controlled using the [page:Audio.play play](),
  56. [page:Audio.pause pause]() etc. methods. Default is *true*.</p>
  57. <h3>[property:Boolean isPlaying]</h3>
  58. <p>Whether the audio is currently playing.</p>
  59. <h3>[property:AudioListener listener]</h3>
  60. <p>A reference to the listener object of this audio.</p>
  61. <h3>[property:Number playbackRate]</h3>
  62. <p>Speed of playback. Default is *1*.</p>
  63. <h3>[property:Number startTime]</h3>
  64. <p>The time at which the sound should begin to play. Same as the *when* paramter of [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/start AudioBufferSourceNode.start](). Default is *0*.</p>
  65. <h3>[property:Number offset]</h3>
  66. <p>An offset to the time within the audio buffer that playback should begin. Same as the *offset* paramter of [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/start AudioBufferSourceNode.start](). Default is *0*.</p>
  67. <h3>[property:Number duration]</h3>
  68. <p>Overrides the duration of the audio. Same as the *duration* paramter of [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/start AudioBufferSourceNode.start](). Default is *undefined* to play the whole buffer.</p>
  69. <h3>[property:String source]</h3>
  70. <p>An [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode AudioBufferSourceNode] created
  71. using [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createBufferSource AudioContext.createBufferSource]().</p>
  72. <h3>[property:String sourceType]</h3>
  73. <p>Type of the audio source. Default is string 'empty'.</p>
  74. <h3>[property:String type]</h3>
  75. <p>String denoting the type, set to 'Audio'.</p>
  76. <h2>Methods</h2>
  77. <h3>[method:Audio connect]()</h3>
  78. <p>
  79. Connect to the [page:Audio.source]. This is used internally on initialisation and when
  80. setting / removing filters.
  81. </p>
  82. <h3>[method:Audio disconnect]()</h3>
  83. <p>
  84. Disconnect from the [page:Audio.source]. This is used internally when
  85. setting / removing filters.
  86. </p>
  87. <h3>[method:BiquadFilterNode getFilter]()</h3>
  88. <p>
  89. Returns the first element of the [page:Audio.filters filters] array.
  90. </p>
  91. <h3>[method:Array getFilters]()</h3>
  92. <p>
  93. Returns the [page:Audio.filters filters] array.
  94. </p>
  95. <h3>[method:Boolean getLoop]()</h3>
  96. <p>
  97. Return the value of [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/loop source.loop]
  98. (whether playback should loop).
  99. </p>
  100. <h3>[method:GainNode getOutput]()</h3>
  101. <p>
  102. Return the [page:Audio.gain gainNode].
  103. </p>
  104. <h3>[method:Float getPlaybackRate]()</h3>
  105. <p>
  106. Return the value of [page:Audio.playbackRate playbackRate].
  107. </p>
  108. <h3>[method:Float getVolume]( value )</h3>
  109. <p>
  110. Return the current volume.
  111. </p>
  112. <h3>[method:Audio play]()</h3>
  113. <p>
  114. If [page:Audio.hasPlaybackControl hasPlaybackControl] is true, starts playback.
  115. </p>
  116. <h3>[method:Audio pause]()</h3>
  117. <p>
  118. If [page:Audio.hasPlaybackControl hasPlaybackControl] is true, pauses playback.
  119. </p>
  120. <h3>[method:null onEnded]()</h3>
  121. <p>
  122. Called automatically when playback finished. Sets If [page:Audio.isPlaying isPlaying] to false.
  123. </p>
  124. <h3>[method:Audio setBuffer]( audioBuffer )</h3>
  125. <p>
  126. Setup the [page:Audio.source source] to the audioBuffer, and sets [page:Audio.sourceType sourceType] to 'buffer'.<br />
  127. If [page:Audio.autoplay autoplay], also starts playback.
  128. </p>
  129. <h3>[method:Audio setFilter]( filter )</h3>
  130. <p>
  131. Applies a single [link:https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode BiquadFilterNode] to the audio.
  132. </p>
  133. <h3>[method:Audio setFilters]( [param:Array value] )</h3>
  134. <p>
  135. value - arrays of filters.<br />
  136. Applies an array of [link:https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode BiquadFilterNodes] to the audio.
  137. </p>
  138. <h3>[method:Audio setLoop]( [param:Boolean value] )</h3>
  139. <p>
  140. Set [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/loop source.loop] to *value*
  141. (whether playback should loop).
  142. </p>
  143. <h3>[method:Audio setMediaElementSource]( mediaElement )</h3>
  144. <p>
  145. 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 />
  146. Also sets [page:Audio.hasPlaybackControl hasPlaybackControl] to false.
  147. </p>
  148. <h3>[method:Audio setNodeSource]( audioNode )</h3>
  149. <p>
  150. Setup the [page:Audio.source source] to the audioBuffer, and sets [page:Audio.sourceType sourceType] to 'audioNode'.<br />
  151. Also sets [page:Audio.hasPlaybackControl hasPlaybackControl] to false.
  152. </p>
  153. <h3>[method:Audio setPlaybackRate]( [param:Float value] )</h3>
  154. <p>
  155. If [page:Audio.hasPlaybackControl hasPlaybackControl] is enabled, set the [page:Audio.playbackRate playbackRate] to *value*.
  156. </p>
  157. <h3>[method:Audio setVolume]( [param:Float value] )</h3>
  158. <p>
  159. Set the volume.
  160. </p>
  161. <h3>[method:Audio stop]()</h3>
  162. <p>
  163. If [page:Audio.hasPlaybackControl hasPlaybackControl] is enabled, stops playback,
  164. resets [page:Audio.startTime startTime] to *0* and sets [page:Audio.isPlaying isPlaying] to false.
  165. </p>
  166. <h2>Source</h2>
  167. <p>
  168. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  169. </p>
  170. </body>
  171. </html>