Re: Creating ADSR Envelopes

On Thu, Jan 10, 2013 at 11:54 AM, Yotam Mann <matoyotambien@gmail.com>wrote:

> yes! it does work on Canary. that's a relief.
>
> the first part of my question is mostly pertaining to envelope retriggers.
> If i schedule an envelope with a very long release, and then at some later
> point while that release is still going on, i get a callback to schedule
> another envelope 0.02s in the future, i would like next envelope's attack
> starting value to begin where the current release has left off (even if it
> never makes it to 0).
>
> maybe this question comes out of ignorance for how the AudioParam's values
> are calculated when there are multiple values scheduled.
>
> here is an simplified example of what i'm talking about:
>
> function triggerAttack (time) {
>   param.linearRampToValue(1, time+attackTime);
>   param.linearRampToValue(sustainValue, time+attackTime+decayTime);
> }
>
> function triggerRelease (time){
>   param.linearRampToValue(0, time+releaseTime);
> }
>
> if i retrigger the attack while the release is still going on, how is the
> attack duration and value calculated? my understanding was that i needed to
> schedule a value at the start of the attack so that the attack will be
> correctly ramped, so i usually write something like this:
>
> function triggerAttack (time) {
>   param.setValueAtTime(*SOME VALUE?*, time);
>   param.linearRampToValue(1, time+attackTime);
>   param.linearRampToValue(sustainValue, time+attackTime+decayTime);
> }
>
> but, i don't know what the value at the param time of the attack is since
> the release is still going on.
>

You should be able to cancel all scheduled values with:
param.cancelScheduledValues(0);

Then simply read the .value attribute to get its current value.


>
> does that make sense?
>
>
>
> On Thu, Jan 10, 2013 at 11:08 AM, Chris Wilson <cwilso@google.com> wrote:
>
>> Hey Yotam,
>>
>> I'm not sure I understand the first half of your statement - if you know
>> when in the future you will be scheduling another envelope, can't you use
>> ramps to that time?  This seems like "I want the release to start 0.02s
>> after I receive this JS event", or something like that - is this correct?
>>
>> That aside, the filter frequency should work as you surmise; however,
>> there was a bug in that for a while.  Are you using Chrome Canary (i.e.
>> version 26.xx?)
>>
>> -Chris
>>
>>
>> On Thu, Jan 10, 2013 at 11:00 AM, Yotam Mann <matoyotambien@gmail.com>wrote:
>>
>>> Hi group,
>>>
>>> I'm working on a synthesizer in Web Audio and i'm stuck on the filter
>>> envelope part.
>>>
>>> One issue that i'm having is that the pattern that I see often for
>>> avoiding clicks when scheduling AudioParam's envelopes doesn't work when
>>> scheduling the envelope in the future where the AudioParam's current value
>>> is no longer the same:
>>>
>>> i.e. AudioParam.setValueAtTime(AudioParam.value, context.currentTime);
>>>
>>> If i want to schedule the next envelope in the future, but don't know if
>>> the previous envelope's release has finished, i can't have the future
>>> attack start where the previous envelope's release left off since there is
>>> not getValueAtTime function for AudioParams.
>>>
>>> For this reason, i decided to make my own envelope generator with a
>>> ScriptNode. This works well when I connect this signal to an oscillator's
>>> gain, but I also want to apply the envelope to a filter's frequency
>>> AudioParam. I scale the ADSR values to be between 0 and 500 for example and
>>> connect it to the filter.frequency, but it doesn't not seem to be making
>>> any difference. does this filter's frequency AudioParam not behave the same
>>> as the gain's gain param?
>>>
>>> Insight on these issues would be greatly appreciated.
>>>
>>> thanks.
>>>
>>> Yotam
>>>
>>
>>
>

Received on Thursday, 10 January 2013 19:59:21 UTC