SuperCollider, Hello World

All Things Sound

Supercollider. My favorite language. A language for everything audio. SuperCollider has powerful tools for sound design, generative composition and synthesis. If you can hear it, SuperCollider can either create it, manipulate it, or visualize it.

How Does it Work?

SuperCollider is free, open source, software developed by James McCartney. You can read about its history and download it here.

When you open it you're presented with a text editor, a console and documentation.

The Server

SuperCollider executes much of it’s code on a server so this has to be booted before just about anything will work.

CMD/CNTRL+B (Mac/Win) will boot the server. You can also boot it from the language menu, or right click in the lower right corner of the interface and choose “Boot Server”

One common problem: While there are many different things that will keep the server from booting the most common problem I've encountered is a sample rate mismatch between SuperCollider and your audio card. If the server fails to boot check the sample rate setting in your audio preferences. On my setup the sample rate has to be 48,000Hz. Your setup may differ.

Once the server is running you can start generating audio, monitoring inputs, sending MIDI, playing files, etc.

Hello World

The first thing to know about the SuperCollider IDE is that you run statements by hitting CMD/CNTRL + Return on either an entire selection or a single line.

To print “Hello World” to the console type:

"Hello World".postln;

and at the end of this line hit CMD/CNTRL + Return

SuperCollider runs the code that is highlighted. If nothing is highlighted it will run the line you're on. A common SuperCollider convention is to include parenthesis at the beginning and the end of a block of code. Double-clicking in the editor will select the block between the parenthesis and from there you can CMD/CNTRL + Return to run you're code.

"Hello World".postln;

This isn’t really what I consider SuperCollider’s “Hello World” statement though. Since this is an audio language I think it makes sense to produce a sound.

A sine wave is probably the most basic sound you can produce. Turn your speakers down because we are not controlling amplitude at this point.

Important: Sometimes you need to kill things right away. To stop everything on the server type CMD/CNTRL + . (period). Before you run any code make sure this is under your fingers.

Type the following and hit CMD/CNTRL + Return:

{ }.play;

You should hear a sine tone of 440Hz. If you don’t the first thing to check is whether the server is running. Any error information will be in the console.

Once you hear a sound go ahead and stop it with CMD/CNTRL + .

The above statement can be written and expanded upon a few different ways:

// The equivalent statement with the freq declared.
{ }.play;

// The freq declared as an array produces left and right signals
// The second value is the amplitude multiplier
// The third value is the amplitude addition (in this case we are reducing the amplitude)
// Stereo sine waves of 440 and 442 (binaural beats)
{[440, 442], 0, 0.2) }.play;

// Same as above but using a variable
// This allows us to stop and start the sound in real time
var sound = {[440, 442], 0, 0.2) };;

// Same as above but using a SynthDef
// More on this technique later"sound", {
    var outArray;
    outArray = [, 0, 0.2),, 0, 0.2)];, outArray);


SuperCollider's basic building blocks are called UGens (Unit Generators.) The statements above use the SinOsc UGen, which generates a sine wave using a wavetable lookup. A detailed description of SinOsc and all other UGens, along with example code, can be found in the documentation.

UGens can be nested, which opens up a lot of possibilities. Our original statement can be written, nested in a panner, to produce a centered signal.

// Sine wave panned center (between 1  -1)
{, 0, 0.2), 0) }.play;

Audio vs. Control Rate UGens

So far we've used audio UGens. These are defined with the method ".ar". Control rate UGens (".kr") produce no audio output but instead act like the voltage control of an analog synthesizer.

The same statement above, with a SinOsc control UGen in place of the pan value, will pan the sound back and forth as the sine value goes between 1 and -1. The frequency of this UGen will control the speed of the panning.

// Sine wave sweeping between left and right pan
{, 0, 0.2), }.play;

You can start to see the power of SuperCollider in these nested statements. This simple statement can be expanded upon in interesting ways. Try placing the control UGen in the frequency or the amplitude. Look through the help files at the other UGens. Along with audio generators you'll find envelopes, filters, delays, noise, math, etc. The power becomes apparent very quickly.

To say I've barely scratched the surface would be a dramatic understatement. The language itself is not only complex but the possibilities are vast. My interest is primarily in generative composition. In my next post I'll talk about this and focus on some of the tools SuperCollider offers.