I am not able to get a sliding change of volume through exponentialRampToValueAtTime of a GainNode.
Here is an example:
var context = new AudioContext(),
osc = context.createOscillator(),
gain = context.createGain();
osc.frequency.value = 440; // A note
osc.start( 0 );
osc.connect( gain );
gain.gain.value = 0;
gain.connect( context.destination );
gain.gain.cancelScheduledValues( 0 );
gain.gain.setValueAtTime( 0, context.currentTime );
gain.gain.exponentialRampToValueAtTime( 1, context.currentTime + 2 );
In my understanding this should gradually increase the volume, until reaching 1 (100%) and this whole process should take 2sec. Is this assumption correct?
If it is, why does stay on 0 for 2 sec, and suddenly switches to full volume?
Thanks in advance for your time and effort.
It seems that this function does not like 0 value. FF throws "SyntaxError: An invalid or illegal string was specified". Below code will ramp correctly. See on Plnkr.
var context = new AudioContext(),
osc = context.createOscillator(),
gain = context.createGain();
osc.frequency.value = 440.0; // A note
osc.start( 0 );
osc.connect( gain );
gain.connect( context.destination );
gain.gain.setValueAtTime(0.0001, context.currentTime); // <-- line of interest
gain.gain.exponentialRampToValueAtTime(1, context.currentTime + 10 );
UPDATE: "A NotSupportedError exception must be thrown if this value is less than or equal to 0, or if the value at the time of the previous event is less than or equal to 0" according Web Audio specification. As figured out by @cwilso (see comments).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With