|
@@ -1,49 +1,47 @@
|
|
|
import { Object3D } from '../core/Object3D.js';
|
|
|
|
|
|
-function Audio( listener ) {
|
|
|
+class Audio extends Object3D {
|
|
|
|
|
|
- Object3D.call( this );
|
|
|
+ constructor( listener ) {
|
|
|
|
|
|
- this.type = 'Audio';
|
|
|
+ super();
|
|
|
|
|
|
- this.listener = listener;
|
|
|
- this.context = listener.context;
|
|
|
+ this.type = 'Audio';
|
|
|
|
|
|
- this.gain = this.context.createGain();
|
|
|
- this.gain.connect( listener.getInput() );
|
|
|
+ this.listener = listener;
|
|
|
+ this.context = listener.context;
|
|
|
|
|
|
- this.autoplay = false;
|
|
|
+ this.gain = this.context.createGain();
|
|
|
+ this.gain.connect( listener.getInput() );
|
|
|
|
|
|
- this.buffer = null;
|
|
|
- this.detune = 0;
|
|
|
- this.loop = false;
|
|
|
- this.loopStart = 0;
|
|
|
- this.loopEnd = 0;
|
|
|
- this.offset = 0;
|
|
|
- this.duration = undefined;
|
|
|
- this.playbackRate = 1;
|
|
|
- this.isPlaying = false;
|
|
|
- this.hasPlaybackControl = true;
|
|
|
- this.sourceType = 'empty';
|
|
|
+ this.autoplay = false;
|
|
|
|
|
|
- this._startedAt = 0;
|
|
|
- this._progress = 0;
|
|
|
-
|
|
|
- this.filters = [];
|
|
|
+ this.buffer = null;
|
|
|
+ this.detune = 0;
|
|
|
+ this.loop = false;
|
|
|
+ this.loopStart = 0;
|
|
|
+ this.loopEnd = 0;
|
|
|
+ this.offset = 0;
|
|
|
+ this.duration = undefined;
|
|
|
+ this.playbackRate = 1;
|
|
|
+ this.isPlaying = false;
|
|
|
+ this.hasPlaybackControl = true;
|
|
|
+ this.sourceType = 'empty';
|
|
|
|
|
|
-}
|
|
|
+ this._startedAt = 0;
|
|
|
+ this._progress = 0;
|
|
|
|
|
|
-Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
|
|
|
+ this.filters = [];
|
|
|
|
|
|
- constructor: Audio,
|
|
|
+ }
|
|
|
|
|
|
- getOutput: function () {
|
|
|
+ getOutput() {
|
|
|
|
|
|
return this.gain;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setNodeSource: function ( audioNode ) {
|
|
|
+ setNodeSource( audioNode ) {
|
|
|
|
|
|
this.hasPlaybackControl = false;
|
|
|
this.sourceType = 'audioNode';
|
|
@@ -52,9 +50,9 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setMediaElementSource: function ( mediaElement ) {
|
|
|
+ setMediaElementSource( mediaElement ) {
|
|
|
|
|
|
this.hasPlaybackControl = false;
|
|
|
this.sourceType = 'mediaNode';
|
|
@@ -63,9 +61,9 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setMediaStreamSource: function ( mediaStream ) {
|
|
|
+ setMediaStreamSource( mediaStream ) {
|
|
|
|
|
|
this.hasPlaybackControl = false;
|
|
|
this.sourceType = 'mediaStreamNode';
|
|
@@ -74,9 +72,9 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setBuffer: function ( audioBuffer ) {
|
|
|
+ setBuffer( audioBuffer ) {
|
|
|
|
|
|
this.buffer = audioBuffer;
|
|
|
this.sourceType = 'buffer';
|
|
@@ -85,9 +83,9 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- play: function ( delay ) {
|
|
|
+ play( delay ) {
|
|
|
|
|
|
if ( delay === undefined ) delay = 0;
|
|
|
|
|
@@ -124,9 +122,9 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
|
|
|
|
|
|
return this.connect();
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- pause: function () {
|
|
|
+ pause() {
|
|
|
|
|
|
if ( this.hasPlaybackControl === false ) {
|
|
|
|
|
@@ -158,9 +156,9 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- stop: function () {
|
|
|
+ stop() {
|
|
|
|
|
|
if ( this.hasPlaybackControl === false ) {
|
|
|
|
|
@@ -177,9 +175,9 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- connect: function () {
|
|
|
+ connect() {
|
|
|
|
|
|
if ( this.filters.length > 0 ) {
|
|
|
|
|
@@ -201,9 +199,9 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- disconnect: function () {
|
|
|
+ disconnect() {
|
|
|
|
|
|
if ( this.filters.length > 0 ) {
|
|
|
|
|
@@ -225,15 +223,15 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- getFilters: function () {
|
|
|
+ getFilters() {
|
|
|
|
|
|
return this.filters;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setFilters: function ( value ) {
|
|
|
+ setFilters( value ) {
|
|
|
|
|
|
if ( ! value ) value = [];
|
|
|
|
|
@@ -251,9 +249,9 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setDetune: function ( value ) {
|
|
|
+ setDetune( value ) {
|
|
|
|
|
|
this.detune = value;
|
|
|
|
|
@@ -267,27 +265,27 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- getDetune: function () {
|
|
|
+ getDetune() {
|
|
|
|
|
|
return this.detune;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- getFilter: function () {
|
|
|
+ getFilter() {
|
|
|
|
|
|
return this.getFilters()[ 0 ];
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setFilter: function ( filter ) {
|
|
|
+ setFilter( filter ) {
|
|
|
|
|
|
return this.setFilters( filter ? [ filter ] : [] );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setPlaybackRate: function ( value ) {
|
|
|
+ setPlaybackRate( value ) {
|
|
|
|
|
|
if ( this.hasPlaybackControl === false ) {
|
|
|
|
|
@@ -306,21 +304,21 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- getPlaybackRate: function () {
|
|
|
+ getPlaybackRate() {
|
|
|
|
|
|
return this.playbackRate;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- onEnded: function () {
|
|
|
+ onEnded() {
|
|
|
|
|
|
this.isPlaying = false;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- getLoop: function () {
|
|
|
+ getLoop() {
|
|
|
|
|
|
if ( this.hasPlaybackControl === false ) {
|
|
|
|
|
@@ -331,9 +329,9 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
|
|
|
|
|
|
return this.loop;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setLoop: function ( value ) {
|
|
|
+ setLoop( value ) {
|
|
|
|
|
|
if ( this.hasPlaybackControl === false ) {
|
|
|
|
|
@@ -352,31 +350,31 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setLoopStart: function ( value ) {
|
|
|
+ setLoopStart( value ) {
|
|
|
|
|
|
this.loopStart = value;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setLoopEnd: function ( value ) {
|
|
|
+ setLoopEnd( value ) {
|
|
|
|
|
|
this.loopEnd = value;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- getVolume: function () {
|
|
|
+ getVolume() {
|
|
|
|
|
|
return this.gain.gain.value;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setVolume: function ( value ) {
|
|
|
+ setVolume( value ) {
|
|
|
|
|
|
this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
|
|
|
|
|
@@ -384,6 +382,6 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
|
|
|
|
|
|
}
|
|
|
|
|
|
-} );
|
|
|
+}
|
|
|
|
|
|
export { Audio };
|