Undertone – Programmable music in F#

Recently I sent a bit of time playing with Overtone. I’ve always been interested in music, but have little talent when it comes to playing instruments, so I really like the idea of a DSL for creating music. I was also inspired by one of my Christmas presents The Wave Watchers Companion to explore relationship between waves and sound. A secondary aim of playing with overtone was to learn a bit more about Clojure which is definitely one of the most interesting languages about at the moment. I tried to resist the urge to port it F#, just enjoy learning about Clojure, but many of the ideas that make Overtone fun would work well in F#, so I couldn’t resist giving it a go. Especially when I released that if I combined it with the technology behind tryfsharp.org which would mean people could just browse to a web page and start creating music immediately. To try Undertone click this link or the below screen shot:

To say Undertone is a port of Overtone is probably a little unfair. Undertone takes a few ideas from Overtone and reimplements them in F#. Perhaps the biggest difference is that Overtone is uses the SuperCollider synthesis engine to generate sounds, where as Undertone has it’s own generation engine based on some work by Charles Petzold on creating a sequencer in Silverlight. In Undertone a note or a tune is just a seq<float> (that’s IEnumerable<Double> for the C# folks) that oscillates between –1.0 and 1.0. Undertone provides 3 things, functions to help you generate individual notes – these are in the Undertone.Waves.Creation module, functions to transform notes – these are in the Undertone.Waves.Transformation module, and Player to play a sequences of notes – the Undertone.Player class.

So the creation of a note in Undertone would look something like this:

let myNote note octave =
    Creation.makeNote Creation.sawtooth 0.2 note octave
    // apply transformations to you're note to adjust the way it sounds
    |> Transformation.flatten 0.8
    |> Transformation.tapper 1.0 0.3

This note can then be visualized using F# Chart and looks like this:

One you have a note you’re happy with it’s then easy to sequence them using F#’s list comprehension syntax:

let tune =
    seq { yield! myNote Note.C 5
          yield! myNote Note.G 4
          yield! myNote Note.E 4
          yield! myNote Note.C 4
          yield! myNote Note.G 3
          yield! myNote Note.E 3
          yield! myNote Note.C 3
          yield! myNote Note.E 3
          yield! myNote Note.G 3
          yield! myNote Note.C 4
          yield! myNote Note.E 4
          yield! myNote Note.G 4
          yield! myNote Note.E 4 }

// play the tune
let player = Player.Play(tune, Repeat = true)

Although you can already make some interesting sounds with Undertone the project is in it’s infancy and there’s quite a few bits missing, notably:

- As there’s no direct way to port the sound generation technique used from Silverlight to .NET so there’s no way to play your tunes in the desktop version of F# interactive. This shouldn’t be that difficult to overcome, its just means writing a new .NET sound generation engine.

- There’s no way to visualize notes in Silverlight, so it would be nice to add a visualization capability

- More wave generation and transformation functions would be good, perhaps including functionality to extract real waves from WAV files, or other formats.

If your interested in improving the project, or just looking at the source, it can be found on github.

The name of the project, Undertone, was inspired by Overtone itself with a nod to Northern Irish punk rock band The Undertones.

dotnetkicks+, digg+, reddit+, del.icio.us+, dzone+, facebook+

Print | posted @ Friday, January 27, 2012 3:35 AM

Comments on this entry:

No comments posted yet.

Your comment:

(Note: all comments are moderated so it may take sometime to appear)

Italic Underline Blockquote Hyperlink
Please add 7 and 5 and type the answer here: