ChucK: Scripting For Music Composition and Sound Synthesis. January 17, 2018 by Riston Leave a Comment The ChucK programming language was developed by Stanford University’s Dr. Ge Wang, under the supervision of Dr. Perry Cook, for the purpose of music composition and digital signal processing. The ChucK language distinguishes itself from other similar languages by providing a simple, yet elegant, syntax that is both easy for artists that are new to programming yet versatile enough as a language to allow experienced programmers to design complex digital signal processing “applications”. Another of its key features is that it allows users to change code in order to alter real time performance, as well as providing a built in set of interfaces for accepting live input from analog, midi, and other digital sources. The MOOC “Programming for Digital Artists and Musicians”, which is offered through the Kadenze learning platform, is led by an active contributor to the development of the Chuck language, Director of the Music Technology program Dr. Ajay Kapur at the California Institute of the Arts. Overview of the Language and its IDE, MiniAudicle ChucK is fully functional as an Object Oriented Language, and is syntactically similar to other compiler languages such as Java and C++, in that it requires the strict declaration of data types for both variables and function parameter signatures. Fortunately, this process is somewhat simplified by allowing “string”to be a native data type, instead of having to import the string library to use in place of char arrays like in C++. The language also allows the ease of use of dynamic, multi-dimensional arrays without having to include outside container classes like in both java and C++. The language also contains the usual slew of default operators allowing mathematical operations, concatenation, plus one very unique operator: the “=>”, or Chucking operator, which covers both variable assignment plus the execution of a particular process. The language comes with two substantial libraries, the Standard Library for working with data in the program, and the Math library for performing essential mathematical computations such as exponents and trigonometric functions. The Synthesis Toolkit Library, written in C++, is also integrated into the language, and it is incorporated through the languages built-in Unit Generator (UGen) objects. UGen objects also contain a wide range of other objects, most notably various types of oscillators and effects such as delay and other filters. Many of these built-in UGen classes feature a large number of functions that can be used for manipulating basic sound properties such as frequency and amplitude, and in the case of Synthesis ToolKit objects more elaborate functions allowing for physical modeling such as pluck position, phonemes, and string tension. The standard library also allows for a host of interfaces for live performance, such as Midi, and one of the primary built-in features provides functionality for working directly with both analog-to-digital (“adc” object) and digital-to-analog(“dac” object) conversion. Another key element of Chuck is the necessity of duration, and time is integral to running any program written in the language, and a variable of duration must be “Chucked” or “=>” to “now” in order for the program to do anything at all . The language also allows the development of highly customized classes, that can composed of various unit generators, audio samples, and effects that can be chained together in highly complex arrangements modeling signal flow. These classes can also contain accessors and mutators, and the standard library includes functions for converting frequency to MIDI and MIDI to frequency to allow for simplified scoring and manipulation of object instances. The miniAudicle is the primary Integrated Development Environment for working with Chuck, and it features three essential windows: the text editor, the console monitor, and the virtual machine. The text editor includes highlighting for Chuck-specific keywords, and the header bar contains the “Start”, “Stop”, and “Add Shred” buttons which are responsible for controlling the virtual machine. Since Chuck also provides the option for working with multiple threads(shreds) and concurrency(adding “Shreds” to run concurrently is called “sporking” in Chuck), having a window showing the active processes is vital, and this is the job of the virtual machine window. The virtual machine window also shows the amount of time that each thread has been executing since it was initialized. The console monitor fulfills the basic functionality of any other IDE console. Composition Methodology ChucK’s standard library does not specify specific divisions of Common Musical Notation, such as notes defining pitch or rhythmic duration; however, through utilizing classes the composer can define musical components according to personal preference. By setting a basic tempo using duration, it is a simple process to derive and assign duration variables such as whole, quarter, and sixteenth notes, and to invoke these classes throughout the execution of the program. ChucK’s duration type allows for a time resolution as low as a “sample”, the same constant derived from the Nyquist theorem of 1/40,000th of a second, up to a week( I would posit that this lengthy duration’s usefulness would be limited to soundscape installations). Similar to common notation standards for rhythmic duration, the lack of notation indicating pitch can easily be worked out by the designer/composer. Since the standard library allows for the two-way conversion of MIDI notes and frequency values, it is easy to define a scale using an array structure where the values are MIDI pitch values. The versatility of the program also would allow the designer to define completely customized intervals using any tuning specification desired, such as designing one’s own array of intervalic ratios and applying them to a base frequency. Scoring is also highly customizable, and the use of classic programming loops and other control structures provides a versatile medium for writing and composing music. For loops and while loops can have their iterations regulated through a series of duration values, such as “beats”, and conditional statements can determine the execution of specific code blocks based on any relevant boolean expression. All of these control structures can in turn be wrapped into functions and classes, in order to divide a score into easily read sections. One of the most useful applications of ChucK; however, is its versatility as a sound synthesis engine. Using the basic oscillators and more complex STK instrument unit generators provides comprehensive building blocks for applying additive and subtractive synthesis. Arrays of oscillators can be created, and each can have its fields accessed and mutated by index. Synth pads can be created by chaining a variety oscillator and STK objects through effects and digital filters. It is easy to even design granular synths that take wav samples and partition them by divisions of ChucK’s sample duration. Final Project/Experimentation For the final project of this MOOC I was bound by substantive limitations, which while certainly not the best piece of music that I have written, was nonetheless interesting. I defined the scale as: [50, 52, 53, 55, 57, 58, 60, 49] @=> int dMin[]; which contains the essential MIDI notes for the d minor as the name implies. I generally also found it to be useful to define basic patterns as 2d arrays, making it easier to distinguish between pitch and duration values: [[2, 1, 4, 0],[0, 6, 8, 14]] @=> int bowPat1[][]; Also control structure could easily guide the execution of the score, as in this segment: Machine.add(me.dir() + “grain.ck”)=> int grainId; while (measure < 60){ if (measure < 2){} else if (measure >=2 && measure< 4){ voxPlayer(beat, voxPat1, dMin[0]); } else if (measure >=4 && measure< 6) { drums(beat, drumA, 2); voxPlayer(beat, voxPat1, dMin[0]); } else if (measure >=6 && measure< 10) { etc……….. The full code for this assignment can be viewed on Github . The initialize.ck file serves a very similar function to the traditional makefile, and the Machine object in the ChucK language provides a intuitive means to provide compiler instructions. Conclusion The ChucK programming language is extremely promising as a way to provide a new tool for musicians to not only add to their creative palette, but to work directly with sound itself. One of the benefits of using an environment for music creation and sound manipulation like ChucK is that the artist is no longer confined to the limitation of their chosen DAW, and in many cases ChucK can be interfaced with other DAWs. One of the challenges for an artist using ChucK, as with most other forms of generating computer music, is that it is difficult to incorporate a truly human feel. However, it is possible to do to a large degree, and in my personal experience I have found that ChucK works well for designing aspects to integrate into more traditional methods of music-making. Here is the final project I did for this course, a little cold and computerized, but not terrible: Final Project Also, a track on Bandcamp where I had programmed a basic granular synth to highlight the bridge toward the end of the piece: Emptiness by Toccata Nosferatu Reference: Kapur, Ajax. Programming for Musicians and Digital Artists. Manning Publications, Shetland Island, NY. 2015. *This book is supplementary to the Kadenze Course by the same name: Introduction to Programming for Musicians and Digital Artists