mirror of
https://github.com/scratchfoundation/scratch-audio.git
synced 2024-12-22 05:53:43 -05:00
use AudioEngine.currentTime and DECAY_WAIT in PanEffect, etc
This commit is contained in:
parent
ee73fd7a8a
commit
e01a32a83d
3 changed files with 9 additions and 15 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue