W3C home > Mailing lists > Public > public-audio@w3.org > January to March 2012

linear ramps and the Web Audio API

From: Phil Burk <philburk@mobileer.com>
Date: Tue, 07 Feb 2012 09:42:06 -0800
Message-ID: <4F31626E.1010406@mobileer.com>
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.


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:

          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
          context.currentTime );

    // set end of ramp
          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 

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.

Phil Burk
Received on Tuesday, 7 February 2012 17:46:17 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:49:57 UTC