Browse Source

Merge pull request #7592 from vincent-courtalon/dev_audio_evolution_2

cleaning up duplicate code in PositionalAudio and 'unsetting' filter
Mr.doob 9 years ago
parent
commit
00551c6a36
2 changed files with 12 additions and 57 deletions
  1. 10 6
      src/audio/Audio.js
  2. 2 51
      src/audio/PositionalAudio.js

+ 10 - 6
src/audio/Audio.js

@@ -22,12 +22,16 @@ THREE.Audio = function ( listener ) {
 	this.isPlaying = false;
 	this.hasPlaybackControl = true;
 	this.sourceType = 'empty';
+	this.filter = null;
 
 };
 
 THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
 THREE.Audio.prototype.constructor = THREE.Audio;
 
+THREE.Audio.prototype.getOutput = function() {
+	return this.gain;
+};
 
 THREE.Audio.prototype.load = function ( fileName ) {
 
@@ -131,14 +135,14 @@ THREE.Audio.prototype.stop = function () {
 
 THREE.Audio.prototype.connect = function () {
 
-	if ( this.filter !== undefined ) {
+	if ( this.filter !== null ) {
 
 		this.source.connect( this.filter );
-		this.filter.connect( this.gain );
+		this.filter.connect( this.getOutput());
 
 	} else {
 
-		this.source.connect( this.gain );
+		this.source.connect( this.getOutput());
 
 	}
 
@@ -146,14 +150,14 @@ THREE.Audio.prototype.connect = function () {
 
 THREE.Audio.prototype.disconnect = function () {
 
-	if ( this.filter !== undefined ) {
+	if ( this.filter !== null ) {
 
 		this.source.disconnect( this.filter );
-		this.filter.disconnect( this.gain );
+		this.filter.disconnect( this.getOutput());
 
 	} else {
 
-		this.source.disconnect( this.gain );
+		this.source.disconnect( this.getOutput());
 
 	}
 

+ 2 - 51
src/audio/PositionalAudio.js

@@ -14,59 +14,10 @@ THREE.PositionalAudio = function ( listener ) {
 THREE.PositionalAudio.prototype = Object.create( THREE.Audio.prototype );
 THREE.PositionalAudio.prototype.constructor = THREE.PositionalAudio;
 
-
-
-THREE.PositionalAudio.prototype.connect = function () {
-
-	if ( this.filter !== undefined ) {
-
-		this.source.connect( this.filter );
-		this.filter.connect( this.panner );
-
-	} else {
-
-		this.source.connect( this.panner );
-
-	}
-
+THREE.PositionalAudio.prototype.getOutput = function() {
+	return this.panner;
 };
 
-THREE.PositionalAudio.prototype.disconnect = function () {
-
-	if ( this.filter !== undefined ) {
-
-		this.source.disconnect( this.filter );
-		this.filter.disconnect( this.panner );
-
-	} else {
-
-		this.source.disconnect( this.panner );
-
-	}
-
-};
-
-THREE.PositionalAudio.prototype.setFilter = function ( value ) {
-
-	if ( this.isPlaying === true ) {
-
-		this.disconnect();
-		this.filter = value;
-		this.connect();
-
-	} else {
-
-		this.filter = value;
-
-	}
-
-};
-
-THREE.PositionalAudio.prototype.getFilter = function () {
-
-	return this.filter;
-
-};
 
 THREE.PositionalAudio.prototype.setRefDistance = function ( value ) {