Lab 1: Introduction to ChucK

Getting Started With ChucK

Making a Simple "Orchestra"

``````SinOsc s => dac;

440 => s.freq;
0.5 => s.gain;

while(true){
10::ms => now;
}``````
• Make sure the ChucK virtual machine in running.
• Run the ChucK program by clicking on "Add Shred".
• The doc of ChucK UGens can be found here: http://chuck.stanford.edu/doc/program/ugen_full.html
• Try to replace `SinOsc` with `TriOsc`, `SqrOsc`, `SawOsc`. Each waveform generates a sound with a different timbre. This is called Wavetable Synthesis.
• Now, let's randomly change the pitch of the oscillator every 100ms:
``````while(true){
Math.random2f(100,1000) => s.freq;
100::ms => now;
}``````
• Time can be expressed in different units (e.g., `second`, `samp`, etc.).
• Adding reverb usually helps make things sound better:
``````SawOsc s => JCRev r => dac;

440 => s.freq;
0.5 => s.gain;
0.05 => r.mix;``````
• `JCRev` only has one parameter which is the amount of reverb applied to the processed sound.
• Functions can be written and executed as separate threads:
``````fun void albert(){
SawOsc s => JCRev r => dac;

440 => s.freq;
0.5 => s.gain;
0.05 => r.mix;

while(true){
Math.random2f(70,300) => s.freq;
500::ms => now;
}
}

fun void maureen(){
TriOsc s => JCRev r => dac;

440 => s.freq;
0.5 => s.gain;
0.05 => r.mix;

while(true){
Math.random2f(200,1500) => s.freq;
250::ms => now;
}
}

spork ~ albert();
2::second => now;
spork ~ maureen();

while(true){
1::second => now;
}``````
• In that case, Albert begins and is followed by Maureen after 2 seconds. Maureen is twice as fast as Albert.
• Let's now add Alex whose making use of subtractive synthesis. `f` is a bandpass filter with a very high Q, giving a pitch to the filtered noise. The center frequency (`f.freq`) of `f` determines the pitch of the generated sound.
``````fun void alex(){
Noise n => BPF f => dac;

5 => n.gain;
30 => f.Q;

while(true){
Math.random2f(500,3000) => f.freq;
125::ms => now;
}
}``````
• Don't forget to "spork" Alex!
• Finally, let's make some "optimization" by declaring the reverb only once:
``````JCRev r => dac;
0.05 => r.mix;

fun void albert(){
SawOsc s => r;

440 => s.freq;
0.5 => s.gain;

while(true){
Math.random2f(70,300) => s.freq;
500::ms => now;
}
}

fun void maureen(){
TriOsc s => r;

440 => s.freq;
0.5 => s.gain;

while(true){
Math.random2f(200,1500) => s.freq;
250::ms => now;
}
}

fun void alex(){
Noise n => BPF f => r;

5 => n.gain;
30 => f.Q;

while(true){
Math.random2f(500,3000) => f.freq;
125::ms => now;
}
}

<<< "Albert begins" >>>;
spork ~ albert();
2::second => now;
<<< "Maureen begins" >>>;
spork ~ maureen();
2::second => now;
<<< "Alex begins" >>>;
spork ~ alex();

while(true){
1::second => now;
}``````
• Note that pitch can also be expressed as a MIDI note number. `Std.mtof(value)` can be used to convert a MIDI note number into a frequency in ChucK.

More Basic ChucK Examples

• Go though the `basic` and `stk` ChucK examples available in `File/Open Example...` in MiniAudicle and try to get some basic understanding of them. Feel free to ask if you have any question!

Assignment (Due on Jan. 18. 2018)

• Go through the keyboard and mouse `hid` ChucK examples (`File/Open Example...` in MiniAudicle) such as `kb.ck`, `keyboard-organ.ck`, `mouse-fm.ck`, `mouse.ck`).
• Design a keyboard and/or mouse-controllable musical instrument using one (or several) of the sound synthesis technique(s) presented in this lab (e.g., in the `basic` and `stk` examples or in the section on making a simple "orchestra").
• Make sure that your instrument is expressive, artful, beautiful, playable, etc.
• Make a video of yourself playing it and post it on YouTube.
• Send the link of this video along with the source code of your instrument to by Jan. 18, 2018.
• Good luck and have fun!

Submissions

• Sho Arora
• Alec Arshavsky
• Noam Ben-Avi
• Ian Bick
• Doga Cavdir
• Abrahm DeVine
• Benjamin Fearon
• Charles Foster
• Kyle Gustafson
• Kyle Laviana
• Jason Liu
• Dana Murphy
• James Ordner
• Trent Peltz
• Kendrick Shen
• Stephanie Sherriff
• Juan Sierra
• Jianqing Yang