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: Mon, 06 Feb 2012 18:24:29 -0800
Message-ID: <4F308B5D.3000704@mobileer.com>
To: public-audio@w3.org
I am continuing my experiments with the Web Audio API.

I tried to use the linear ramp function of the AudioGainNode.


I tried using linearRampToValueAtTime(value,time). 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 
ramp segments can be chained together without glitches.

Phil Burk
Received on Tuesday, 7 February 2012 02:28:52 UTC

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