[chuck-users] Envelope.last()

Spencer Salazar ssalazar at CS.Princeton.EDU
Sat Jan 13 19:58:03 EST 2007


On Jan 13, 2007, at 1:22 PM, Daniel Trueman wrote:

> thanks spencer. which of course leads to more questions...
>
> by accident, i did this:
>
> >>>>>>>>>>>
> Step stp => Envelope e => SinOsc s => dac;
> 220 => s.freq;
>
> // set step value
> 1 => stp.next;
> // set the current value of the envelope
> s.freq() => e.value;
> // set the target value of envelope
> s.freq() * 2 => e.target;
> // set time to reach target
> 10 => e.time;
>
> while (20::ms => now){
> 	//nothing needed to do....
> }
> >>>>>>>>>>>
>
> and it works! so i gather there is some default parameter that gets  
> set in a ugen when you chuck to it?

Ah yes.  Thats actually a much more efficient method than the one I  
wrote, as the ChucK audio subsystem is applying the envelope for  
you.  Oscillator ugens have a parameter .sync, which states how a  
given oscillator is affected by its input.  The online documentation  
and ChucK manual are a bit out of date as to what values .sync  
accepts and what those values do, as they have changed recently.  So  
here they are:

0 => osc.sync (the default) causes the frequency of the oscillator to  
be whatever its input is;
1 => osc.sync causes the phase of the oscillator to be whatever its  
input is;
2 => osc.sync adds the oscillator's input to its current frequency,  
i.e. frequency modulation

Notably, this only works with the basic oscillator ugens, so the  
other less efficient enveloping method would be needed for other  
ugens like filters or STK instruments.

> i'm curious in part because i'd like to write classes which can do  
> this, for example:
>
> someRandomControlSignal => MySillyControlFilter_class mscfc =>  
> Envelope e => SinOsc s => dac;
>
> etc....
>
> is there a way to write classes which can be chucked to in this way?

That sort of thing is possible, but currently it is not possible to  
write chuckable ugens in ChucK code--that has to be done on the C++  
side, and invariably involves compiling a custom chuck binary.   
Solutions to both of those problems are high on the to-do list (first- 
class UGens in ChucK code, dynamic UGen plugins).  There are a few  
non-ideal workarounds at the moment, mostly involving writing  
functions to act as the chuck and unchuck operators.  You could also  
probably implement MySillyControlFilter_class in ChucK using some  
combination of built-in ugens, but packaging it into a single  
chuckable ugen would not be possible without delving into the chuck  
source.

spencer

> again, this can obviously be done other ways, but grasshopper is  
> attempting to learn.
>
> sorry if this is documented somewhere already!
>
> dan
>
>
> On Jan 13, 2007, at 11:19 AM, Spencer Salazar wrote:
>
>> Hey Dan,
>> You're on the right track with that code.  Envelope needs a source to
>> work on, though--if there isn't a ugen inputting samples to it, it
>> just envelopes a zero signal.  The Step ugen works nicely for this,
>> as you can feed it an arbitrary sample value, and it will
>> continuously feed this value through a patch.
>>
>> SinOsc s => dac;
>> 220 => s.freq;
>>
>> Step stp => Envelope e => blackhole;
>> // set step value
>> s.freq() => stp.next;
>> // set the current value of the envelope
>> 1 => e.value;
>> // set the target value of envelope
>> 2 => e.target;
>> // set time to reach target
>> 10 => e.time;
>>
>> // activate
>> e.keyOn();
>>
>> while (20::ms => now){
>> 	e.last()  => s.freq;
>> }
>>
>> A functionally equivalent but potentially clearer way of writing this
>> would be:
>>
>> SinOsc s => dac;
>> 220 => s.freq;
>>
>> Step stp => Envelope e => blackhole;
>> // set step value
>> 1 => stp.next;
>> // set the current value of the envelope
>> s.freq() => e.value;
>> // set the target value of envelope
>> s.freq() * 2 => e.target;
>> // set time to reach target
>> 10 => e.time;
>>
>> // activate
>> e.keyOn();
>>
>> while (20::ms => now){
>> 	e.last()  => s.freq;
>> }
>>
>> spencer
>>
>> On Jan 13, 2007, at 12:27 AM, dan trueman wrote:
>>
>>> can Envelope work like SinOsc to control ugen parameters? meaning,
>>> something like this, hacked from the lovely ChucK manual blackhole
>>> example:
>>>
>>> SinOsc s => dac;
>>> Envelope e => blackhole;
>>> 10. => lfo.time;
>>> s.freq = 220.;
>>> e.target(440.);
>>>
>>> while (20::ms => now){
>>> 	e.last()  => s.freq;
>>> }
>>>
>>> ?
>>>
>>> it doesn't work, and it seems that e.last() doesn't actually give
>>> you anything. obviously there are other ways to do this, but i'm
>>> trying to *learn* here!
>>>
>>> takk,
>>> dan
>>> _______________________________________________
>>> chuck-users mailing list
>>> chuck-users at lists.cs.princeton.edu
>>> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>>
>> _______________________________________________
>> chuck-users mailing list
>> chuck-users at lists.cs.princeton.edu
>> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users



More information about the chuck-users mailing list