I am trying to implement volume envelopes that can restart at any time, even if it is already in the middle of the param-motion element, but I cannot figure out how to do this without clicks in the received audio (which seems somewhat irregular as to when they are occur).
Is it possible? I see that AudioParam.cancelScheduledValues() "cancels all planned future changes in AudioParam", but I'm not sure what will happen with the current change.
This is the code that I use to start / restart the volume envelope.
var now = context.currentTime; var currentVol = gain.gain.value; gain.gain.cancelScheduledValues(now); gain.gain.setValueAtTime(currentVol, now); gain.gain.exponentialRampToValueAtTime(1, now + volAttack); gain.gain.exponentialRampToValueAtTime(0.000001, now + volAttack + volDecay);
source share