Cellular automata are a powerful computational formalism. Stephen Wolfram’s book A New Kind of Science provides a thorough study of these devices. Not surprisingly, Wolfram Mathematica has great support for working with them.

For example, the following figure shows the evolution of Rule 30 over 50 steps, plotted using ArrayPlot function (in Mathematica):

Cellular Automata

Using cellular automata for generating music is not new. A google search throws up many papers and articles on this topic. Wolfram Tones  gives a nice example of the idea.

The latest version of Opusmodus has introduced a function cellular-automaton for tracing the evolution of a primitive automaton over a given number of steps, starting from an initial condition. For today’s post, I wanted to generate music in Opusmodus using this new function.

Here is what I have done in a nutshell. I generate a 50-step evolution of rules 26 and 30 each, starting from the initial bit vector (0, 0, 0, 1, 0, 1, 0, 0, 0, 0). One of the two is randomly chosen to serve as the basis for our score. Additionally, I randomly choose 10 consecutive rows of the active element (each row maps to a bar of synthesised music). Both these tricks guarantee that different music is generated each time you run the program.

The bit vector corresponding to a row is converted into a sequence of note lengths, 1 becoming a 1/16th unit and 0 becoming a rest for the same duration. Just to make this a bit interesting, I use three tracks, comprising Bass Drum, Glockenspiel and English Horn. The rhythm for all instruments is derived from the same evolution vector. For the non-percussion instruments, I select random pitches from mela-kokilapriya (an Indian scale) and pentatonic-blues.

CA in Opusmodus

What I have done is just one of the innumerable possibilities of using CA for music. Nothing out of the world here, but an interesting idea that can be used in a larger (more realistic) project!

Here is the source code and here is a sample midi file generated from a single run of the program.