You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.7 KiB

2 years ago
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8" />
<base href="../../../" />
<script src="page.js"></script>
<link type="text/css" rel="stylesheet" href="page.css" />
</head>
<body>
<h1>[name]</h1>
<p class="desc">
创建AudioAnalyser对象, 使用[link:https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode AnalyserNode]
去分析音频数据.<br /><br />
使用了 [link:https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API Web Audio API].
</p>
<h2>代码示例</h2>
<code>
// create an AudioListener and add it to the camera
const listener = new THREE.AudioListener();
camera.add( listener );
// create an Audio source
const sound = new THREE.Audio( listener );
// load a sound and set it as the Audio object's buffer
const audioLoader = new THREE.AudioLoader();
audioLoader.load( 'sounds/ambient.ogg', function( buffer ) {
sound.setBuffer( buffer );
sound.setLoop(true);
sound.setVolume(0.5);
sound.play();
});
// create an AudioAnalyser, passing in the sound and desired fftSize
const analyser = new THREE.AudioAnalyser( sound, 32 );
// get the average frequency of the sound
const data = analyser.getAverageFrequency();
</code>
<h2>例子</h2>
<p>
[example:webaudio_sandbox webaudio / sandbox ]<br />
[example:webaudio_visualizer webaudio / visualizer ]
</p>
<h2>构造函数</h2>
<h3>[name]( audio, [link:https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/fftSize fftSize] )</h3>
<p>
创建[page:AudioAnalyser AudioAnalyser].
</p>
<h2>属性</h2>
<h3>[property:AnalyserNode analyser]</h3>
<p>[link:https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode AnalyserNode]用来分析音频数据.</p>
<h3>[property:Integer fftSize]</h3>
<p>
2的幂次方最高为2048, 用来表示确定频域的FFT (傅立叶变换)大小.
这个[link:https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/fftSize page]有详细信息.
</p>
<h3>[property:Uint8Array data]</h3>
<p>
用来分析数据的Uint8Array的大小由[link:https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/frequencyBinCount analyser.frequencyBinCount]
确定.
</p>
<h2>方法</h2>
<h3>[method:Uint8Array getFrequencyData]()</h3>
<p>
使用网络音频的[link:https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/getByteFrequencyData getByteFrequencyData] 方法.
看这个页面.
</p>
<h3>[method:Number getAverageFrequency]()</h3>
<p>
通过方法[page:AudioAnalyser.getFrequencyData getFrequencyData]获取平均频率.
</p>
<h2>源码</h2>
<p>
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
</p>
</body>
</html>