[Stk] Ramping with ADSR

Ariel Elkin arielelkin at gmail.com
Mon Sep 17 10:26:41 PDT 2012


Beautiful, works like a charm. Thanks Gary!

On 17 Sep 2012, at 4:52pm, Gary Scavone wrote:

> Hi Ariel,
> 
> The setTime() function currently assumes a target of 1.0 and a current value of 0.0.  As well, the rate doesn't automatically update itself based on a previously set time if you later change the target value.  I admit that is a bit limiting but I don't plan updates for a while.  In the mean time, you can set your specific rate directly using the setRate() function.  You can do something like:
> 
>  rate = (targetValue - currentValue) / (time * sampleRate);
> 
> Regards,
> 
> --gary
> 
> On 2012-09-17, at 11:22 AM, Ariel Elkin <arielelkin at gmail.com> wrote:
> 
>> …so the class was already there… guess I wasn't even able to reinvent the wheel  :-(
>> 
>> Anyway, so I'm now using Envelope, but the values are still ramping up too slowly. 
>> 
>> This is how I set up my Envelope:
>> 
>>   audioData.envelope = new Envelope();
>>   audioData.envelope->setTime(10);
>> 
>> And later on I call:
>> 
>>   audioData.envelope->setTarget(400);
>> 
>> But I'm getting the same problem. When I call envelope->lastOut() every 500ms to check its value, after 10 seconds of calling setTarget(), the value is still at around 1.4 instead of 400.
>> 
>> If I divide by 100 the parameter I give to setTime(), then it ramps at more or less the desired duration. Are you sure the value is in seconds?
>> 
>> Ariel
>> 
>> 
>> On 17 Sep 2012, at 3:46pm, Gary Scavone wrote:
>> 
>>> If you want a basic ramp, try Envelope (https://ccrma.stanford.edu/software/stk/classstk_1_1Envelope.html).
>>> 
>>> --gary
>>> 
>>> On 2012-09-17, at 10:39 AM, Ariel Elkin <arielelkin at gmail.com> wrote:
>>> 
>>>> Hi all,
>>>> 
>>>> I would like to have a sine wave's frequency smoothly go from 0 to 400 over 10 seconds. 
>>>> 
>>>> I've tried implementing that with a function that updates the wave's frequency every 20 milliseconds, but there are audible bumps in the sound. So I need something that can create a smoother ramp, and I thought of ADSR. 
>>>> 
>>>> But I noticed that calling ADSR::keyOn() automatically sets the attack target to 1.0, and I want it to be an arbitrary value (400.0 in my case). So I added the function below to ADSR:
>>>> 
>>>> void ADSR:: keyTo( StkFloat target )
>>>> {
>>>>     target_ = target;
>>>>     state_ = ATTACK;
>>>> }
>>>> 
>>>> Here's how I setup my ADSR object: 
>>>> 
>>>> audioData.adsr = new ADSR();
>>>> audioData.adsr->setValue(0);
>>>> 
>>>> audioData.adsr->setAttackTime(10);
>>>> audioData.adsr->setDecayTime(1);
>>>> audioData.adsr->setReleaseTime(1);
>>>> 
>>>> I've then been calling ADSR::lastOut() every 500ms to check its value, and I notice that it goes from 0.0 to about 1.5 in the first 10 seconds. Can anybody see why? Is it possible/a good idea to implement a ramp with ADSR? 
>>>> 
>>>> Cheers
>>>> 
>>>> Ariel
>>>> 
>>>> _______________________________________________
>>>> Stk mailing list
>>>> Stk at ccrma.stanford.edu
>>>> http://ccrma-mail.stanford.edu/mailman/listinfo/stk
>>> 
>> 
>> 
>> _______________________________________________
>> Stk mailing list
>> Stk at ccrma.stanford.edu
>> http://ccrma-mail.stanford.edu/mailman/listinfo/stk
> 




More information about the Stk mailing list