You are on page 1of 7

ChucK: A Multimedia Programming Language

Sarah “Viva Violet” Gorbatov

ChucK is a multimedia programming language for real-time sound synthesis and music creation. It is
open-source and presents a unique time-based, concurrent programming model that is precise and
expressive (we call this strongly-timed), dynamic control rates, and the ability to add and modify code
on-the-fly. It is fun and easy to learn, and it offers us composers, researchers, and performers a powerful
tool for building and experimenting with complex audio synthesis/analysis programs, as well as real-time
interactive music.

At the root of every ChucK code are comments, debug print, and reserved words.

Comments are sections of code that are ignored by the compiler - they help other programmers, ourselves
included, interpret our code.​ Double slashes indicate to the compiler to skip the rest of the line. /* and */
denote block commenting - the compiler ignores the text in between.
 
// this is a comment
int foo; // another comment

/*
this is a block comment
still going...
*/

Average Debug Print Syntax -


 
// prints out value of ​expression
​<<<​ ​expression​ ​>>>​; 
 
- This will print the values and types of any expressions placed within them.

Debug print constructions may be placed around any non-declaration expressions ​(non-l-value) and will
not affect the execution of the code. Expressions which represent an object will print the value of that
object’s reference address:
  
// assign 5 to a newly declared variable
5 => int i;
// prints "5 : (int)"
<<<i>>>;

// prints "hello! : (string)"


<<<"hello!">>>; //prints "hello! : (string)"

// prints "3.5 : (float)"


<<<1.0 + 2.5 >>>=> float x;
For more formatted data output, a comma-separated list of expressions will print only their respective
values (with one space between):

// prints "the value of x is 3.5" (x from above)


<<<"the value of x is" , x >>>;

// prints "4 + 5 is 9"


<<<"4 + 5 is", 4 + 5>>>;

// prints "here are 3 random numbers ? ? ?"


<<<"here are 3 random numbers",
Std.rand2(0,9),
Std.rand2(0,9),
Std.rand2(0,9) >>>;

Reserved Words:

● (primitive types)
○ int 
○ float 
○ time 
○ dur 
○ void 
○ same​ ​(unimplemented)

● (control structures)
○ if 
○ else 
○ while 
○ until 
○ for 
○ repeat 
○ break 
○ continue 
○ return 
○ switch​ ​(unimplemented)

● (class keywords)
○ class 
○ extends 
○ public 
○ static 
○ pure 
○ this 
○ super​ ​(unimplemented)
○ interface​ ​(unimplemented)
○ implements​ ​(unimplemented)
○ protected​ ​(unimplemented)
○ private​ ​(unimplemented)

● (other chuck keywords)


○ function 
○ fun 
○ spork 
○ const 
○ new 

● (special values)
○ now 
○ true 
○ false 
○ maybe 
○ null 
○ NULL 
○ me 
○ pi 

● (special: default durations)


○ samp 
○ ms 
○ second 
○ minute 
○ hour 
○ day 
○ week 

● (special: global ugens)


○ dac 
○ adc 
○ blackhole 

Every ChucK code, no matter its intricacy, is compiled into virtual instructions which are immediately run
into what is called the ChucK Virtual Machine.

THE FOLLOWING ARE MY CODES FOR THE PRESENTED COMPOSITIONS:

1.)​ ​stuffola.ck

// name: ​stuffola.ck
// composer: sarah gorbatov
// date: winter 2019

​ ow​ =
SinOsc​ r ​ >​ d​ ac​;
SinOsc​ c​ ol​ =​ >​ d​ ac​;

// frequencies
[​1209​.​0​,​ ​1336​.​0​,​ ​1477​.​0​]​ ​@=>​ f ​ loat​ ​cols[];
[​697​.​0​,​ ​770​.​0​,​ ​852​.​0​,​ ​941​.​0​]​ @​ =>​ ​float​ ​rows[];

// if you want to look up by number ( 0 - 9, *, # )


