|
@@ -10,7 +10,7 @@ THREE.Audio = function ( listener ) {
|
|
|
|
|
|
this.context = listener.context;
|
|
|
this.source = this.context.createBufferSource();
|
|
|
- this.source.onended = this.onEnded.bind(this);
|
|
|
+ this.source.onended = this.onEnded.bind( this );
|
|
|
|
|
|
this.gain = this.context.createGain();
|
|
|
this.gain.connect( this.context.destination );
|
|
@@ -21,6 +21,7 @@ THREE.Audio = function ( listener ) {
|
|
|
this.autoplay = false;
|
|
|
|
|
|
this.startTime = 0;
|
|
|
+ this.playbackRate = 1;
|
|
|
this.isPlaying = false;
|
|
|
|
|
|
};
|
|
@@ -41,7 +42,7 @@ THREE.Audio.prototype.load = function ( file ) {
|
|
|
|
|
|
scope.source.buffer = buffer;
|
|
|
|
|
|
- if( scope.autoplay ) scope.play();
|
|
|
+ if ( scope.autoplay ) scope.play();
|
|
|
|
|
|
} );
|
|
|
|
|
@@ -66,12 +67,14 @@ THREE.Audio.prototype.play = function () {
|
|
|
source.buffer = this.source.buffer;
|
|
|
source.loop = this.source.loop;
|
|
|
source.onended = this.source.onended;
|
|
|
- source.connect( this.panner );
|
|
|
source.start( 0, this.startTime );
|
|
|
-
|
|
|
+ source.playbackRate.value = this.playbackRate;
|
|
|
+
|
|
|
this.isPlaying = true;
|
|
|
|
|
|
this.source = source;
|
|
|
+
|
|
|
+ this.connect();
|
|
|
|
|
|
};
|
|
|
|
|
@@ -89,6 +92,72 @@ THREE.Audio.prototype.stop = function () {
|
|
|
|
|
|
};
|
|
|
|
|
|
+THREE.Audio.prototype.connect = function () {
|
|
|
+
|
|
|
+ if ( this.filter !== undefined ) {
|
|
|
+
|
|
|
+ this.source.connect( this.filter );
|
|
|
+ this.filter.connect( this.panner );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ this.source.connect( this.panner );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
+THREE.Audio.prototype.disconnect = function () {
|
|
|
+
|
|
|
+ if ( this.filter !== undefined ) {
|
|
|
+
|
|
|
+ this.source.disconnect( this.filter );
|
|
|
+ this.filter.disconnect( this.panner );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ this.source.disconnect( this.panner );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
+THREE.Audio.prototype.setFilter = function ( value ) {
|
|
|
+
|
|
|
+ if (this.isPlaying) {
|
|
|
+
|
|
|
+ this.disconnect();
|
|
|
+ this.filter = value;
|
|
|
+ this.connect();
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ this.filter = value;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
+THREE.Audio.prototype.getFilter = function () {
|
|
|
+
|
|
|
+ return this.filter;
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
+THREE.Audio.prototype.setPlaybackRate = function ( value ) {
|
|
|
+
|
|
|
+ this.playbackRate = value;
|
|
|
+
|
|
|
+ if (this.isPlaying) source.playbackRate.value = this.playbackRate;
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
+THREE.Audio.prototype.getPlaybackRate = function () {
|
|
|
+
|
|
|
+ return this.playbackRate;
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
THREE.Audio.prototype.onEnded = function() {
|
|
|
|
|
|
this.isPlaying = false;
|
|
@@ -101,24 +170,48 @@ THREE.Audio.prototype.setLoop = function ( value ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
+THREE.Audio.prototype.getLoop = function () {
|
|
|
+
|
|
|
+ return this.source.loop;
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
THREE.Audio.prototype.setRefDistance = function ( value ) {
|
|
|
|
|
|
this.panner.refDistance = value;
|
|
|
|
|
|
};
|
|
|
|
|
|
+THREE.Audio.prototype.getRefDistance = function () {
|
|
|
+
|
|
|
+ return this.panner.refDistance;
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
THREE.Audio.prototype.setRolloffFactor = function ( value ) {
|
|
|
|
|
|
this.panner.rolloffFactor = value;
|
|
|
|
|
|
};
|
|
|
|
|
|
+THREE.Audio.prototype.getRolloffFactor = function () {
|
|
|
+
|
|
|
+ return this.panner.rolloffFactor;
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
THREE.Audio.prototype.setVolume = function ( value ) {
|
|
|
|
|
|
this.gain.gain.value = value;
|
|
|
|
|
|
};
|
|
|
|
|
|
+THREE.Audio.prototype.getVolume = function () {
|
|
|
+
|
|
|
+ return this.gain.gain.value;
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
THREE.Audio.prototype.updateMatrixWorld = ( function () {
|
|
|
|
|
|
var position = new THREE.Vector3();
|
|
@@ -133,4 +226,4 @@ THREE.Audio.prototype.updateMatrixWorld = ( function () {
|
|
|
|
|
|
};
|
|
|
|
|
|
-} )();
|
|
|
+} )();
|