[chuck-users] A couple of questions

pibsid at suomi24.fi pibsid at suomi24.fi
Mon Jan 14 05:10:08 EST 2008

Johan Nilsson wrote:
>>1) Here is an example of a simple synthesizer with two envelopes, one for gain and one for frequency. For the first one it is rather straight forward how to connect it using the chuck operator, but as for the frequency envelope: is there some better way to implement it? I get the feeling I make things a bit complicated and inefficient this way. It would feel more natural to me to chuck it to a frequency input of osc.

I'll leave the rest of your questions to more experienced chuckers.

But as for question 1:
You can chuck an input to an oscillator with a sync mode 2 and it does the same as your control loop:

Modified version of your code follows:
class Synth
 SawOsc osc => ADSR ampEnv => dac;
 2 => osc.sync; //Modulate frequency according to input;
 Step oneThousand => ADSR freqEnv => osc; 
 1000.0 => oneThousand.next; //Needed so that freqEnv outputs non-zero samples.
 500::ms => freqEnv.attackTime;
 500::ms => freqEnv.decayTime;
 0.5 => freqEnv.sustainLevel;
 1000::ms => freqEnv.releaseTime => ampEnv.releaseTime;
 float freq; 
 fun void keyOn(float f)
  f => freq => osc.freq;
 fun void keyOff()

 /*fun void frequencyEnvelope()
  while(10::ms => now)
   freqEnv.value() * 1000 + freq => osc.freq;

//Try it out:
Synth s;
220 => s.keyOn;
1.5::second => now;
2::second => now;

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20080114/d8ce9916/attachment.htm 

More information about the chuck-users mailing list