提交 48096824 编写于 作者: M Mr.doob

Added AudioAnalyser.

上级 9d64683c
......@@ -61,6 +61,8 @@
var mesh;
var material_sphere1, material_sphere2;
var analyser1, analyser2, analyser3;
var clock = new THREE.Clock();
init();
......@@ -114,6 +116,8 @@
sound2.autoplay = true;
mesh2.add( sound2 );
//
var mesh3 = new THREE.Mesh( sphere, material_sphere3 );
mesh3.position.set( 0, 30, -250 );
......@@ -129,6 +133,12 @@
sound3.setVolume(0.5);
mesh3.add(sound3);
// analysers
analyser1 = new THREE.AudioAnalyser( sound1, 32 );
analyser2 = new THREE.AudioAnalyser( sound2, 32 );
analyser3 = new THREE.AudioAnalyser( sound3, 32 );
// global ambient audio
var sound4 = new THREE.Audio( listener );
......@@ -237,9 +247,9 @@
controls.update( delta );
material_sphere1.color.setHSL( 0.0, 0.3 + 0.7 * ( 1 + Math.cos( time ) ) / 2, 0.5 );
material_sphere2.color.setHSL( 0.1, 0.3 + 0.7 * ( 1 + Math.sin( time ) ) / 2, 0.5 );
material_sphere3.color.setHSL( 0.1, 0.5, 0.3 + 0.7 * ( 1 + Math.sin( time ) ) / 2);
material_sphere1.emissive.b = ( analyser1.getData()[ 8 ] / 256 );
material_sphere2.emissive.b = ( analyser2.getData()[ 8 ] / 256 );
material_sphere3.emissive.b = ( analyser3.getData()[ 8 ] / 256 );
renderer.render( scene, camera );
......
/**
* @author mrdoob / http://mrdoob.com/
*/
THREE.AudioAnalyser = function ( audio, fftSize ) {
this.analyser = audio.context.createAnalyser();
this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
this.data = new Uint8Array( this.analyser.frequencyBinCount );
audio.getOutput().connect( this.analyser );
};
THREE.AudioAnalyser.prototype = {
constructor: THREE.AudioAnalyser,
getData: function () {
this.analyser.getByteFrequencyData( this.data );
return this.data;
}
};
......@@ -53,6 +53,7 @@
"src/animation/tracks/StringKeyframeTrack.js",
"src/animation/tracks/VectorKeyframeTrack.js",
"src/audio/Audio.js",
"src/audio/AudioAnalyser.js",
"src/audio/AudioBuffer.js",
"src/audio/PositionalAudio.js",
"src/audio/AudioListener.js",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册