Below are the notes that I took at the ChucK audio programming workshop lead by Ge Wang at Stanford CCRMA on Sunday Jan 13, 2008. Ge Wang and I organized this event through the Bay Area Computer Music Technology group. Many thanks to Ge for teaching this! You can join the Bay Area Computer Music Technology group if you would like to be informed of the advanced workshop, which should happen in another few months.
These are raw notes. If you notice any egregious typos let me know and I will correct them. Happy ChucKing…
ChucK Workshop Notes – Lead by Ge Wang – Sun, Jan 13th, 2008
Code == musical instrument On the fly programming
Audicle is fun and crazy to use, but it’s still a line of research. MiniAudicle is more usable.
Language design solutions:
- Make time itself computable
- Synchronize events
- Flexible and Readable – optimize later
The CHUCK Operator
this is the chuck operator:=>
simple chuck:
x => y;
action depends on what x and y are.
chain chuck:
w => x => y => z;
operations run from left to right. This is backwards from other langs like (c/c++, Java)
nested (do what’s in brackets first):
w => (x => y) => z
unchuck:
x =< y =< z;
feedback:
x => y => x
Time and Basic Usage
dur is a native type
Basic code test:SinOsc foo => dac;
Generate a sine wave. foo instanciates SineOsc. foo is like a patchcord.
440 => foo.freq;
To make sound you must advance time:
1::second => now;
comments:
//this is a comment - same as Java or C/C++
/* can also use c style comments */
There are emacs keybindings for chuck. Others? Coloring in MiniAudicle.
default intensity is 1. chuck will not advance time for you. you must advance time.
basic program://----------------
SinOsc foo => dac;
.5 => foo.gain;
//advance time!
220 => foo.freq;
.5::second => now;
windows and linux versions work. Mac OS X is the easiest to use.
MiniAudicle:
- start virtual machine
- add shread to run. can add multiple threads.
- replace thread, replaces old thread code, replace just replaces the latest thread
- remove thread removes thread on top
- watch for errors in the console monitor
for os x users only go to
- miniAudicle => prefereces
- enable on-the-fly programming visual feedback (show you gostbusters x when there is an error)
SinOsc foo => dac;
.5 => foo.gain;
//advance time!
while ( true )
{
//choose frequency randomly
Std.rand2f(30,1000) => foo.freq;
100::ms => now;
}
consider:
- 3/2 does integer division not floating point division
- 3/2 = 1
- 3./2 or 3.0/2 = 1.5
100::ms => now; //does not use system clock
//puts code processing to sleep while stepping forward
if code needed to advance time is not computable in the given time you will have dropouts you can compute in “real time” or “off line”
can inject code into running threads, but this is programmatic rather than a built in part of the virtual machine.
time constructs:1::week //stopped here because month and week are variable size
1::day
1::hour
1::minute
1::second
1::ms
1::samp
could do:
52::week => dur year; //define 1::year
up next: sounds, parallel, controllers
SinOsc foo => dac; //foo is local to this shred
Links on the ChucK Language
- home page for ChucK is: chuck.cs.princeton.edu – download chuck, miniAudicle
- language specs
Check out the unit generators listing in the specs. Eventually users will be able to develop their own unit generators.
BiQuad is all you need to implement a filter of any complexity (due to re-factoring). ResonZ is (probably) the same as reson~ in max/msp
STK unit generators are in chuck: Envelope, ADSR, Delay, etc. STK instruments unit generators BandedWG – tibetan bowls, and bowed instruments Bowed – cool but not realistic Flute – excellent model but hard to control (lots of params) Shakers – awesome, 22 presets maracas to points in (statistical method for modeling particle systems – from Peri Cooks Physm)
Small Musically Expressive Laptop Toolkit
- has some great chuck code
- keyboard and mouse events
More Complex Sounds (than a sine wave)
Basic Harpsichord sounding instrument with verb code:StifKarp foo => JCRev r => dac;
.1 => r.mix; //set reverb ammount 0 is none, generally params are 0 -1
//advance time!
while ( true )
{
//choose frequency randomly
Std.rand2(30,90) => Std.mtof => foo.freq;
//note on!
1 => foo.noteOn;
//advance time
500::ms => now;
}
There are 50,000 line chuck apps out there!
Ge’s Q&A:
- Object system is still not fully implemented.
- Laptop orchestra recordings are on line (but this doesn’t give 90 discrete channels of sound that you would get at a concert) – good chuck examples
- There are some good non-PLork chuck pieces as well
- Wiki and forum also has chuck code.
- Piece called “TBA” – first instance of orchestral livecoding
- Coding as a gesture. What are the aesthetic of laptop performance beyond the glow of the laptop on the face.
- The score as a page of code that is going to be typed…
- Livecoding communication with comments
- Rehearsal becomes important… knowing what kind of sounds you can get out of your algorithms becomes tremendously important.
If they are started concurrently they are all controlled off of the same clock and time is advanced in a concurrent fashion.
By the way the full audicle application is really amazing. Very visually interesting… Very important synchronization code convention. You can synchronize applications by using this code in all running synchronized shreds. Uses modulo to quantize events:
.5::second => dur T;
T - (now % T) => now; //take now and use modulo
All threads have access to the same system clock To synchronize threads add the above code to the head of threads to be synchronized
Input devices
Use: Hid (HidIn deprecated) – get keyboard input
Chuck team has an interest in Commodity devices and using them for music making.
Chuck is open source and released under GPL. Note some of the waveguides may have patents associated with the algorithms. Patents expire shortly (they are from the early eighties). For the most part you are fine, you may want to check if you are distributing to millions of people.
Karplus Strong Implementation
Karplus and Strong Plucked string filter - Researchers at Stanford attempting to synthesize drum timbres - Julius Smith and David Jaffe(?) were inspired to look further - higher frequencies die off faster than lower frequency
//basic karplus strong algorithm
//although they used noise rather than an impulse
//feedforward
Impulse i => Delay d => dac;
//feedback with gentle lowpass
d => OneZero lowpass => d;
//generate the impulse
.5 => i.next;
//set the delay length
500::samp => d.delay; //this length controls the pitch
//dissipation
.99 => lowpass.gain;
//advance time
4::second => now;
You can currently package code such as the above into a chuck object. But currently you cannot currently make something like this into a unit generator.
look into the deep folder for interesting code examples:
- THX emulater (amusing)
- unclap.ck – Steve Reich clapping music realization
can talk to other applications using OSC bindings.
The Future
Another chuck workshop digesting advanced material is in the works for about two months from now through the Bay Area Computer Music Technology Group