use AudioEngine.currentTime and DECAY_WAIT in PanEffect, etc

This commit is contained in:
Michael "Z" Goddard 2018-06-25 14:27:21 -04:00
parent ee73fd7a8a
commit e01a32a83d
No known key found for this signature in database
GPG key ID: 762CD40DD5349872
3 changed files with 9 additions and 15 deletions

View file

@ -46,7 +46,7 @@ class SoundPlayer extends EventEmitter {
* @type {boolean}
*/
get isStarting () {
return this.isPlaying && this.startingUntil > this.audioEngine.audioContext.currentTime;
return this.isPlaying && this.startingUntil > this.audioEngine.currentTime;
}
/**
@ -219,7 +219,8 @@ class SoundPlayer extends EventEmitter {
this.isPlaying = true;
this.startingUntil = this.audioEngine.audioContext.currentTime + this.audioEngine.DECAY_DURATION;
const {currentTime, DECAY_DURATION} = this.audioEngine;
this.startingUntil = currentTime + DECAY_DURATION;
this.emit('play');
}
@ -245,8 +246,8 @@ class SoundPlayer extends EventEmitter {
taken.finished().then(() => taken.dispose());
taken.volumeEffect.set(0);
const {audioContext, DECAY_DURATION, DECAY_WAIT} = this.audioEngine;
taken.outputNode.stop(audioContext.currentTime + DECAY_WAIT + DECAY_DURATION);
const {currentTime, DECAY_WAIT, DECAY_DURATION} = this.audioEngine;
taken.outputNode.stop(currentTime + DECAY_WAIT + DECAY_DURATION);
}
/**

View file

@ -62,16 +62,9 @@ class PanEffect extends Effect {
const leftVal = Math.cos(p * Math.PI / 2);
const rightVal = Math.sin(p * Math.PI / 2);
this.leftGain.gain.setTargetAtTime(
leftVal,
this.audioEngine.audioContext.currentTime,
this.audioEngine.DECAY_DURATION
);
this.rightGain.gain.setTargetAtTime(
rightVal,
this.audioEngine.audioContext.currentTime,
this.audioEngine.DECAY_DURATION
);
const {currentTime, DECAY_WAIT, DECAY_DURATION} = this.audioEngine;
this.leftGain.gain.setTargetAtTime(leftVal, currentTime + DECAY_WAIT, DECAY_DURATION);
this.rightGain.gain.setTargetAtTime(rightVal, currentTime + DECAY_WAIT, DECAY_DURATION);
}
/**

View file

@ -38,7 +38,7 @@ class VolumeEffect extends Effect {
this.value = value;
const {gain} = this.outputNode;
const {audioContext: {currentTime}, DECAY_DURATION, DECAY_WAIT} = this.audioEngine;
const {currentTime, DECAY_WAIT, DECAY_DURATION} = this.audioEngine;
gain.setValueAtTime(gain.value, currentTime + DECAY_WAIT);
gain.linearRampToValueAtTime(value / 100, currentTime + DECAY_WAIT + DECAY_DURATION);
}