Re: linear ramps and the Web Audio API

Hello Chris,

On 2/7/12 1:04 PM, Chris Rogers wrote:
> The time is a target time and the value is the ramp's end value.  One
> thing that I haven't made clear in the specification is that the
> intended use to first call setValueAtTime() to establish the initial
> (value,time).  Then subsequent calls to linearRampToValueAtTime()
> or exponentialRampToValueAtTime() can be made, and even chained one
> after the other.

Ahah!  I tried that and it worked much better. I now get smooth 
envelopes.  THANKS for the tip.

> One case I probably haven't handled which I think
> you're trying to test is how to call linearRampToValueAtTime() to
> establish the end-point of the linear ramp, but where you don't know
> what the starting value is (so a call to setValueAtTime() would not be
> possible).

Exactly. One might, for example, want to schedule some ramps in response 
to a user input. The current value may be unknown.

> Instead, in this case, we would want to start ramping from
> *whatever* value the parameter is "currently at".

As a workaround I do:

   var now = context.currentTime;
   gainNode.gain.cancelScheduledValues( now );
   // Anchor beginning of ramp at current value.
   gainNode.gain.setValueAtTime(gainNode.gain.value, now);

before I start scheduling the next series of ramps. I am probably 
getting small glitches because the ramp changes between the get and set. 
But it sounds much better than before.

   http://www.softsynth.com/webaudio/gainramp.php

> perhaps we need something like:
 >
> void anchorValueAtTime(in float time);
 >
> This would simply take whatever the current value is of the parameter at
> the given time and establish it as the anchor point (startValue,
> startTime) for a subsequent call to linearRampToValueAtTime(endValue,
> endTime) or exponentialRampToValueAtTime.

Yes. I think that would solve the problem and integrates well with the 
existing API.

Thanks for your help!

Phil Burk

Received on Wednesday, 8 February 2012 02:01:13 UTC