The logistic map is maybe the most-often used example system for the transition from periodic behavior to chaotic behavior. It’s simple to understand, simple to treat on paper and in the computer, but the behavior is rich and various, see picture. Now, for some time I was wondering if there would not be a way to listen to chaos, and not just look at it. In this post I will show (or make audible) how I use python real time interactive simulation coupled with pure data to create live sound samples from logistic map iterations. I know it’s one for the nerds, but if you understood this, you’re probably drooling now…

Periodic orbits of the logistic map for different parameter values.
Periodic orbits of the logistic map for different parameter values.

So, we are looking at two pieces of software, both running live and coupled through two TCP/IP socket connections. (Not that I would know all too much about sockets, but I made it work. Mostly.) To get a rough idea of what’s happening, we should talk about the separate pieces first.

Python real time simulation: The logistic map is a pretty straight-forward update process: x_{n+1} = r x_n(1-x_n). To make it audible, I want a click sound produced for each iteration, and wait for a time x_n in between this and the next n+1 click sound. Very simple, I run a never-ending while loop in python, in each loop the next x_{n+1} is calculated, and then the code waits for a time proportional to x_n. Now, the socket connections come into play. In each step, python checks for incoming messages that might reset the parameters of the iteration, and sends a timed click signal with the x_n value to pure data.

pure data click sound creation: pure data is also listening to incoming messages on a receiving socket. When a message comes in, it sends a click to the speakers, while partitioning the signal to the left and right audio channel according to the value of x_n.

pure data remote-controlling python: Here is where the real magic is happening. In pure data I included two fader controls, which regulate the r parameter of the logistic map, and the overall speed of the clicks to be produced. When these are changed, a message is sent from pure data to python via the socket connection. In each iteration step, python retrieves all the messages sent to it and adjusts its simulation parameters accordingly. Here we are: python and pure data both running live and speaking to one another in a two way connection. Beautiful.

Pure data patch and python console screenshot
Pure data and python running in parallel and communicating over two socket connections. The white windows are the pure data patch (left, with two faders for control of the simulation) and the pure data main window. The bottom left is my linux terminal displaying live output from the python simulation. Yes, it was also quite late already.

Here is what it sounds like: These are six examples of live sampling from the logistic map. The first five are short samples at constant values of r. Look at the graph above at the given r values, you might be able to connect the patterns in sound with the visual patterns.
In the sixth, last one I show the live control capabilities. First, I start at r=2.75 (same interval between all beats) and increase r all the way up to 4. This takes us through period doubling (occurrence of several repeating intervals between beats) all the way into chaos at  r=4. Then, I increase the speed of the simulation, and go back down to r=2.75. In terms of the graph, that means I start all the way at the left, then go all the way over to the right, increase the simulation speed, and then go back all the way to the left.

Sounds like: When this is taken to perfection, you might arrive with Autechre. This track is especially striking, while the whole album is great. If still alive after the first listen, you will likely want it again, 100 times.

The code? Sorry, too ugly to be published. Another time maybe, when I understood better what I am doing there. Or e-mail me.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s