Music Theory and Functional Programming

Being a fan of programming languages and computation in general, I'm always looking for new abstractions and way of representing real stuff in computers. Watching Chris Ford's great talk from Clojure's conj taught me about a new abstraction - that of representing music.

First of all, this involves Clojure. Its simple syntax, along with the LISP-y "code as data" philosophy make it the perfect candidate for interesting abstractions. Then, there's the great Overtone library that allows us to describe sounds using their physical nature (i.e. frequencies of oscillating sound waves).

Using Overtone, one can find a bijection between sounds and ~approximately numerical values. I'm saying approximately because there might not be just numbers, but lists or maps containing numbers. Anyway, the idea is the same. Then, having reduced everything to the numerical domain, one can use Clojure's excellent pure functions to perform transformations on both data and code - that is, the representation of music.

This allows to experiment with both simple transformations (like changing the key) and complex musical procedures (like canons) in a really simple way, since it is all about transforming collections of numbers. I really think this representation that Chris Ford introduces is brilliant - to go into more details here would be to spoil it. Thus, I invite you to check the talk out on YouTube (embedding is disabled, so you'll have to follow the link): Enjoy!

By the way - this is in no way saying that you have to use Clojure or LISP or functional programming in general to do this. No way. Here's, for example, a Python library called pyDub that introduces some nice syntactic sugar to handle music files with ease. It's just that to me, using Clojure's library of functions on collections feels more natural and (I think) yields nicer, easier to read code.

Mihnea Dobrescu-Balaur

Building @Hootsuite Analytics. Interested in Open Source, programming languages and the Open Web. Big fan of basketball and photography. Tweet @mihneadb.

Bucharest, Romania

Subscribe to Mihnea DB

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!