AudioAnalyser.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>AudioAnalyser - 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. <h1 translate="no">AudioAnalyser</h1>
  13. <section>
  14. <header>
  15. <div class="class-description"><p>This class can be used to analyse audio data.</p></div>
  16. <h2>Code Example</h2>
  17. <div translate="no"><pre><code class="language-js">// create an AudioListener and add it to the camera
  18. const listener = new THREE.AudioListener();
  19. camera.add( listener );
  20. // create an Audio source
  21. const sound = new THREE.Audio( listener );
  22. // load a sound and set it as the Audio object's buffer
  23. const audioLoader = new THREE.AudioLoader();
  24. audioLoader.load( 'sounds/ambient.ogg', function( buffer ) {
  25. sound.setBuffer( buffer );
  26. sound.setLoop(true);
  27. sound.setVolume(0.5);
  28. sound.play();
  29. });
  30. // create an AudioAnalyser, passing in the sound and desired fftSize
  31. const analyser = new THREE.AudioAnalyser( sound, 32 );
  32. // get the average frequency of the sound
  33. const data = analyser.getAverageFrequency();
  34. </code></pre></div>
  35. </header>
  36. <article>
  37. <div class="container-overview">
  38. <h2>Constructor</h2>
  39. <h3 class="name name-method" id="AudioAnalyser" translate="no">new <a href="#AudioAnalyser">AudioAnalyser</a><span class="signature">( audio : <span class="param-type">Audio</span>, fftSize : <span class="param-type">number</span> )</span> </h3>
  40. <div class="method">
  41. <div class="description">
  42. <p>Constructs a new audio analyzer.</p>
  43. </div>
  44. <table class="params">
  45. <tbody>
  46. <tr>
  47. <td class="name"><code>audio</code></td>
  48. <td class="description last"><p>The audio to analyze.</p></td>
  49. </tr>
  50. <tr>
  51. <td class="name"><code>fftSize</code></td>
  52. <td class="description last"><p>The window size in samples that is used when performing a Fast Fourier Transform (FFT) to get frequency domain data.<br/>Default is <code>2048</code>.</p></td>
  53. </tr>
  54. </tbody>
  55. </table>
  56. </div>
  57. </div>
  58. <h2 class="subsection-title">Properties</h2>
  59. <div class="member">
  60. <h3 class="name" id="analyser" translate="no">.<a href="#analyser">analyser</a><span class="type-signature"> : AnalyserNode</span> </h3>
  61. <div class="description">
  62. <p>The global audio listener.</p>
  63. </div>
  64. </div>
  65. <div class="member">
  66. <h3 class="name" id="data" translate="no">.<a href="#data">data</a><span class="type-signature"> : Uint8Array</span> </h3>
  67. <div class="description">
  68. <p>Holds the analyzed data.</p>
  69. </div>
  70. </div>
  71. <h2 class="subsection-title">Methods</h2>
  72. <h3 class="name name-method" id="getAverageFrequency" translate="no">.<a href="#getAverageFrequency">getAverageFrequency</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  73. <div class="method">
  74. <div class="description">
  75. <p>Returns the average of the frequencies returned by <a href="AudioAnalyser.html#getFrequencyData">AudioAnalyser#getFrequencyData</a>.</p>
  76. </div>
  77. <dl class="details">
  78. <dt class="tag-returns"><strong>Returns:</strong> The average frequency.</dt>
  79. </dl>
  80. </div>
  81. <h3 class="name name-method" id="getFrequencyData" translate="no">.<a href="#getFrequencyData">getFrequencyData</a><span class="signature">()</span><span class="type-signature"> : Uint8Array</span> </h3>
  82. <div class="method">
  83. <div class="description">
  84. <p>Returns an array with frequency data of the audio.</p>
  85. <p>Each item in the array represents the decibel value for a specific frequency.
  86. The frequencies are spread linearly from 0 to 1/2 of the sample rate.
  87. For example, for 48000 sample rate, the last item of the array will represent
  88. the decibel value for 24000 Hz.</p>
  89. </div>
  90. <dl class="details">
  91. <dt class="tag-returns"><strong>Returns:</strong> The frequency data.</dt>
  92. </dl>
  93. </div>
  94. <h2 class="subsection-title">Source</h2>
  95. <p>
  96. <a href="https://github.com/mrdoob/three.js/blob/master/src/audio/AudioAnalyser.js" target="_blank" rel="noopener" translate="no">src/audio/AudioAnalyser.js</a>
  97. </p>
  98. </article>
  99. </section>
  100. <script src="../scripts/linenumber.js"></script>
  101. <script src="../scripts/page.js"></script>
  102. </body>
  103. </html>
粤ICP备19079148号