- From: Phil Burk <philburk@mobileer.com>
- Date: Mon, 06 Feb 2012 18:24:29 -0800
- 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. <http://www.softsynth.com/webaudio/gainramp.php> 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: 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 ramp segments can be chained together without glitches. Thanks, Phil Burk
Received on Tuesday, 7 February 2012 02:28:52 UTC