What Is Algorithmic Composition? Let Us Begin at the Beginning
Total Page:16
File Type:pdf, Size:1020Kb
A Csound Algorithmic Composition Tutorial Michael Gogins 11 August 2009 Introduction This tutorial will teach you, step by step, how to do algorithmic composition using Csound and the CsoundAC Python extension module for algorithmic composition. You should be prepared with some basic experience in music composition, computer programming (even if it is only writing a few scripts or spreadsheets), and software synthesis (preferably using Csound). But above all, you need to have a strong curiosity about algorithmic composition (also known as generative composition or score generation) from a musical ± not technical ± point of view. This section briefly introduces basic concepts and definitions, provides some references to external resources for algorithmic composition, and presents a series of historically based, tutorial compositions demonstrating basic techniques of composing with algorithms. These pieces are: The Musikalisches Wuerfelspiel (musical dice game) of 1787 and variations upon it (Chuang, 2007). Automatic generation of counterpoints to randomly generated cantus firmi, based on the work of Lejaren Hiller (Hiller & Isaacson, 1959) and Bill Schottstaedt (Schottstaedt, 1984). Transpositions of star positions and spectral data onto scores, based on John Cage's Atlas Eclipticalis (Cage, Atlas Eclipticalis, 1961). Sustained drones with beating combination and difference tones, inspired by the work of LaMonte Young (Young, 2000). Fractal music, inspired by the work of Charles Dodge (Dodge, Viola Elegy, 1987). Minimalist music, based on the principles of Terry Riley's In C (Riley, 2007). All of these tutorial compositions use Python with the CsoundAC module for both composition and synthesis. All required Csound software, SoundFonts, and instrument definitions are included. All soundfiles are rendered in stereo with floating-point samples at 44,100 frames per second and 1 control sample per audio sample frame, for high-resolution sound and high-precision performance. The text provides detailed instructions that should enable you to create each piece by writing code from scratch, but pre-written and tested versions of each piece can also be found in the MusicProjects directory. It is assumed that you are working on Windows XP, but similar steps would obtain for Linux or OS X, except that at the time of writing, on OS X you would first need to build CsoundAC on your computer from Csound CVS sources. What is Algorithmic Composition? Let us begin at the beginning. What is an algorithm? What is composition? The technical definition of algorithm is just: A definite procedure. Definite simply means there are no ambiguous steps. Someone who does not understand the field in the least can still perform the algorithm correctly, by following directions one step at a time, and that is why computers can automate the performance of algorithms. Definite is not at all the same thing as deterministic. Flipping a coin produces a perfectly random sequence ± but it is still a perfectly definite procedure. Examples of algorithms include cooking recipes, MapQuest directions, the steps children are taught for doing long division or taking square roots, and all computer programs. Philosophers and mathematicians have proved that general-purpose computers, such as your own personal computer, are universal in the sense that they can perform any algorithm that any other particular computer can perform (as long as they have enough time and enough memory), if necessary by running a program that simulates the other sort of machine. Another term for universal is Turing-complete. There probably are many ways of making a computer (or a computer language, for that matter) Turing-complete; but in general, if a computer or language implements all of a rather small set of basic instructions, it is Turing-complete. These instructions include reading or writing a value to an arbitrary memory address, interpreting such a value as an instruction and carrying it out, performing the logical operations AND, OR, and NOT on such values, and performing the instruction at one address if a logical expression is true, but at another address if it is false (branching). Philosophers and mathematicians also go further, and assume ± and to date there is absolutely no evidence to the contrary! ± that anything at all that can be computed, can be computed by a universal computer. The technical term for this assumption is the Church-Turing thesis (Kleene, 1967). There is no known counterexample to the thesis, and it is widely accepted, but it has never been proved. The question of its truth has been a central question of philosophy since the 1930s. Proof or disproof would revolutionize our understanding of logic, mathematics, computer science, and even physics. For a brilliant exposition of these things that cuts to the heart of the matter ± there are so infinitely many truths, that almost none of them can actually be proved -- see (Chaitin, 1998). What is composition? Composition is the combination of distinct elements or parts to form a unified whole; in this context, the art or act of composing a work of music. Algorithmic composition, then, is the art or act of combining distinct elements or parts to form a single unified work of music ± using an algorithm. Commonly, there is an implication that the algorithm is run on a computer, which enables the composition of music that would be tedious or even impossible to compose by hand. But running on a computer is not necessary to the definition. The first algorithmic compositions far predate computers and so were of course composed by hand, and algorithmic compositions are still being composed by hand. An outstanding recent example of an algorithmically composed piece produced completely by hand is Leonid Hrabovsky©s Concerto Misterioso (1993). It is of course also possible to generate scores by means of a computer, but then print them out in music notation and play them, as Bruce Jacob (2009) has done. But for the sake of speed and self-sufficiency, the approach taken in this book is both to generate, and to render, scores using a computer. Philosophers and mathematicians have also proved that computers can©t write their own programs. Or rather, the proof goes: If computers do write programs, they can©t always debug them. The technical term for this is the halting theorem (Turing, 1936). Actually it is possible for computers to write algorithms using evolutionary programming, but so far at any rate, the problem domains suited to evolutionary programming are rather small ± extremely small, compared to the vast possibilities of musical composition. In music, the fitness function would have to be either a good algorithmic model of educated musical taste, a daunting problem to say the least; or an actual panel of educated and discriminating human listeners, perhaps an equally daunting prospect. (For an introduction to the field see (Banzhaf, Nordin, Keller, & Francone, 1998); for an eye-opening exploration of the creative possibilities of evolutionary programming, including musical applications, see (Bentley & Corne, 2002); for an open-source Java program that evolves graphical designs using various algorithms, see (Jourdan, 2004); for an introduction to genetic programming for musical composition, see (Miranda & Biles, 2007).) But the decisive point is that even the genetic algorithm still requires a programmer to set up the algorithm and define a fitness function before it begins to evolve solutions ± so the setup as a whole is still a program that still needs to be debugged, and that cannot always debug itself. In short: Computers execute algorithms, programmers write them. Therefore computers don©t, and can©t, do algorithmic composition. Only composers who program do. Now the interesting questions begin. First, why bother? Composers already hear music in their heads, and write it down. No need for computers or algorithms there. But even the greatest composers have limited imaginations. Perhaps they can imagine a work of music whole and write it down from memory, but that still takes time, and even for the greatest composers, changes in style come slowly. Perhaps the imagination depends upon unconscious templates that constrain the possible elements and their combinations. Certainly the imagination can hold only a limited number of elements in mind at the same time. Perhaps algorithms could run much faster, or generate new templates and new styles as easily as they generate pieces, or hold more elements together at the same time. In other words, algorithms might offer, at least in principle, a means of transcending some of the limitations of the human mind. So, what kind of music can composers with computers compose, that composers without computers can©t? Many thinkers have observed that music lends itself to mathematical analysis, beginning with the definition of musical intervals as Pythagorean ratios. For centuries, the rules of voice leading and harmony, and especially canonical forms such as rounds and fugues, have been stated in the form of algorithms. So music seems by its very nature to be suited to an algorithmic approach. The differences between the human imagination and computer algorithms further suggest that algorithms can be used to make works with more notes than composers can keep track of; works with polymeters like 173/171; works where each level of time has to perfectly mirror every other level of time; works that specify a tiny grain of sound for each star in the sky; works where rhythmic canons have