According to the spec events are calculated in order, so if you have a setValueAtTime
scheduled before a rampToValueAtTime
the ramp will get calculated after that:
audioParam.setValueAtTime(audioParam.value, time);
audioParam.linearRampToValueAtTime(0, time+this.time);
If you are looking for something that ramps while keeping the current value in mind (the time to ramp depends on the difference between the value right now and the given target value), I recommend you to use the setTargetAtTime
system. This should be usefull as the spec mentions it is for example useful in your situation:
Start exponentially approaching the target value at the given time with a rate having the given time constant. Among other uses, this is useful for implementing the "decay" and "release" portions of an ADSR envelope.
This calculates with a timeConstant, which defines how much time it should take to ramp to 1 - 1/e (around 63.2%)
.Use it like
audioParam.setTargetAtTime(<target_value>, <start_Time>, <timeConstant>);
The higher the time constant, the slower the transition is. I recommend you play around with the value to see what fits for your situation.