Audio.html 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Audio - Three.js Docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <script src="../scripts/highlight.min.js"></script>
  8. <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
  9. <link type="text/css" rel="stylesheet" href="../styles/page.css">
  10. </head>
  11. <body>
  12. <p class="inheritance" translate="no"><a href="EventDispatcher.html">EventDispatcher</a> → <a href="Object3D.html">Object3D</a> → </p>
  13. <h1 translate="no">Audio</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>Represents a non-positional ( global ) audio object.</p>
  17. <p>This and related audio modules make use of the <a href="https://www.w3.org/TR/webaudio-1.1/">Web Audio API</a>.</p></div>
  18. <h2>Code Example</h2>
  19. <div translate="no"><pre><code class="language-js">// create an AudioListener and add it to the camera
  20. const listener = new THREE.AudioListener();
  21. camera.add( listener );
  22. // create a global audio source
  23. const sound = new THREE.Audio( listener );
  24. // load a sound and set it as the Audio object's buffer
  25. const audioLoader = new THREE.AudioLoader();
  26. audioLoader.load( 'sounds/ambient.ogg', function( buffer ) {
  27. sound.setBuffer( buffer );
  28. sound.setLoop( true );
  29. sound.setVolume( 0.5 );
  30. sound.play();
  31. });
  32. </code></pre></div>
  33. </header>
  34. <article>
  35. <div class="container-overview">
  36. <h2>Constructor</h2>
  37. <h3 class="name name-method" id="Audio" translate="no">new <a href="#Audio">Audio</a><span class="signature">( listener : <span class="param-type">AudioListener</span> )</span> </h3>
  38. <div class="method">
  39. <div class="description">
  40. <p>Constructs a new audio.</p>
  41. </div>
  42. <table class="params">
  43. <tbody>
  44. <tr>
  45. <td class="name"><code>listener</code></td>
  46. <td class="description last"><p>The global audio listener.</p></td>
  47. </tr>
  48. </tbody>
  49. </table>
  50. </div>
  51. </div>
  52. <h2 class="subsection-title">Properties</h2>
  53. <div class="member">
  54. <h3 class="name" id="autoplay" translate="no">.<a href="#autoplay">autoplay</a><span class="type-signature"> : boolean</span> </h3>
  55. <div class="description">
  56. <p>Whether to start playback automatically or not.<br/>Default is <code>false</code>.</p>
  57. </div>
  58. </div>
  59. <div class="member">
  60. <h3 class="name" id="buffer" translate="no">.<a href="#buffer">buffer</a><span class="type-signature"> : AudioBuffer</span> <span class="type-signature">(readonly) </span></h3>
  61. <div class="description">
  62. <p>A reference to an audio buffer.</p>
  63. <p>Defined via <a href="Audio.html#setBuffer">Audio#setBuffer</a>.<br/>Default is <code>null</code>.</p>
  64. </div>
  65. </div>
  66. <div class="member">
  67. <h3 class="name" id="context" translate="no">.<a href="#context">context</a><span class="type-signature"> : <a href="AudioContext.html">AudioContext</a></span> <span class="type-signature">(readonly) </span></h3>
  68. <div class="description">
  69. <p>The audio context.</p>
  70. </div>
  71. </div>
  72. <div class="member">
  73. <h3 class="name" id="detune" translate="no">.<a href="#detune">detune</a><span class="type-signature"> : number</span> <span class="type-signature">(readonly) </span></h3>
  74. <div class="description">
  75. <p>Modify pitch, measured in cents. +/- 100 is a semitone.
  76. +/- 1200 is an octave.</p>
  77. <p>Defined via <a href="Audio.html#setDetune">Audio#setDetune</a>.<br/>Default is <code>0</code>.</p>
  78. </div>
  79. </div>
  80. <div class="member">
  81. <h3 class="name" id="duration" translate="no">.<a href="#duration">duration</a><span class="type-signature"> : undefined | number</span> </h3>
  82. <div class="description">
  83. <p>Overrides the default duration of the audio.<br/>Default is <code>undefined</code>.</p>
  84. </div>
  85. </div>
  86. <div class="member">
  87. <h3 class="name" id="filters" translate="no">.<a href="#filters">filters</a><span class="type-signature"> : Array.&lt;AudioNode></span> <span class="type-signature">(readonly) </span></h3>
  88. <div class="description">
  89. <p>Can be used to apply a variety of low-order filters to create
  90. more complex sound effects e.g. via <code>BiquadFilterNode</code>.</p>
  91. <p>The property is automatically set by <a href="Audio.html#setFilters">Audio#setFilters</a>.</p>
  92. </div>
  93. </div>
  94. <div class="member">
  95. <h3 class="name" id="gain" translate="no">.<a href="#gain">gain</a><span class="type-signature"> : GainNode</span> <span class="type-signature">(readonly) </span></h3>
  96. <div class="description">
  97. <p>The gain node used for volume control.</p>
  98. </div>
  99. </div>
  100. <div class="member">
  101. <h3 class="name" id="hasPlaybackControl" translate="no">.<a href="#hasPlaybackControl">hasPlaybackControl</a><span class="type-signature"> : boolean</span> <span class="type-signature">(readonly) </span></h3>
  102. <div class="description">
  103. <p>Indicates whether the audio playback can be controlled
  104. with method like <a href="Audio.html#play">Audio#play</a> or <a href="Audio.html#pause">Audio#pause</a>.</p>
  105. <p>This flag will be automatically set when audio sources are
  106. defined.<br/>Default is <code>true</code>.</p>
  107. </div>
  108. </div>
  109. <div class="member">
  110. <h3 class="name" id="isPlaying" translate="no">.<a href="#isPlaying">isPlaying</a><span class="type-signature"> : boolean</span> <span class="type-signature">(readonly) </span></h3>
  111. <div class="description">
  112. <p>Indicates whether the audio is playing or not.</p>
  113. <p>This flag will be automatically set when using <a href="Audio.html#play">Audio#play</a>,
  114. <a href="Audio.html#pause">Audio#pause</a>, <a href="Audio.html#stop">Audio#stop</a>.<br/>Default is <code>false</code>.</p>
  115. </div>
  116. </div>
  117. <div class="member">
  118. <h3 class="name" id="listener" translate="no">.<a href="#listener">listener</a><span class="type-signature"> : <a href="AudioListener.html">AudioListener</a></span> <span class="type-signature">(readonly) </span></h3>
  119. <div class="description">
  120. <p>The global audio listener.</p>
  121. </div>
  122. </div>
  123. <div class="member">
  124. <h3 class="name" id="loop" translate="no">.<a href="#loop">loop</a><span class="type-signature"> : boolean</span> <span class="type-signature">(readonly) </span></h3>
  125. <div class="description">
  126. <p>Whether the audio should loop or not.</p>
  127. <p>Defined via <a href="Audio.html#setLoop">Audio#setLoop</a>.<br/>Default is <code>false</code>.</p>
  128. </div>
  129. </div>
  130. <div class="member">
  131. <h3 class="name" id="loopEnd" translate="no">.<a href="#loopEnd">loopEnd</a><span class="type-signature"> : number</span> </h3>
  132. <div class="description">
  133. <p>Defines where in the audio buffer the replay should
  134. stop, in seconds.<br/>Default is <code>0</code>.</p>
  135. </div>
  136. </div>
  137. <div class="member">
  138. <h3 class="name" id="loopStart" translate="no">.<a href="#loopStart">loopStart</a><span class="type-signature"> : number</span> </h3>
  139. <div class="description">
  140. <p>Defines where in the audio buffer the replay should
  141. start, in seconds.<br/>Default is <code>0</code>.</p>
  142. </div>
  143. </div>
  144. <div class="member">
  145. <h3 class="name" id="offset" translate="no">.<a href="#offset">offset</a><span class="type-signature"> : number</span> </h3>
  146. <div class="description">
  147. <p>An offset to the time within the audio buffer the playback
  148. should begin, in seconds.<br/>Default is <code>0</code>.</p>
  149. </div>
  150. </div>
  151. <div class="member">
  152. <h3 class="name" id="playbackRate" translate="no">.<a href="#playbackRate">playbackRate</a><span class="type-signature"> : number</span> <span class="type-signature">(readonly) </span></h3>
  153. <div class="description">
  154. <p>The playback speed.</p>
  155. <p>Defined via <a href="Audio.html#setPlaybackRate">Audio#setPlaybackRate</a>.<br/>Default is <code>1</code>.</p>
  156. </div>
  157. </div>
  158. <div class="member">
  159. <h3 class="name" id="source" translate="no">.<a href="#source">source</a><span class="type-signature"> : AudioNode</span> <span class="type-signature">(readonly) </span></h3>
  160. <div class="description">
  161. <p>Holds a reference to the current audio source.</p>
  162. <p>The property is automatically by one of the <code>set*()</code> methods.<br/>Default is <code>null</code>.</p>
  163. </div>
  164. </div>
  165. <div class="member">
  166. <h3 class="name" id="sourceType" translate="no">.<a href="#sourceType">sourceType</a><span class="type-signature"> : 'empty' | 'audioNode' | 'mediaNode' | 'mediaStreamNode' | 'buffer'</span> <span class="type-signature">(readonly) </span></h3>
  167. <div class="description">
  168. <p>Defines the source type.</p>
  169. <p>The property is automatically by one of the <code>set*()</code> methods.<br/>Default is <code>'empty'</code>.</p>
  170. </div>
  171. </div>
  172. <h2 class="subsection-title">Methods</h2>
  173. <h3 class="name name-method" id="connect" translate="no">.<a href="#connect">connect</a><span class="signature">()</span><span class="type-signature"> : <a href="Audio.html">Audio</a></span> </h3>
  174. <div class="method">
  175. <div class="description">
  176. <p>Connects to the audio source. This is used internally on
  177. initialisation and when setting / removing filters.</p>
  178. </div>
  179. <dl class="details">
  180. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  181. </dl>
  182. </div>
  183. <h3 class="name name-method" id="disconnect" translate="no">.<a href="#disconnect">disconnect</a><span class="signature">()</span><span class="type-signature"> : <a href="Audio.html">Audio</a> | undefined</span> </h3>
  184. <div class="method">
  185. <div class="description">
  186. <p>Disconnects to the audio source. This is used internally on
  187. initialisation and when setting / removing filters.</p>
  188. </div>
  189. <dl class="details">
  190. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  191. </dl>
  192. </div>
  193. <h3 class="name name-method" id="getDetune" translate="no">.<a href="#getDetune">getDetune</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  194. <div class="method">
  195. <div class="description">
  196. <p>Returns the detuning of oscillation in cents.</p>
  197. </div>
  198. <dl class="details">
  199. <dt class="tag-returns"><strong>Returns:</strong> The detuning of oscillation in cents.</dt>
  200. </dl>
  201. </div>
  202. <h3 class="name name-method" id="getFilter" translate="no">.<a href="#getFilter">getFilter</a><span class="signature">()</span><span class="type-signature"> : AudioNode | undefined</span> </h3>
  203. <div class="method">
  204. <div class="description">
  205. <p>Returns the first filter in the list of filters.</p>
  206. </div>
  207. <dl class="details">
  208. <dt class="tag-returns"><strong>Returns:</strong> The first filter in the list of filters.</dt>
  209. </dl>
  210. </div>
  211. <h3 class="name name-method" id="getFilters" translate="no">.<a href="#getFilters">getFilters</a><span class="signature">()</span><span class="type-signature"> : Array.&lt;AudioNode></span> </h3>
  212. <div class="method">
  213. <div class="description">
  214. <p>Returns the current set filters.</p>
  215. </div>
  216. <dl class="details">
  217. <dt class="tag-returns"><strong>Returns:</strong> The list of filters.</dt>
  218. </dl>
  219. </div>
  220. <h3 class="name name-method" id="getLoop" translate="no">.<a href="#getLoop">getLoop</a><span class="signature">()</span><span class="type-signature"> : boolean</span> </h3>
  221. <div class="method">
  222. <div class="description">
  223. <p>Returns the loop flag.</p>
  224. <p>Can only be used with compatible audio sources that allow playback control.</p>
  225. </div>
  226. <dl class="details">
  227. <dt class="tag-returns"><strong>Returns:</strong> Whether the audio should loop or not.</dt>
  228. </dl>
  229. </div>
  230. <h3 class="name name-method" id="getOutput" translate="no">.<a href="#getOutput">getOutput</a><span class="signature">()</span><span class="type-signature"> : GainNode</span> </h3>
  231. <div class="method">
  232. <div class="description">
  233. <p>Returns the output audio node.</p>
  234. </div>
  235. <dl class="details">
  236. <dt class="tag-returns"><strong>Returns:</strong> The output node.</dt>
  237. </dl>
  238. </div>
  239. <h3 class="name name-method" id="getPlaybackRate" translate="no">.<a href="#getPlaybackRate">getPlaybackRate</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  240. <div class="method">
  241. <div class="description">
  242. <p>Returns the current playback rate.</p>
  243. </div>
  244. <dl class="details">
  245. <dt class="tag-returns"><strong>Returns:</strong> The playback rate.</dt>
  246. </dl>
  247. </div>
  248. <h3 class="name name-method" id="getVolume" translate="no">.<a href="#getVolume">getVolume</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  249. <div class="method">
  250. <div class="description">
  251. <p>Returns the volume.</p>
  252. </div>
  253. <dl class="details">
  254. <dt class="tag-returns"><strong>Returns:</strong> The volume.</dt>
  255. </dl>
  256. </div>
  257. <h3 class="name name-method" id="onEnded" translate="no">.<a href="#onEnded">onEnded</a><span class="signature">()</span> </h3>
  258. <div class="method">
  259. <div class="description">
  260. <p>Automatically called when playback finished.</p>
  261. </div>
  262. </div>
  263. <h3 class="name name-method" id="pause" translate="no">.<a href="#pause">pause</a><span class="signature">()</span><span class="type-signature"> : <a href="Audio.html">Audio</a> | undefined</span> </h3>
  264. <div class="method">
  265. <div class="description">
  266. <p>Pauses the playback of the audio.</p>
  267. <p>Can only be used with compatible audio sources that allow playback control.</p>
  268. </div>
  269. <dl class="details">
  270. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  271. </dl>
  272. </div>
  273. <h3 class="name name-method" id="play" translate="no">.<a href="#play">play</a><span class="signature">( delay : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a> | undefined</span> </h3>
  274. <div class="method">
  275. <div class="description">
  276. <p>Starts the playback of the audio.</p>
  277. <p>Can only be used with compatible audio sources that allow playback control.</p>
  278. </div>
  279. <table class="params">
  280. <tbody>
  281. <tr>
  282. <td class="name"><code>delay</code></td>
  283. <td class="description last"><p>The delay, in seconds, at which the audio should start playing.<br/>Default is <code>0</code>.</p></td>
  284. </tr>
  285. </tbody>
  286. </table>
  287. <dl class="details">
  288. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  289. </dl>
  290. </div>
  291. <h3 class="name name-method" id="setBuffer" translate="no">.<a href="#setBuffer">setBuffer</a><span class="signature">( audioBuffer : <span class="param-type">AudioBuffer</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a></span> </h3>
  292. <div class="method">
  293. <div class="description">
  294. <p>Sets the given audio buffer as the source of this instance.</p>
  295. <p><a href="Audio.html#sourceType">Audio#sourceType</a> is set to <code>buffer</code> and <a href="Audio.html#hasPlaybackControl">Audio#hasPlaybackControl</a> to <code>true</code>.</p>
  296. </div>
  297. <table class="params">
  298. <tbody>
  299. <tr>
  300. <td class="name"><code>audioBuffer</code></td>
  301. <td class="description last"><p>The audio buffer.</p></td>
  302. </tr>
  303. </tbody>
  304. </table>
  305. <dl class="details">
  306. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  307. </dl>
  308. </div>
  309. <h3 class="name name-method" id="setDetune" translate="no">.<a href="#setDetune">setDetune</a><span class="signature">( value : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a></span> </h3>
  310. <div class="method">
  311. <div class="description">
  312. <p>Defines the detuning of oscillation in cents.</p>
  313. </div>
  314. <table class="params">
  315. <tbody>
  316. <tr>
  317. <td class="name"><code>value</code></td>
  318. <td class="description last"><p>The detuning of oscillation in cents.</p></td>
  319. </tr>
  320. </tbody>
  321. </table>
  322. <dl class="details">
  323. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  324. </dl>
  325. </div>
  326. <h3 class="name name-method" id="setFilter" translate="no">.<a href="#setFilter">setFilter</a><span class="signature">( filter : <span class="param-type">AudioNode</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a></span> </h3>
  327. <div class="method">
  328. <div class="description">
  329. <p>Applies a single filter node to the audio.</p>
  330. </div>
  331. <table class="params">
  332. <tbody>
  333. <tr>
  334. <td class="name"><code>filter</code></td>
  335. <td class="description last"><p>The filter to set.</p></td>
  336. </tr>
  337. </tbody>
  338. </table>
  339. <dl class="details">
  340. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  341. </dl>
  342. </div>
  343. <h3 class="name name-method" id="setFilters" translate="no">.<a href="#setFilters">setFilters</a><span class="signature">( value : <span class="param-type">Array.&lt;AudioNode></span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a></span> </h3>
  344. <div class="method">
  345. <div class="description">
  346. <p>Sets an array of filters and connects them with the audio source.</p>
  347. </div>
  348. <table class="params">
  349. <tbody>
  350. <tr>
  351. <td class="name"><code>value</code></td>
  352. <td class="description last"><p>A list of filters.</p></td>
  353. </tr>
  354. </tbody>
  355. </table>
  356. <dl class="details">
  357. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  358. </dl>
  359. </div>
  360. <h3 class="name name-method" id="setLoop" translate="no">.<a href="#setLoop">setLoop</a><span class="signature">( value : <span class="param-type">boolean</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a> | undefined</span> </h3>
  361. <div class="method">
  362. <div class="description">
  363. <p>Sets the loop flag.</p>
  364. <p>Can only be used with compatible audio sources that allow playback control.</p>
  365. </div>
  366. <table class="params">
  367. <tbody>
  368. <tr>
  369. <td class="name"><code>value</code></td>
  370. <td class="description last"><p>Whether the audio should loop or not.</p></td>
  371. </tr>
  372. </tbody>
  373. </table>
  374. <dl class="details">
  375. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  376. </dl>
  377. </div>
  378. <h3 class="name name-method" id="setLoopEnd" translate="no">.<a href="#setLoopEnd">setLoopEnd</a><span class="signature">( value : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a></span> </h3>
  379. <div class="method">
  380. <div class="description">
  381. <p>Sets the loop end value which defines where in the audio buffer the replay should
  382. stop, in seconds.</p>
  383. </div>
  384. <table class="params">
  385. <tbody>
  386. <tr>
  387. <td class="name"><code>value</code></td>
  388. <td class="description last"><p>The loop end value.</p></td>
  389. </tr>
  390. </tbody>
  391. </table>
  392. <dl class="details">
  393. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  394. </dl>
  395. </div>
  396. <h3 class="name name-method" id="setLoopStart" translate="no">.<a href="#setLoopStart">setLoopStart</a><span class="signature">( value : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a></span> </h3>
  397. <div class="method">
  398. <div class="description">
  399. <p>Sets the loop start value which defines where in the audio buffer the replay should
  400. start, in seconds.</p>
  401. </div>
  402. <table class="params">
  403. <tbody>
  404. <tr>
  405. <td class="name"><code>value</code></td>
  406. <td class="description last"><p>The loop start value.</p></td>
  407. </tr>
  408. </tbody>
  409. </table>
  410. <dl class="details">
  411. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  412. </dl>
  413. </div>
  414. <h3 class="name name-method" id="setMediaElementSource" translate="no">.<a href="#setMediaElementSource">setMediaElementSource</a><span class="signature">( mediaElement : <span class="param-type">HTMLMediaElement</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a></span> </h3>
  415. <div class="method">
  416. <div class="description">
  417. <p>Sets the given media element as the source of this instance.</p>
  418. <p><a href="Audio.html#sourceType">Audio#sourceType</a> is set to <code>mediaNode</code> and <a href="Audio.html#hasPlaybackControl">Audio#hasPlaybackControl</a> to <code>false</code>.</p>
  419. </div>
  420. <table class="params">
  421. <tbody>
  422. <tr>
  423. <td class="name"><code>mediaElement</code></td>
  424. <td class="description last"><p>The media element.</p></td>
  425. </tr>
  426. </tbody>
  427. </table>
  428. <dl class="details">
  429. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  430. </dl>
  431. </div>
  432. <h3 class="name name-method" id="setMediaStreamSource" translate="no">.<a href="#setMediaStreamSource">setMediaStreamSource</a><span class="signature">( mediaStream : <span class="param-type">MediaStream</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a></span> </h3>
  433. <div class="method">
  434. <div class="description">
  435. <p>Sets the given media stream as the source of this instance.</p>
  436. <p><a href="Audio.html#sourceType">Audio#sourceType</a> is set to <code>mediaStreamNode</code> and <a href="Audio.html#hasPlaybackControl">Audio#hasPlaybackControl</a> to <code>false</code>.</p>
  437. </div>
  438. <table class="params">
  439. <tbody>
  440. <tr>
  441. <td class="name"><code>mediaStream</code></td>
  442. <td class="description last"><p>The media stream.</p></td>
  443. </tr>
  444. </tbody>
  445. </table>
  446. <dl class="details">
  447. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  448. </dl>
  449. </div>
  450. <h3 class="name name-method" id="setNodeSource" translate="no">.<a href="#setNodeSource">setNodeSource</a><span class="signature">( audioNode : <span class="param-type">AudioNode</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a></span> </h3>
  451. <div class="method">
  452. <div class="description">
  453. <p>Sets the given audio node as the source of this instance.</p>
  454. <p><a href="Audio.html#sourceType">Audio#sourceType</a> is set to <code>audioNode</code> and <a href="Audio.html#hasPlaybackControl">Audio#hasPlaybackControl</a> to <code>false</code>.</p>
  455. </div>
  456. <table class="params">
  457. <tbody>
  458. <tr>
  459. <td class="name"><code>audioNode</code></td>
  460. <td class="description last"><p>The audio node like an instance of <code>OscillatorNode</code>.</p></td>
  461. </tr>
  462. </tbody>
  463. </table>
  464. <dl class="details">
  465. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  466. </dl>
  467. </div>
  468. <h3 class="name name-method" id="setPlaybackRate" translate="no">.<a href="#setPlaybackRate">setPlaybackRate</a><span class="signature">( value : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a> | undefined</span> </h3>
  469. <div class="method">
  470. <div class="description">
  471. <p>Sets the playback rate.</p>
  472. <p>Can only be used with compatible audio sources that allow playback control.</p>
  473. </div>
  474. <table class="params">
  475. <tbody>
  476. <tr>
  477. <td class="name"><code>value</code></td>
  478. <td class="description last"><p>The playback rate to set.</p></td>
  479. </tr>
  480. </tbody>
  481. </table>
  482. <dl class="details">
  483. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  484. </dl>
  485. </div>
  486. <h3 class="name name-method" id="setVolume" translate="no">.<a href="#setVolume">setVolume</a><span class="signature">( value : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a></span> </h3>
  487. <div class="method">
  488. <div class="description">
  489. <p>Sets the volume.</p>
  490. </div>
  491. <table class="params">
  492. <tbody>
  493. <tr>
  494. <td class="name"><code>value</code></td>
  495. <td class="description last"><p>The volume to set.</p></td>
  496. </tr>
  497. </tbody>
  498. </table>
  499. <dl class="details">
  500. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  501. </dl>
  502. </div>
  503. <h3 class="name name-method" id="stop" translate="no">.<a href="#stop">stop</a><span class="signature">( delay : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a> | undefined</span> </h3>
  504. <div class="method">
  505. <div class="description">
  506. <p>Stops the playback of the audio.</p>
  507. <p>Can only be used with compatible audio sources that allow playback control.</p>
  508. </div>
  509. <table class="params">
  510. <tbody>
  511. <tr>
  512. <td class="name"><code>delay</code></td>
  513. <td class="description last"><p>The delay, in seconds, at which the audio should stop playing.<br/>Default is <code>0</code>.</p></td>
  514. </tr>
  515. </tbody>
  516. </table>
  517. <dl class="details">
  518. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  519. </dl>
  520. </div>
  521. <h2 class="subsection-title">Source</h2>
  522. <p>
  523. <a href="https://github.com/mrdoob/three.js/blob/master/src/audio/Audio.js" target="_blank" rel="noopener" translate="no">src/audio/Audio.js</a>
  524. </p>
  525. </article>
  526. </section>
  527. <script src="../scripts/linenumber.js"></script>
  528. <script src="../scripts/page.js"></script>
  529. </body>
  530. </html>
粤ICP备19079148号