Getting ChucK running
Welcome to ShredQuest, a series where we build a groovebox from scratch in ChucK. If you write code but have never touched audio, this is written for you. No music theory, no DSP maths you have to take on faith.
Quick word on why ChucK and not something you already know. In most languages, audio is something you hand to a callback and hope for the best. Your code runs, a buffer gets filled, and the actual timing of things is somebody else's problem. ChucK does the opposite. Time is a value you control directly, down to the individual sample, and that turns out to change how you think about the whole problem.
By the end of this series you'll have a working groovebox: multiple tracks, a synth voice you wrote yourself, patterns you can edit while the music is still playing. We'll get there one chapter at a time, and every chapter adds to the same file.
Installing it
Grab the release from chuck.stanford.edu/release. There are installers for macOS and Windows, and on Linux you can build from source or use your package manager. This series is written against ChucK 1.5.5.7 or newer. That matters more than you'd think, and I'll explain why in chapter 4.
You get two things. chuck is the command-line compiler and virtual machine.
miniAudicle is a small editor with a run button and a console, which is nicer while
you're learning. Use whichever you prefer; everything here works in both.
Check it worked:
$chuck --versionYou should see the version number, your platform, and the audio driver it picked. If you see a version, you're done.
Your first file
Make a file called groovebox.ck. That .ck extension is what ChucK source files use.
This one file is the thing we'll grow across the whole series.
// a sine wave, straight into the speakers SinOsc osc => dac; 440 => osc.freq; 2::second => now;
Run it:
$chuck groovebox.ckA clean 440 Hz tone for exactly two seconds, then silence and the program exits. Not two seconds and a bit. Exactly two.
Four lines and there's already a lot going on, so we'll pull it apart properly in the
next chapter. For now just notice that => shows up three times doing what look like
three completely different jobs, and that the program ended on its own without you
telling it to stop.
If you hear nothing
Run chuck --probe. It lists every audio device ChucK can see, each with a number. Pick
the one you actually want and pass it in:
$chuck --dac2 groovebox.ckThere's also chuck --silent, which runs your program with no audio device at all.
Useless for hearing things, very useful when you only want to check that the code
compiles and the timing is right. I use it constantly.