Author |
Message |
Khepri
Joined: Jul 20, 2009 Posts: 22 Location: Canada
|
Posted: Tue Aug 14, 2012 3:22 pm Post subject:
Chuck for Dummies Subject description: Attack Rate |
|
|
I'm thinking of starting a "Chuck for Dummies" writing project for myself. Who knows - it might eventually develop into a fairly comprehensive basic-level reference for those in need of this kind of "for Dummies" thing.
So . . . here's a "for Dummies" kind of question: What exactly does an Envelope's "rate" parameter do? Is it a curve? Some exponential thing? (Non-math Dummy here.) If, for example, you can decide an ADSR's decay period, why do you need a "rate" of change when you've already specified the duration of that change?
Thanks _________________ Don't fear mistakes. There are none.
- Miles Davis |
|
Back to top
|
|
|
Antimon
Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 371
G2 patch files: 100
|
Posted: Wed Aug 15, 2012 1:40 pm Post subject:
|
|
|
With ChucK, I can recommend experimenting with some code when wondering about stuff like this, since it's so easy and you learn stuff while doing. :)
Anyway, this one is kind of interesting. Envelope provides a single linear slope, and the rate, time and duration settings on it are interchangeable. Setting one affects the other two.
I sat down and fiddled a bit and came up with this code:
Code: | Envelope e => blackhole;
Envelope e2 => blackhole;
SinOsc o => dac;
SinOsc o2 => dac;
0.3 => o.gain;
0.3 => o2.gain;
200 => e.value;
400 => e.target;
1::second => e.duration;
300 => e2.value;
500 => e2.target;
1.0/220.5 => e2.rate;
<<< "e time", e.time(), e.rate(), (1.0/e.rate()) >>>;
<<< "e2 time", e2.time(), e2.rate() >>>;
while (true) {
e.value() => o.freq;
e2.value() => o2.freq;
1::ms => now;
}
|
It ramps up the frequency of two oscillators (the while loop at the end is for copying values from the envelopes to the oscillators), one of them is set using duration() and the other using rate(). They both take one second to complete.
The value 1/220.5 seems connected to the sample frequency, which is 44100 kHz here. If this is consistent then rate means units per 200 samples (if my brain got this right). It looks esoteric enough though that I wouldn't trust it really. I'd recommend using time() or duration() and just calculating the time you want.
Anyway I think all the envelope slopes are linear. If you want exponential/logarithmic stuff you'll have to roll your own, maybe using a loop like I did here or something.
If that didn't help at all give a shout and I'll try to be more coherent. :)
Edit: wrote time(), I meant duration() _________________ Antimon's Window
@soundcloud @Flattr home - you can't explain music |
|
Back to top
|
|
|
Khepri
Joined: Jul 20, 2009 Posts: 22 Location: Canada
|
Posted: Wed Aug 15, 2012 6:04 pm Post subject:
|
|
|
Thanks very much, Antimon! I appreciate the example code. I should be able to take a good look at it tomorrow. I'm inexperienced enough with both C syntax and ChucK that I sometimes don't even see a way to test things out. But you are right -- it is quite an easy system to test things on, generally. I was doing that with ADSR today, and will try adding some envelopes to the same tune tomorrow.
Khepri _________________ Don't fear mistakes. There are none.
- Miles Davis |
|
Back to top
|
|
|
|