mirror of
https://github.com/scratchfoundation/scratch-audio.git
synced 2025-07-02 23:00:24 -04:00
Merge pull request #118 from adroitwhiz/fix-volume-stutter
Don't setValueAtTime in volume effect
This commit is contained in:
commit
b279a63e70
3 changed files with 7 additions and 11 deletions
|
@ -299,8 +299,8 @@ class SoundPlayer extends EventEmitter {
|
||||||
taken.finished().then(() => taken.dispose());
|
taken.finished().then(() => taken.dispose());
|
||||||
|
|
||||||
taken.volumeEffect.set(0);
|
taken.volumeEffect.set(0);
|
||||||
const {currentTime, DECAY_WAIT, DECAY_DURATION} = this.audioEngine;
|
const {currentTime, DECAY_DURATION} = this.audioEngine;
|
||||||
taken.outputNode.stop(currentTime + DECAY_WAIT + DECAY_DURATION);
|
taken.outputNode.stop(currentTime + DECAY_DURATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -42,9 +42,8 @@ class VolumeEffect extends Effect {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
|
||||||
const {gain} = this.outputNode;
|
const {gain} = this.outputNode;
|
||||||
const {currentTime, DECAY_WAIT, DECAY_DURATION} = this.audioEngine;
|
const {currentTime, DECAY_DURATION} = this.audioEngine;
|
||||||
gain.setValueAtTime(gain.value, currentTime + DECAY_WAIT);
|
gain.linearRampToValueAtTime(value / 100, currentTime + DECAY_DURATION);
|
||||||
gain.linearRampToValueAtTime(value / 100, currentTime + DECAY_WAIT + DECAY_DURATION);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -71,7 +71,7 @@ tap.test('SoundPlayer', suite => {
|
||||||
});
|
});
|
||||||
|
|
||||||
suite.test('stop decay', t => {
|
suite.test('stop decay', t => {
|
||||||
t.plan(7);
|
t.plan(5);
|
||||||
soundPlayer.play();
|
soundPlayer.play();
|
||||||
soundPlayer.connect(audioEngine);
|
soundPlayer.connect(audioEngine);
|
||||||
const outputNode = soundPlayer.outputNode;
|
const outputNode = soundPlayer.outputNode;
|
||||||
|
@ -88,13 +88,10 @@ tap.test('SoundPlayer', suite => {
|
||||||
inputs: [outputNode.toJSON()]
|
inputs: [outputNode.toJSON()]
|
||||||
}], 'output node connects to gain node to input node');
|
}], 'output node connects to gain node to input node');
|
||||||
|
|
||||||
audioContext.$processTo(audioEngine.DECAY_WAIT + audioEngine.DECAY_DURATION / 2);
|
audioContext.$processTo(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');
|
t.equal(outputNode.$state, 'PLAYING');
|
||||||
|
|
||||||
audioContext.$processTo(audioEngine.DECAY_WAIT + audioEngine.DECAY_DURATION + 0.001);
|
audioContext.$processTo(audioEngine.DECAY_DURATION + 0.001);
|
||||||
t.deepEqual(help.engineInputs, [{
|
t.deepEqual(help.engineInputs, [{
|
||||||
name: 'GainNode',
|
name: 'GainNode',
|
||||||
gain: {
|
gain: {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue