Ver Fonte

adding back updated load function to Audio for compatibility, AudioBuffer now only take the Audio context instead of the listener at creation

vincent courtalon há 10 anos atrás
pai
commit
1ce730cd89
4 ficheiros alterados com 19 adições e 22 exclusões
  1. 5 18
      examples/misc_sound.html
  2. 10 0
      src/audio/Audio.js
  3. 2 2
      src/audio/AudioBuffer.js
  4. 2 2
      src/audio/AudioListener.js

+ 5 - 18
examples/misc_sound.html

@@ -97,9 +97,7 @@
 				scene.add( mesh1 );
 
 				var sound1 = new THREE.PositionalAudio( listener );
-				var buffer1 = new THREE.AudioBuffer( listener );
-				buffer1.load( 'sounds/358232_j_s_song.ogg' );
-				sound1.setBuffer(buffer1);
+				sound1.load( 'sounds/358232_j_s_song.ogg' );
 				sound1.setRefDistance( 20 );
 				sound1.autoplay = true;
 				mesh1.add( sound1 );
@@ -111,9 +109,7 @@
 				scene.add( mesh2 );
 
 				var sound2 = new THREE.PositionalAudio( listener );
-				var buffer2 = new THREE.AudioBuffer( listener );
-				buffer2.load( 'sounds/376737_Skullbeatz___Bad_Cat_Maste.ogg' );
-				sound2.setBuffer(buffer2);
+				sound2.load( 'sounds/376737_Skullbeatz___Bad_Cat_Maste.ogg' );
 				sound2.setRefDistance( 20 );
 				sound2.autoplay = true;
 				mesh2.add( sound2 );
@@ -133,22 +129,13 @@
 				sound3.setVolume(0.5);
 				mesh3.add(sound3);
 				
-		/*		buffer2.load( 'sounds/376737_Skullbeatz___Bad_Cat_Maste.ogg' );
-				sound2.setBuffer(buffer2);
-				sound2.setRefDistance( 20 );
-				sound2.autoplay = true;
-				mesh2.add( sound2 );
-		*/		
-
 				// global ambient audio
 	
 				var sound4 = new THREE.Audio( listener );
-				var buffer3 = new THREE.AudioBuffer( listener );
-				buffer3.load( 'sounds/Project_Utopia.ogg' );
-				sound4.setBuffer(buffer3);
+				sound4.load( 'sounds/Project_Utopia.ogg' );
 				sound4.autoplay = true;
 				sound4.setLoop(true);
-				sound3.setVolume(0.5);
+				sound4.setVolume(0.5);
 				
 				// ground
 
@@ -252,7 +239,7 @@
 
 				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.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);
 
 				renderer.render( scene, camera );
 

+ 10 - 0
src/audio/Audio.js

@@ -29,6 +29,16 @@ THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
 THREE.Audio.prototype.constructor = THREE.Audio;
 
 
+THREE.Audio.prototype.load = function ( fileName ) {
+
+	var audioBuffer = new THREE.AudioBuffer(this.context);
+	audioBuffer.load(fileName);
+	this.setBuffer(audioBuffer);
+	return this;
+
+};
+
+
 THREE.Audio.prototype.setNodeSource = function ( audioNode ) {
 
 	this.hasPlaybackControl = false;

+ 2 - 2
src/audio/AudioBuffer.js

@@ -2,9 +2,9 @@
  * @author mrdoob / http://mrdoob.com/
  */
 
-THREE.AudioBuffer = function ( listener ) {
+THREE.AudioBuffer = function ( context ) {
 
-	this.context = listener.context;
+	this.context = context;
 	this.ready = false;
 	this.readyCallbacks = [];
 

+ 2 - 2
src/audio/AudioListener.js

@@ -26,7 +26,7 @@ THREE.AudioListener.prototype.getOutputNode = function () {
 
 THREE.AudioListener.prototype.removeFilter = function ( ) {
 	
-	if (this.filter !== null && this.filter !== undefined) {
+	if (this.filter !== null) {
 	
 		this.masterGain.disconnect(this.filter);
 		this.filter.disconnect(this.context.destination);
@@ -39,7 +39,7 @@ THREE.AudioListener.prototype.removeFilter = function ( ) {
 
 THREE.AudioListener.prototype.setFilter = function ( value ) {
 
-	if (this.filter !== null && this.filter !== undefined) {
+	if (this.filter !== null) {
 		
 		this.masterGain.disconnect(this.filter);
 		this.filter.disconnect(this.context.destination);