From 0059ff53e1f7cca3be06a545f04f63985285c153 Mon Sep 17 00:00:00 2001 From: "Michael \"Z\" Goddard" Date: Mon, 11 Jun 2018 15:20:48 -0400 Subject: [PATCH] start audio param transition at now Explicitly start the param transitions at the audio context's now time. --- src/effects/PanEffect.js | 12 ++++++++++-- src/effects/VolumeEffect.js | 6 +++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/effects/PanEffect.js b/src/effects/PanEffect.js index ea50c2f..d58558a 100644 --- a/src/effects/PanEffect.js +++ b/src/effects/PanEffect.js @@ -58,8 +58,16 @@ 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, 0, this.audioEngine.DECAY_TIME); - this.rightGain.gain.setTargetAtTime(rightVal, 0, this.audioEngine.DECAY_TIME); + this.leftGain.gain.setTargetAtTime( + leftVal, + this.audioEngine.audioContext.currentTime, + this.audioEngine.DECAY_TIME + ); + this.rightGain.gain.setTargetAtTime( + rightVal, + this.audioEngine.audioContext.currentTime, + this.audioEngine.DECAY_TIME + ); } /** diff --git a/src/effects/VolumeEffect.js b/src/effects/VolumeEffect.js index 8e536d7..32204f0 100644 --- a/src/effects/VolumeEffect.js +++ b/src/effects/VolumeEffect.js @@ -34,7 +34,11 @@ class VolumeEffect extends Effect { this.value = value; // A gain of 1 is normal. Scale down scratch's volume value. Apply the // change over a tiny period of time. - this.outputNode.gain.setTargetAtTime(value / 100, 0, this.audioEngine.DECAY_TIME); + this.outputNode.gain.setTargetAtTime( + value / 100, + this.audioEngine.audioContext.currentTime, + this.audioEngine.DECAY_TIME + ); } /**