fun​ ​int​ ​key2col(​ ​int​ ​key​ ​)
{​ ​if​(​ ​!key​ ​)​ ​return​ ​1​;​ ​return​ ​(key​ ​-​ ​1​)​ ​%​ 3
​ ​;​ ​}
fun​ ​int​ ​key2row(​ ​int​ ​key​ ​)
{​ ​if​(​ ​!key​ ​)​ ​return​ ​3​;​ ​return​ ​(key​ ​-​ ​1​)​ ​/​ 3​ ​;​ ​}

0​ ​=>​ ​int​ ​i;


int​ ​r,c,n;

// go!
while​ ​(i​ ​<​ ​7​)​ ​{
​.​5​ ​=>​ ​row.gain;
​.​5​ ​=>​ ​col.gain;
​Math​.random2(​0​,​3​)​ ​=>​ r ​ ;
​Math​.random2(​0​,​2​)​ ​=>​ c ​ ;
​1​ ​+​ ​r​ ​*​ ​3​ ​+​ ​c​ ​=>​ ​n;

​if​ ​(n==​11​)​ ​0​ ​=>​ ​n;


​if​ ​(n==​10​)​ ​{
​<<<​ ​r​ ​,​ ​c,​ ​"*"​ ​>>>;
​}
​else​ ​if​ ​(n==​12​)​ ​{
​<<<​ ​r​ ​,​ ​c,​ ​"#"​ ​>>>;
​ }
​else
​<<<​ ​r​ ​,​ ​c,​ ​n​ ​>>>;

​rows[r]​ =​ >​ r​ ow.freq;


​cols[c]​ =​ >​ c​ ol.freq;

​0​.​1​ ​::​ ​second​ ​=>​ ​now​;


​0​.​0​ ​=>​ ​row.gain;
​0​.​0​ ​=>​ ​col.gain;
​0​.​05​ ​::​ ​second​ ​=>​ ​now​;
​i​ ​+​ ​1​ ​=>​ ​i;
}

// another candidate for lamest demo

// patch
SinOsc​ s => ​JCRev​ g => ​dac​;
.​5​ => g.gain;
.​075​ => g.mix;

// note number
20​ => ​float​ note;

// go up to 127
while​( note < ​128​ )
{
​// convert MIDI note to hz
​Std​.mtof( note ) => s.freq;
​// turn down the volume gradually
.​5​ - (note/​256​.​0​) => s.gain;

​// move up by whole step


note + ​2​ => note;
​// advance time
.​125​::​second​ => ​now​;
}

// turn off s
0​ => s.gain;
// wait a bit
2​::​second​ => ​now​;

// karplus + strong plucked string filter

// feedforward
Noise​ ​imp​ ​=>​ ​OneZero​ ​lowpass​ ​=>​ ​dac​;
// feedback
lowpass​ ​=>​ ​Delay​ ​delay​ ​=>​ ​lowpass;

// our radius
.​99999​ ​=>​ ​float​ ​R;
// our delay order
500​ ​=>​ ​float​ ​L;
// set delay
L::​samp​ ​=>​ ​delay.delay;
// set dissipation factor
Math​.pow(​ ​R,​ ​L​ ​)​ ​=>​ ​delay.gain;
// place zero
-​1​ ​=>​ ​lowpass.zero;

// fire excitation
1​ ​=>​ ​imp.gain;
// for one delay round trip
L::​samp​ ​=>​ ​now​;
// cease fire
0​ ​=>​ ​imp.gain;

// advance time
(​Math​.log(.​0001​)​ ​/​ ​Math​.log(R))::​samp​ ​=>​ ​now​;

2.)​ ​echo.ck
// feedforward
adc​ => ​Gain​ g => ​dac​;
// feedback
g => ​Gain​ feedback => ​DelayL​ delay => g;

// set delay parameters


.​75​::​second​ => delay.max => delay.delay;
// set feedback
.​5​ => feedback.gain;
// set effects mix
.​75​ => delay.gain;

// infinite time loop


while​( ​true​ ) 1::​second​ => ​now​;

***For more information about ChucK, contact either me or our programming instructor at
gorbatovsarah@gmail.com​ / ​aryeh.laufer@theideaschool.org​***

You might also like