ChucK - programmable sound

There are a great many programming languages: from mainstream to esoteric, from educational to highly specialized. And if many of us are familiar with the mainstream in one way or another (at least at the basic school level), then programming languages ​​designed to perform special tasks remain mysterious for many. Let's open the curtain a bit and see, even with one eye, the world of programming ... music!

So, our guest today, ChucK , invented by Perry Cook and Guy Wang from Princeton University in 2003, the latest version was released in 2009.
ChucK is one of the programming languages ​​designed to write music, synthesize sound in real time and organize the interaction of various specialized peripherals.


ChucK is an interpreted language. Natively supports the parallel execution of several threads (the so-called "shreds") of the program, and the shreds are executed in accordance with certain cycles (sample rate, control rate), which allows them to be synchronized by Chuck himself. By the way, in the description of the authors it is said that “ChucK is on-the-fly programming language”, which in fact allows you to make changes to the program right at the time of execution and allows some to do amazing things on stage. (Yes, yes! Geeks scribbling code on the stage that immediately turns into music is a reality!)
ChucK is a multi-paradigm language with strong typing of data and not quite ordinary syntax related to the peculiarity of the field of application (more on this later). It is most convenient to approach Chuck from the perspective of OOP, especially for those who have already encountered modular synthesis studios.

Let's start

Distributed by ChucK under the GNU GPL and is available for Windows, Linux, Mac OS X, and more recently, iOS (with closed source).
To get started, get the tools. For the necessary software, go here .
Using the link, you can find the console interpreter binaries for Mac OS X and Windows; for Linux, source codes for self-compilation are presented (with all the necessary instructions, so even a beginner can figure it out). But notepad + console is not the most convenient bunch, for comfortable work we need a development environment. There are two options to choose from:

• miniAudicle - editor with syntax highlighting, debugger and virtual machine in one bottle. It’s already in beta, so get ready for a lot of surprises. For example, I (and not only) failed to assemble this craft under Linux with JACK support, and on Windows I had to manually demolish the miniAudicle.exe process when exiting, because The program does not complete correctly.

• Audicle - an experimental modular development environment, may seem more convenient to those familiar with Max / MSP. However, for those who are used to working in classic IDEs, Audicle will seem obscure. In addition, it is even more raw and buggy than miniAudicle.
I personally settled on the first option due to greater stability and greater (subjectively) convenience. Screenshot

There is no version for iOS on the site, probably it can be found in the AppStore. I will not dwell on the assembly and installation of the necessary software, I hope that anyone who wants to figure it out on their own, since all the instructions on the site are there, and educated people are sitting on the hub. For those who still have difficulties in the end, I will give a link to the forum of Chakists.


Before writing the code, let's agree that all the actions we have will be performed in the miniAudicle program. Before work, start the virtual machine (ChucK -> Start Virtual Machine in the main menu of the program). The shred is launched by the big green Add Shred button, and the stop by the red Remove Shred button. If your shred is executed, and you click "Add Shred", you thereby add another copy, to restart there is a button "Replace Shred".
So. Where is it customary to start getting acquainted with a new programming language? Well, of course, from the banal "Hello, World!":

<<< "Hello,World!" >>>;

The not quite ordinary syntax is explained very simply: Chuck is simply not designed to work with standard text output and what is enclosed in <<< >>> characters is, in fact, an output of debugging information. Let's look at the following example: Pay attention to the notation of real numbers. Such a record is not mandatory, but it is used in the documentation. By the way, here is the first example of a "not quite ordinary" syntax, the operator =>.

.5 => float hello; // вещественной переменной hello присваивается значение 5

The => operator is called chuck, and it does more than just an assignment operator. In fact, it plays the role of a connecting cord between objects, and assignment will be only one of the special cases of “connection”. For example, a model of a classical synthesizer written using this construction would look like this: 440 => Oscillator => Envelope => Filter => AudioOut.
Let's try to figure this out with such a typical example (and at the same time, we’ll figure it out in relation to time intervals):

SinOsc S => JCRev R => dac;
.2 => S.gain;
440 => S.freq;
.3 => R.mix;

5::second + now => time later;

while( now < later )
1::second => now;

Try running this piece of code. You will hear 5 seconds of a 440Hz sine wave passed through the reverb. Let's take it in order. The following construction is presented in the first line: an instance of the sinusoidal oscillator S is initialized, then, using the => operator, the signal is sent to the JCReverb R reverb instance, and from it the signal is sent to dac (standard sound output in ChucK). In lines 2 and 3 we set the sound parameters: gain - volume, mix - the degree of mixing of the original (so-called dry) sine wave and the signal processed by the reverb. Just like in life: we hear both direct and reflected sound. (A reverb simulates reflections from surfaces, allowing you to achieve a sound effect in any room). In S.freq - frequency is set.
And then the fun begins. The fact is that in Chuck there are two special data types for controlling synchronization and some other needs. This is type time and type dur (duration). Type time is absolute time, and dur is relative. The line we count 5 seconds from the current moment (a special variable now (of type time) serves to determine the current time) and assign this value to the later variable. As it’s not difficult to guess, there follows a cycle, each step of which is carried out for a strictly defined period of time (here, in one second). Here, this cycle is given for clarity of reference to time, and in a real situation the same thing will be written much easier:

5::second + now => time later;

SinOsc S => JCRev R => dac;
.2 => S.gain;
440 => S.freq;
.3 => R.mix;
5::second => now;

Time can be set not only in seconds, but also in samples, milliseconds, minutes, hours and even days, weeks and years. Here, the developers clearly approached the subject with humor.

Perhaps enough

This concludes our acquaintance with Chuck. I think this is enough as an introduction. I will only add that ChucK is not limited to simple synthesis. It allows you to work with the MIDI protocol, external audio files and sequencers.

For those who want to continue acquaintance, I
’ll add some useful links: - the official language specification, it is highly recommended that you read - wiki
chuck / doc / examples - code examples. (Also, the manual in pdf and many examples can be found in the folder with miniAudicle.) is a small, but almost the only living community of Chakists.

In Russian, unfortunately, there is no useful information at all.

In fact, ChucK is not the only PL specifically designed for sound extraction, there are other solutions, including purely commercial and more friendly ones. For those who want to get involved, but to whom Chuck seems too complicated to master (although in fact, there is nothing complicated, the main thing is to get involved and figure it out) or is not suitable for other reasons, you can advise other solutions: wiki / Audio_programming_language
And if you suddenly want to join the development, look for ChucK at

Also popular now: