AudioAnalyser.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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"><a href="Audio.html">Audio</a></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">
  48. <strong>audio</strong>
  49. </td>
  50. <td class="description last">
  51. <p>The audio to analyze.</p>
  52. </td>
  53. </tr>
  54. <tr>
  55. <td class="name">
  56. <strong>fftSize</strong>
  57. </td>
  58. <td class="description last">
  59. <p>The window size in samples that is used when performing a Fast Fourier Transform (FFT) to get frequency domain data.</p>
  60. <p>Default is <code>2048</code>.</p>
  61. </td>
  62. </tr>
  63. </tbody>
  64. </table>
  65. </div>
  66. </div>
  67. <h2 class="subsection-title">Properties</h2>
  68. <div class="member">
  69. <h3 class="name" id="analyser" translate="no">.<a href="#analyser">analyser</a><span class="type-signature"> : AnalyserNode</span> </h3>
  70. <div class="description">
  71. <p>The global audio listener.</p>
  72. </div>
  73. </div>
  74. <div class="member">
  75. <h3 class="name" id="data" translate="no">.<a href="#data">data</a><span class="type-signature"> : Uint8Array</span> </h3>
  76. <div class="description">
  77. <p>Holds the analyzed data.</p>
  78. </div>
  79. </div>
  80. <h2 class="subsection-title">Methods</h2>
  81. <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>
  82. <div class="method">
  83. <div class="description">
  84. <p>Returns the average of the frequencies returned by <a href="AudioAnalyser.html#getFrequencyData">AudioAnalyser#getFrequencyData</a>.</p>
  85. </div>
  86. <dl class="details">
  87. <dt class="tag-returns"><strong>Returns:</strong> The average frequency.</dt>
  88. </dl>
  89. </div>
  90. <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>
  91. <div class="method">
  92. <div class="description">
  93. <p>Returns an array with frequency data of the audio.</p>
  94. <p>Each item in the array represents the decibel value for a specific frequency.
  95. The frequencies are spread linearly from 0 to 1/2 of the sample rate.
  96. For example, for 48000 sample rate, the last item of the array will represent
  97. the decibel value for 24000 Hz.</p>
  98. </div>
  99. <dl class="details">
  100. <dt class="tag-returns"><strong>Returns:</strong> The frequency data.</dt>
  101. </dl>
  102. </div>
  103. <h2 class="subsection-title">Source</h2>
  104. <p>
  105. <a href="https://github.com/mrdoob/three.js/blob/master/src/audio/AudioAnalyser.js" translate="no" target="_blank" rel="noopener">src/audio/AudioAnalyser.js</a>
  106. </p>
  107. </article>
  108. </section>
  109. <script src="../scripts/linenumber.js"></script>
  110. <script src="../scripts/page.js"></script>
  111. </body>
  112. </html>
粤ICP备19079148号