mirror of
https://github.com/scratchfoundation/scratch-audio.git
synced 2024-12-22 05:53:43 -05:00
rename DECAY_* constants to DECAY_WAIT and DECAY_DURATION
This commit is contained in:
parent
fb355abb7d
commit
ee73fd7a8a
6 changed files with 20 additions and 20 deletions
|
@ -109,7 +109,7 @@ class AudioEngine {
|
|||
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/AudioParam/setTargetAtTime}
|
||||
* @const {number}
|
||||
*/
|
||||
get DECAY_TIME () {
|
||||
get DECAY_DURATION () {
|
||||
return 0.025;
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ class AudioEngine {
|
|||
* @see {@link https://bugzilla.mozilla.org/show_bug.cgi?id=1228207}
|
||||
* @const {number}
|
||||
*/
|
||||
get DECAY_SOON () {
|
||||
get DECAY_WAIT () {
|
||||
return 0.05;
|
||||
}
|
||||
|
||||
|
|
|
@ -219,7 +219,7 @@ class SoundPlayer extends EventEmitter {
|
|||
|
||||
this.isPlaying = true;
|
||||
|
||||
this.startingUntil = this.audioEngine.audioContext.currentTime + this.audioEngine.DECAY_TIME;
|
||||
this.startingUntil = this.audioEngine.audioContext.currentTime + this.audioEngine.DECAY_DURATION;
|
||||
|
||||
this.emit('play');
|
||||
}
|
||||
|
@ -245,8 +245,8 @@ class SoundPlayer extends EventEmitter {
|
|||
taken.finished().then(() => taken.dispose());
|
||||
|
||||
taken.volumeEffect.set(0);
|
||||
const {audioContext, DECAY_TIME, DECAY_SOON} = this.audioEngine;
|
||||
taken.outputNode.stop(audioContext.currentTime + DECAY_SOON + DECAY_TIME);
|
||||
const {audioContext, DECAY_DURATION, DECAY_WAIT} = this.audioEngine;
|
||||
taken.outputNode.stop(audioContext.currentTime + DECAY_WAIT + DECAY_DURATION);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -144,7 +144,7 @@ class Effect {
|
|||
this.outputNode.disconnect();
|
||||
}
|
||||
|
||||
if (this._isPatch || this._lastPatch + this.audioEngine.DECAY_TIME < this.audioEngine.currentTime) {
|
||||
if (this._isPatch || this._lastPatch + this.audioEngine.DECAY_DURATION < this.audioEngine.currentTime) {
|
||||
this.outputNode.connect(target.getInputNode());
|
||||
}
|
||||
|
||||
|
|
|
@ -65,12 +65,12 @@ class PanEffect extends Effect {
|
|||
this.leftGain.gain.setTargetAtTime(
|
||||
leftVal,
|
||||
this.audioEngine.audioContext.currentTime,
|
||||
this.audioEngine.DECAY_TIME
|
||||
this.audioEngine.DECAY_DURATION
|
||||
);
|
||||
this.rightGain.gain.setTargetAtTime(
|
||||
rightVal,
|
||||
this.audioEngine.audioContext.currentTime,
|
||||
this.audioEngine.DECAY_TIME
|
||||
this.audioEngine.DECAY_DURATION
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,9 +38,9 @@ class VolumeEffect extends Effect {
|
|||
this.value = value;
|
||||
|
||||
const {gain} = this.outputNode;
|
||||
const {audioContext: {currentTime}, DECAY_TIME, DECAY_SOON} = this.audioEngine;
|
||||
gain.setValueAtTime(gain.value, currentTime + DECAY_SOON);
|
||||
gain.linearRampToValueAtTime(value / 100, currentTime + DECAY_SOON + DECAY_TIME);
|
||||
const {audioContext: {currentTime}, DECAY_DURATION, DECAY_WAIT} = this.audioEngine;
|
||||
gain.setValueAtTime(gain.value, currentTime + DECAY_WAIT);
|
||||
gain.linearRampToValueAtTime(value / 100, currentTime + DECAY_WAIT + DECAY_DURATION);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -88,13 +88,13 @@ tap.test('SoundPlayer', suite => {
|
|||
inputs: [outputNode.toJSON()]
|
||||
}], 'output node connects to gain node to input node');
|
||||
|
||||
audioContext.$processTo(audioEngine.DECAY_SOON + audioEngine.DECAY_TIME / 2);
|
||||
audioContext.$processTo(audioEngine.DECAY_WAIT + audioEngine.DECAY_DURATION / 2);
|
||||
const engineInputs = help.engineInputs;
|
||||
t.notEqual(engineInputs[0].gain.value, 1, 'gain value should not be 1');
|
||||
t.notEqual(engineInputs[0].gain.value, 0, 'gain value should not be 0');
|
||||
t.equal(outputNode.$state, 'PLAYING');
|
||||
|
||||
audioContext.$processTo(audioEngine.DECAY_SOON + audioEngine.DECAY_TIME + 0.001);
|
||||
audioContext.$processTo(audioEngine.DECAY_WAIT + audioEngine.DECAY_DURATION + 0.001);
|
||||
t.deepEqual(help.engineInputs, [{
|
||||
name: 'GainNode',
|
||||
gain: {
|
||||
|
@ -129,14 +129,14 @@ tap.test('SoundPlayer', suite => {
|
|||
t.deepEqual(log, ['finished first', 'finished second', 'finished third'], 'finished in order');
|
||||
|
||||
// fast forward to one ms before decay time
|
||||
audioContext.$processTo(audioEngine.DECAY_TIME - 0.001);
|
||||
audioContext.$processTo(audioEngine.DECAY_DURATION - 0.001);
|
||||
soundPlayer.play();
|
||||
|
||||
t.equal(originalNode, soundPlayer.outputNode, 'same output node');
|
||||
|
||||
|
||||
// now at DECAY_TIME, we should meet a new player as the old one is taken/stopped
|
||||
audioContext.$processTo(audioEngine.DECAY_TIME);
|
||||
// now at DECAY_DURATION, we should meet a new player as the old one is taken/stopped
|
||||
audioContext.$processTo(audioEngine.DECAY_DURATION);
|
||||
|
||||
t.equal(soundPlayer.isStarting, false, 'player.isStarting now false');
|
||||
|
||||
|
@ -157,7 +157,7 @@ tap.test('SoundPlayer', suite => {
|
|||
const firstPlayNode = soundPlayer.outputNode;
|
||||
|
||||
// go past debounce time and play again
|
||||
audioContext.$processTo(audioEngine.DECAY_TIME);
|
||||
audioContext.$processTo(audioEngine.DECAY_DURATION);
|
||||
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
|
@ -181,18 +181,18 @@ tap.test('SoundPlayer', suite => {
|
|||
t.equal(help.engineInputs[0].gain.value, 1, 'old sound connectect to gain node with volume 1');
|
||||
|
||||
const {currentTime} = audioContext;
|
||||
audioContext.$processTo(currentTime + audioEngine.DECAY_SOON + 0.001);
|
||||
audioContext.$processTo(currentTime + audioEngine.DECAY_WAIT + 0.001);
|
||||
t.notEqual(help.engineInputs[0].gain.value, 1,
|
||||
'old sound connected to gain node which will fade');
|
||||
|
||||
audioContext.$processTo(currentTime + audioEngine.DECAY_SOON + audioEngine.DECAY_TIME + 0.001);
|
||||
audioContext.$processTo(currentTime + audioEngine.DECAY_WAIT + audioEngine.DECAY_DURATION + 0.001);
|
||||
t.equal(soundPlayer.outputNode.$state, 'PLAYING');
|
||||
t.equal(firstPlayNode.$state, 'FINISHED');
|
||||
|
||||
t.equal(help.engineInputs[0].gain.value, 0, 'faded old sound to 0');
|
||||
|
||||
t.equal(log.length, 1);
|
||||
audioContext.$processTo(currentTime + audioEngine.DECAY_SOON + audioEngine.DECAY_TIME + 0.3);
|
||||
audioContext.$processTo(currentTime + audioEngine.DECAY_WAIT + audioEngine.DECAY_DURATION + 0.3);
|
||||
|
||||
// wait for a micro-task loop to fire our previous events
|
||||
return Promise.resolve();
|
||||
|
|
Loading…
Reference in a new issue