There are a great many programming languages: from mainstream to esoteric, from training to highly specialized. And if many of us are familiar with the mainstream one way or another (at least at the level of school BASIC), then programming languages ​​designed to perform special tasks remain for many a mystery covered in darkness. Let's open the curtain a bit and see, let it be with one eye, the world of programming ... music!
So, our today's guest,
ChucK , was invented by Perry Cook and Ge Wang from Princeton University in 2003, the latest version was released in 2009.
ChucK is one of the programming languages ​​intended for writing music, real-time sound synthesis and organizing the interaction of various specialized peripherals.

')
ChucK is an interpreted language. Natively supports parallel execution of several threads (the so-called "shreds") of the program, and the execution of shreds occurs in accordance with certain cycles (sample rate, control rate), which allows them to be synchronized by the forces of Chuck himself. By the way, the description of the authors says that “ChucK is on-the-fly programming language”, which in fact allows you to make changes to the program during the performance and gives some people the opportunity to do amazing things on stage. (Yes, yes! Geeky scribbling on the stage a code that immediately turns into music - this is reality!)
ChucK is a multi-paradigm language with strong data typing and a slightly different syntax related to the specific application (more on this later). The most convenient approach to Chuck from the perspective of the PLO, especially those who have already encountered modular synthesis studios.
Let's start?
ChucK is distributed under the GNU GPL license and is available for Windows, Linux, Mac OS X, and more recently iOS (with closed code).
First, let's get some tools. For the necessary software go
here .
The link can be used to find the console interpreter binaries for Mac OS X and Windows, for Linux you can find the source code for self-compilation (with all the necessary instructions, so even a beginner can figure it out). But the notebook + console is not the most convenient combination, 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 has long been in the beta version, so get ready for a lot of surprises. For example, I (and not only) never managed to build this crafts for Linux with JACK support, and on Windows I had to manually demolish the miniAudicle.exe process, because The program does not complete correctly.
Screenshot• Audicle is an experimental modular development environment that may be more convenient for those familiar with Max / MSP. However, for those who are used to working in the classic IDE, Audicle will seem incomprehensible. In addition, it is even more raw and buggy than miniAudicle.
I personally stopped at the first option due to greater stability and greater (subjectively) convenience.
ScreenshotThere is no version for iOS on the site, probably it can be found in the AppStore. I will not dwell in detail on the assembly and installation of the necessary software, I hope that whoever wants it will figure it out himself, all the instructions on the site are there, and educated people are sitting on the habr. For those who still have difficulties at the end I will give a link to the forum of the Chakists.
10 HELLO, WORLD!
Before stitching the code, let's agree that all actions will be performed in miniAudicle. Before work, start the virtual machine (ChucK -> Start Virtual Machine in the main program menu). The start of the shred is done with the big green button “Add Shred”, and the stop is done with the red “Remove Shred” button. If your shred is executed, and you click "Add Shred", you thereby add another copy, for restarting there is a button "Replace Shred".
So. How to start dating with a new programming language? Well, of course, from the banal "Hello, World!":
<<< "Hello,World!" >>>;
Not quite the usual syntax is explained very simply: Chuck is simply not designed to work with standard text output and what is enclosed in the symbols <<< >>>, in fact, is the output of debug information. Let's look at the following example:
.5 => float hello; // hello 5
Pay attention to the entry of real numbers. Such a record is not mandatory, but it is the documentation that is used. By the way, here is the first example of the “not quite usual” syntax, operator =>.
The => operator is called chuck, and not only performs the functions of an assignment operator. In fact, it plays the role of a connecting cord between objects, and the assignment will be only one of the special cases of the “connection”. For example, a classical synthesizer model, recorded using this construct, would look like this: 440 => Oscillator => Envelope => Filter => AudioOut.
Let's try to understand this here on such a typical example (and at the same time we will understand in relation to the 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 transmitted through a reverb. Let's sort everything in order. The first line presents the following construction: an instance of the sinusoidal oscillator S is initialized, then, using the operator =>, the signal is sent to an instance of the JCReverb R reverb and the signal goes to dac (standard audio 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) sinusoid and the signal processed by the reverb. Just as in life: we hear both direct and reflected sound. (The reverb simulates reflections from surfaces, allowing you to achieve a sound effect in a room). In S.freq - set the frequency.
And then the fun begins. The fact is that in Chuck there are two special types of data for synchronization management and some other needs. These are the time type and the dur (duration) type. The time type is absolute time, and dur is relative. String
5::second + now => time later;
we count 5 seconds from the current moment (the special variable now (like time) serves to determine the current time) and assign this value to the variable later. As it is not difficult to guess, a cycle goes on, each step of which is performed 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 will be written much simpler:
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.
Probably enough
This concludes the acquaintance with Chuck. I think this will be enough as an introduction. I will add only that ChucK is not limited to simple synthesis. It allows you to work with the MIDI protocol, external sound files and sequencers.
For those who want to continue acquaintance, I will attach some useful links:
chuck.cs.princeton.edu/doc/language - official language specification, highly recommended for full reading
wiki.cs.princeton.edu/index.php/ChucK - wiki
chuck.cs.princeton.edu/doc/examples - code samples. (Also the manual in pdf and many examples can be found in the folder with miniAudicle.)
electro-music.com/forum/forum-140.html is a small but almost the only living community of chakistov.
In Russian, unfortunately, there is no useful information at all.
In fact, ChucK is not the only PL that is specifically designed for sound extraction, there are also other solutions, including purely commercial ones and more friendly ones. For those who want to get involved, but to whom Chuck seems too difficult to master (although in fact, there is nothing difficult, the main thing is to get involved and figure out) or not suitable for other reasons, you can recommend other solutions:
en.wikipedia.org/ wiki / Audio_programming_languageAnd if you suddenly want to join the development, look for ChucK on sourceforge.net.