Re: Creating ADSR Envelopes

But I don't think that will work in this case - the key problem is that
Yotam is trying to trigger the envelope (i.e. checkpoint the current
release value and then schedule a new ramp) at some point in the future.
 If you cancelSceduledValues(0), it will stop the current release, even
though you're not intending to trigger the new envelope for another 0.02s.
 You could param.cancelScheduledValues( currentTime + 0.02 ), but you need
to read .value *at that point, 0.02s in the future.*  You can only read and
set the .value to its current value in Javascript right now.

 I suppose if you used all setTargetValueAtTime() calls, you could get
effectively the right behavior (except, of course, no linear ramps for
attacks).

The only way I can see to get this behavior currently is to set a JS
timeout for the envelope retrigger (and in that JS timeout,
cancelScheduledValues, setValue(current value), linearRamp...).

I do think 1) we should explicitly capture in the spec what happens when
you cancelScheduledValues(), both to the current value and for any future
scheduling calls; 2) we might consider adding a
cancelScheduledValuesAndCheckpoint( time ) call, that would solve this
issue.


On Thu, Jan 10, 2013 at 11:58 AM, Chris Rogers <crogers@google.com> wrote:

>
>
> 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 20:16:01 UTC