[chuck-users] Get the value of an Envelope
Tom Lieber
lieber at princeton.edu
Tue Jan 20 15:52:14 EST 2009
2009/1/20 Andrew C. Smith <acsmith at willamette.edu>:
> I've got some flawed code here, and that's because I'm stuck. I want
> to dynamically change Gen17's coefficients using an Envelope to get a
> smooth sample-rate transition, but I can't figure out how to use the
> last value from an Envelope and put it into the array to assign to
> cheb.coefs. How would I do this? Would I need a sample rate for()
> control? Thanks.
>
> Andrew
>
> SinOsc drive => Gen17 cheb => dac;
> [1., 0.5, 0.25, 0.125, 0.06] @=> float coefs[];
> 0.2 => cheb.gain;
>
> while(true)
> {
> Std.rand2(0, 4) => int coef_changed;
> Std.rand2f(0., 0.99) => float dest;
>
> coefs => cheb.coefs;
> Envelope change => coefs[coef_changed];
>
> change.target(dest);
> change.duration(50::ms);
>
> 50::ms => now;
> }
The last value is always available via .last(), in this case
change.last(). Unfortunately, the "UGen connection" => and the
"assignment" => are separate operators, so you can't chuck the
envelope into the array. In order to update coefs value using the
envelope, you will have to sample its values manually using a loop
like you said. I think you want something like this:
while(true)
{
Std.rand2(0, 4) => int coef_changed;
Std.rand2f(0., 0.99) => float dest;
coefs => cheb.coefs;
Envelope change => blackhole;
change.target(dest);
change.duration(50::ms);
// sample envelope every 1ms
for(now => time t; (now - t) < 50::ms; 1::ms => now) {
change.last() => coefs[coef_changed];
// ... use coefs ...
}
}
--
Tom Lieber
http://AllTom.com/
More information about the chuck-users
mailing list