AudioAnalyser.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. <h1>[name]</h1>
  11. <p class="desc">
  12. Create a AudioAnalyser object, which uses an
  13. [link:https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode AnalyserNode] to analyse audio data.<br /><br />
  14. This uses the
  15. [link:https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API Web Audio API].
  16. </p>
  17. <h2>Code Example</h2>
  18. <code>
  19. // create an AudioListener and add it to the camera
  20. const listener = new THREE.AudioListener();
  21. camera.add( listener );
  22. // create an 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. // create an AudioAnalyser, passing in the sound and desired fftSize
  33. const analyser = new THREE.AudioAnalyser( sound, 32 );
  34. // get the average frequency of the sound
  35. const data = analyser.getAverageFrequency();
  36. </code>
  37. <h2>Examples</h2>
  38. <p>
  39. [example:webaudio_sandbox webaudio / sandbox ]<br />
  40. [example:webaudio_visualizer webaudio / visualizer ]
  41. </p>
  42. <h2>Constructor</h2>
  43. <h3>[name]( audio, [link:https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/fftSize fftSize] )</h3>
  44. <p>Create a new [page:AudioAnalyser AudioAnalyser].</p>
  45. <h2>Properties</h2>
  46. <h3>[property:AnalyserNode analyser]</h3>
  47. <p>
  48. An [link:https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode AnalyserNode] used to analyze audio.
  49. </p>
  50. <h3>[property:Integer fftSize]</h3>
  51. <p>
  52. A non-zero power of two up to 2048, representing the size of the FFT (Fast
  53. Fourier Transform) to be used to determine the frequency domain. See
  54. [link:https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/fftSize this page] for details.
  55. </p>
  56. <h3>[property:Uint8Array data]</h3>
  57. <p>
  58. A Uint8Array with size determined by
  59. [link:https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/frequencyBinCount analyser.frequencyBinCount] used to hold analysis data.
  60. </p>
  61. <h2>Methods</h2>
  62. <h3>[method:Uint8Array getFrequencyData]()</h3>
  63. <p>
  64. Uses the Web Audio's
  65. [link:https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/getByteFrequencyData getByteFrequencyData] method. See that page.
  66. </p>
  67. <h3>[method:Number getAverageFrequency]()</h3>
  68. <p>
  69. Get the average of the frequencies returned by the
  70. [page:AudioAnalyser.getFrequencyData getFrequencyData] method.
  71. </p>
  72. <h2>Source</h2>
  73. <p>
  74. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  75. </p>
  76. </body>
  77. </html>