Experience algorithmic composition in the language of ChucK
For the whole week (January 23-31, 2018), an exhibition was held at the Dar art gallery (Pskov), announced with the help of the program in Chuck. I will try to tell why and how it all happened.
Small preamble needed
It so happens that facebook activity develops into something more; This is how the original “Post-Historic City of P.” project was formed - an online community, sometimes, however, going to offline promotions . According to the materials of the community, in September 2017, the book “The Post-Historical City P. Anti-guidebook” was published, of which I was one of the authors (and publishers). More information about the book can be read on the links below, but for now it suffices to say that it is a collection of photographs and texts, something like a catalog that mythologizes the boring concrete reality of the modern city.
Somewhere in the fall, the idea of ​​the exhibition, the greatest hits large-format collection based on the book, as well as something that was not included in the book, was born. Then the thought appeared to voice the space in which the images and texts would be located, with the sounds of the city. Without delaying the case indefinitely, Dmitry, my co-author, armed with the appropriate device, went to wander around the city of P., recording noises, conversations, squeaks and rustles. The result was something about one and a half hours of raw sound from different places of the city.
')
Then, as usual, avrala began at work, business trips, other interesting activities, the New Year, finally, and when suddenly the issue with the exhibition was resolved - unexpectedly quickly - it turned out that after a couple of weeks you need to have a ready sound.
Implementation
Initially, I wanted to do something unrecorded, unpredictable - not just chop and glue ready sounds, but so that they overlap each other and live their life as it were. I knew practically nothing about ChucK at that time, but on the first examination it seemed to be a suitable tool - familiar language constructs, classes with inheritance, multithreading for nothing, the ability to work with audio at a rather low level. After listening to the Kadenze lectures at a fast pace over several evenings, on weekends I sat down to implement the project.
The structure as a result was the following:
random landscapes of sound landscapes flowing into each other - environment, background on which everything happens
events - individual cues or sounds that also occur randomly using a set of simple effects (reverse play, echo, “robot”, acceleration / deceleration)
"Bits" - a set of fairly standard electro / hip-hop patterns voiced by squeaks, sobs, replicas, cut from the original sound
a simple granular synthesis on a small set of individual sounds: a small piece is played from random places of the original file, each time is different
The resulting composition was a good addition to the exhibition: while a person looks at a photo and reads the text, from the speakers placed on the ceiling, you can hear, for example, the echoing sound of the yard, distant children's voices, then suddenly some strange remark appears, spinning, moving away and accelerating Or there is a nervous hiccuping bit against which a synthesizer rustles with fragments of someone else’s voice. All this, of course, is happening in an unpredictable way, and you never know what will sound the next moment.
As a music, this is quite a cruel thing in relation to the listener, but as a background, accompaniment, the result was quite satisfactory. No less regular and no more schizophrenic than the surrounding panel daily life, this sound environment creates exactly the effect that we needed: not to plunge into the reality of the city of P., but to get out of it, look from the outside, be surprised and ponder.
I will not analyze the source code here - who wants, can read it on GitHub , nothing complicated there. To run and listen, just download and install ChucK and run run.cmd from the root folder. Everything - development and playback - was done under Windows.
Buns and charm
One of the most elegant things in ChucK is a self-titled overloaded operator that looks like “=>”. Yes, assignments (and, accordingly, initialization with the declaration of variables) look a bit unusual:
0 => int i; "test" => string message;
at first you mechanically confuse the right and left sides. But how beautifully the objects are connected. Suppose we want to take a sound file, add reverberations, adjust the volume and output the result to a separate channel. In this case, a simple intuitive chain is built:
SndBuf sound => JCRev reverb => Gain master => Pan2 pan => dac;
Further, you can adjust the necessary parameters - since we are still not working with time, all this does not sound yet.
The handling of time is another elegantly made piece of ChucK. Expressions that calculate time look like “number :: unit of time”. For example:
1::second 1000::samp 2::day (x + y)::minute
and so on. To hear any sound, you need to determine how much it will sound. The chuck operator is also used for this:
1::second => now;
Such an expression is called “advance time” - for some reason I like to translate it as “take time”. Thus, to make the first sound on ChucK, you need to do the following:
Another beautifully implemented thing is creating threads (in ChucK terminology, shred). In order to create a new “shred” the keyword “spork” and the special operator “~” are used. Here's what it looks like:
In general, I do not intend, of course, to write here “ChucK for beginners”; I think these examples are enough to interest those who may be interested.
Glitches and frustrations
With all the simplicity, friendliness and intuitiveness, in ChucK (at least under Windows - maybe with other platforms things are better) there are also problems.
The development environment - miniAudicle - of course, is not very suitable for such. Yes, there is syntax highlighting, device overview, virtual machine control, console. But - not even an elementary search / replace. Moreover, it periodically crashes with an error - for example, if you forget to put @ in the assignment operator by reference “@ =>” - and if at this moment the console window is not visible, then there is no way to understand what the problem is.
In ChucK, there are classes with inheritance, and this is very cool - but there are no constructors in them, which is somewhat frustrating. Generally, when I started writing code myself, some cognitive dissonance arose - if quite complicated things are done in ChucK simply, then as for simple things - like working with strings - not a word in the documentation. It turned out that there is another documentation where there is a certain amount of information about standard libraries.
At first I did the stream for each type of sound, and tried to reuse SndBuf objects - but it turned out that after some time, first, some cracking starts to appear during playback, and secondly, some effects are not turned off, but accumulate despite all my efforts to reset them.
As a result, I came to the construction when each event creates a separate shred, where all objects are recreated and then deleted. However, it turned out that they are not deleted - the claimed garbage collection, apparently, is far from perfect, and during playback, the process gradually eats up all the available memory. I couldn’t overcome this problem in the allotted time, so I just asked the gallery workers to restart the executable file from time to time.
In general - ChucK makes a very pleasant impression, for a quick draft, a small project, a demonstration - the very thing. But if you have conceived a more serious project - it is worthwhile to weigh the pros and cons, in some places ChucK is still damp.
Documentation This is far from complete documentation. Surprisingly, there is not a word about the basic things that are likely to be needed, such as working with strings or file I / O.
Other documentation . This material partially overlaps with the previous one, but also - which is very valuable - fills in the gaps with respect to standard libraries.
Course on Kadenze . To listen to lectures registration is required, to complete assignments and obtain a certificate you need to pay. This course is designed for people with no programming experience, so having such a place will be boring. But then you get a lot of valuable information about ChucK almost from the first hands.
Book "Programming for Musiciands and Digital Artists" . The book contains approximately the same information as the video course. Those who come from Kadenze are given a discount; but at the same time, the full version of the book is easy enough to download in pdf