- From: Phil Burk <philburk@mobileer.com>
 - Date: Tue, 07 Feb 2012 09:42:06 -0800
 - To: public-audio@w3.org
 
I am having fun experimenting with the Web Audio API. Great stuff.
I tried to use the linear ramp function of the AudioGainNode.
   <http://www.softsynth.com/webaudio/gainramp.php>
I had some problems when I tried using 
linearRampToValueAtTime(value,time). I am getting pops and some 
unexpected behavior.
The documentation is not very clear about whether the time is a duration 
or a target time. I think it is the time the value should be reached.
In mode=1 of my test I tried to ramp up a tone using:
    gainNode.gain.linearRampToValueAtTime(1.0,
          context.currentTime + 1.0);
But it jumped abruptly to 1.0 after a 1 second delay.
I then found that if I set a sort of breakpoint at the current value and 
current time then I could get a ramp that worked most of the time. But 
sometime it would jump uncontrollably.
    // set beginning of ramp
    gainNode.gain.linearRampToValueAtTime(gainNode.gain.value,
          context.currentTime );
    // set end of ramp
    gainNode.gain.linearRampToValueAtTime(1.0,
          context.currentTime + 1.0);
I had better luck with the setTargetValueAtTime() method. It usually 
gave me smooth ramps.
It would be nice if there was a function that did the following:
   linearRampWithDuration( targetValue, timeToStart, duration );
At timeToStart the parameter will begin ramping from its current value 
towards the targetValue so as to arrive at the targetValue in duration 
seconds.
The following calls could then be made:
   var now = context.currentTime;
   // Start ramping now from current value towards 1.0 over 2 seconds.
   gain.linearRampWithDuration( 1.0, now, 2.0 );
   // after 1 second start ramping down to 0.3 over 2 seconds
   gain.linearRampWithDuration( 0.3, now+1.0, 2.0 );
It is handy if the each ramp simply starts at the current value so that 
a ramp can be redirected without pops.
Thanks,
Phil Burk
Received on Tuesday, 7 February 2012 17:46:17 UTC