Re: Fading sound in and out

Actually, your problem is you're not setting the start point for the linear
ramp appropriately; you setValueAtTime(0) when the context is created, But
you need to additionally set it when the play or stop button is pressed (to
give it a start value and (more importantly) time for the ramp.  See
http://jsfiddle.net/9La05fg5/11/.

What's happening now is whenever the click methods are called, the start
time and value for the ramp is whatever the last schedule event was - e.g.,
if you loaded the page and waited three seconds, then clicked play, the
linear ramp will have its start point (value 0) set on creation - 3 seconds
in the past - and the end point is three seconds in the future (value 1) -
so it will immediately jump to 0.5, and ramp from 0.5 to 1 over the next 3
seconds, which is why it's not smooth enough.

I really need to write an explanatory article about how to use the
scheduler.


On Wed, Aug 20, 2014 at 9:43 AM, Chinmay Pendharkar <notthetup@gmail.com>
wrote:

> Hello,
>
> You can look at using the exponentialRampToValueAtTime or setTargetAtTime methods
> instead.
>
> Human perception of loudness is logarithmic in nature, so exponential
> decays of loudness feel 'smoother' to us than linear decays.
>
> -Chinmay
>
>
> On Wed, Aug 20, 2014 at 10:29 PM, Yehonathan Sharvit <viebel@gmail.com>
> wrote:
>
>> Hi,
>>
>>
>> What is the best way to fade sound in and out?
>>
>> I tried to achieve that by calling linearRampToValueAtTime (see a demo:
>> http://jsfiddle.net/viebel/9La05fg5/7/) on a gain node but the effect
>> was not smooth enough?
>>
>> How could I make it smoother?
>>
>> Thanks,
>> Yehonathan.
>>
>
>

Received on Wednesday, 20 August 2014 16:22:10 UTC