ChucK for Beginners
Today I gave a sample lecture to some sixth form students for Huddersfield University.
Took the opportunity to introduce them to ChucK and I think they found it quite enjoyable.
When introducing ChucK I prefer to use the miniAudicle as the VM monitor makes it easy to spot and sort problems and helps students develop a clear understanding.
So to start with a simple sine wave,
SinOsc s => dac; 500::ms => now;
Then a sine wave with a random frequency
SinOsc s => dac; Std.rand2f(300,600) => s.freq; 500::ms => now;
Now add in a simple control structure
SinOsc s => dac; while(1) { Std.rand2f(300,600) => s.freq; 500::ms => now; }
I use this example to explain the VM monitor and demonstrate how to stop a shred from the user interface.
Now is a good time to make a chord and explain the Ugens
SinOsc s => dac; SinOsc ss => dac; SinOsc sss => dac; while(1) { Std.rand2f(300,600) => s.freq; s.freq() + 100 => ss.freq; s.freq() + 200 => sss.freq; 500::ms => now; }
At this point I tend to talk about Ugen DSP network by modifying the code to include a Gain Ugen.
SinOsc s => Gain g => dac; SinOsc ss => g; SinOsc sss => g; while(1) { Std.rand2f(300,600) => s.freq; s.freq() + 100 => ss.freq; s.freq() + 200 => sss.freq; 500::ms => now; }
Doing this also makes it possible to sort the dac amplitude issues by altering the gain.
SinOsc s => Gain g => dac; SinOsc ss => g; SinOsc sss => g; 0.3 => g.gain; while(1) { Std.rand2f(300,600) => s.freq; s.freq() + 100 => ss.freq; s.freq() + 200 => sss.freq; 500::ms => now; }
I think this block of code provides an easy to follow introduction to the ChucK programming language.
Finally to finish the example off I like to expand the code to include to demonstrate the use of functions and sporking.
adc => Gain gg => blackhole; SinOsc s => Gain g => dac; SinOsc ss => g; SinOsc sss => g; function void linker() { while(1) { gg.last() => g.gain; 2::ms => now; } } spork ~ linker(); while(1) { Std.rand2f(300,600) => s.freq; s.freq() + 100 => ss.freq; s.freq() + 200 => sss.freq; 500::ms => now; }
So I think thats a good way to start off with ChucK.