This is the first of (I hope…) series of tutorials on using great Overtone library for turning your computer into a musical instrument with Clojure.
Today we’ll recreate Daft Punk’s “Da Funk” main theme. The track which had a huge influence for me (and many more) entering the world of electronic music. It’s really simple but how huge!
At the end of this tutorial we’ll create this phrase:
EDIT: Based on HN/Reddit comments about some errors in my synth definitions making main theme sounding a lot different that the original I made some changes to this post. I left the corrections in the text, but code and sound samples are now updated. Thanks for all the suggestions!
The nice thing about Daft Punk is that they “open sourced” a large amount of their music. You can find midi notes, loops, acapellas and beats for many of their songs (including Da Funk) on a site called Daft Club. The track is also the subject of many YouTube tutorial videos, and appears in Mitchell Sigman’s Steal this sound which make a perfect one to recreate using Overtone.
So from the midi file from Daft Club we can get these notes:
The key is
F major G minor and BPM is 110.
To recreate the melody I’ll use Leipzig - superb library which provides a DSL for constructing melody as data structure.
The base is
phrase function which takes two sequences: durations and pitches (as degrees of a given scale). So as we’re in
F major, F is 0, G is 1, A is 2 G minor, G is 0, A is 1, Bb is 2 and so on. If you want a pause, just use
nil as pitch, but remember to handle it carefully later.
Now let’s create instrument:
So we use a saw-wave with
half of frequency (one octave down) original frequency and add some attack and release to amplitude envelope shape.
Now we need to tell Leipzig that part
:da-funk should use
Finally, to play a melody we need to convert from midi notes to hertz and specify song tempo:
You should hear something like this:
OK, let’s shape the sound a bit. Let’s add second saw oscillator detuned by 5 semitones and mix them together:
0.749 is a ratio of
adding subtracting 5 semitones in hertz. This should sound like this:
To create the “wah-wah” effect we need to apply a band-pass filter on the sound from oscillators:
So we increase resonance a bit (0.6 vs. standard 0.5) and use center frequency of 2200 hertz. Then we apply a filter envelope: add attack and release of 0.5 and scale the envelope to half of note duration. You can of course experiment with these settings.
And finally let’s add some distortion - we could install
fx-distortion on our instrument, but since it’s integral part of the sound, let’s just inline it:
The drum pattern is a classic 4x4:
We can also use Leipzig to construct the drums - it’s actually taken from whelmed repo from Leipzig’s author Chris Ford.
First, we need to create drum kit player:
kit is a mapping from drum name to actual drum sound preloaded:
Again - the drum samples are taken from Daft Club resources.
We just need a helper
tap function to program a sequence of a single drum
Now we are ready to construct the beat:
So we play fat-kick with kick every beat, snare every odd beat and hihats in the middle. Nice usage of Clojure collection framework.
To play only drums we need to recreate track like this:
And finally, to mix the synth with drums we need to use
That’s it! This approach needs a little bit to understand, but it’s really powerful in terms of representing simple songs. Also, it plays really well with live coding, which I plan to show in one of the next tutorials.
EDIT: I’m aware that my version differs from the original song. I’m doing this blog mainly for fun and does not state that this approach could lead to a professional sounding tune.