神刀安全网

Recreating Daft Punk's Da Funk with Overtone and Leipzig

This is the first of (I hope…) series of tutorials on using greatOvertone 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!

TL;DR

At the end of this tutorial we’ll create this phrase:


Theme

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:

Recreating Daft Punk's Da Funk with Overtone and Leipzig

The key is F major and BPM is 110.

To recreate the melody I’ll use Leipzig – superb library which provides a DSL for constructing melody as data structure.

(require '[leipzig.melody :refer :all]) (require '[leipzig.live :as live]) (require '[leipzig.scale :as scale])  (def da-funk   (->> (phrase [2 1/2 1/2 1/2 2.5 1/2 1/2 1/2 2.5 1/2 1/2 1/2 2.5 1 1]                [1 0 1 3 -2 -3 -2 0 -4 -5 -4 -2 -6 -5 -4])        (where :pitch (comp scale/F scale/major))        (all :part :da-funk)        (all :amp 1)))

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 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:

(require '[overtone.live :refer :all])  (definst da-funk [freq 440 dur 1.0 amp 1.0]    (let [env (env-gen (adsr 0.3 0.7 0.5 0.3)                      (line:kr 1.0 0.0 dur) :action FREE)          freq (/ freq 2)          osc (saw freq)]      (-> osc (* env amp) pan2)))

So we use a saw-wave with half of frequency (one octave down) and add some attack and release to amplitude envelope shape.

Now we need to tell Leipzig that part :da-funk should use da-funk instrument:

(defmethod live/play-note :da-funk [{hertz :pitch seconds :duration amp :amp}]   (when hertz (da-funk :freq hert :dur seconds :amp (or amp 1))))

Finally, to play a melody we need to convert from midi notes to hertz and specify song tempo:

(->> da-funk     (wherever :pitch, :pitch temperament/equal)     (tempo (bpm 110))     live/play)  

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:

(definst da-funk [freq 440 dur 1.0 amp 1.0]    (let [env (env-gen (adsr 0.3 0.7 0.5 0.3) (line:kr 1.0 0.0 dur) :action FREE)          freq (/ freq 2)          osc (mix [(saw freq)                    (saw (* freq 1.3348398541700344))])]      (-> osc          (* env amp)          pan2)))

This 1.334 is a ratio of adding 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:

(definst da-funk [freq 440 dur 1.0 amp 1.0 cutoff 2200]    (let [env (env-gen (adsr 0.3 0.7 0.5 0.3) (line:kr 1.0 0.0 dur) :action FREE)          level (+ (* freq 0.25)                   (env-gen (adsr 0.5 0.3 1 0.5) (line:kr 1.0 0.0 (/ dur 2)) :level-scale cutoff))          freq (/ freq 2)          osc (mix [(saw freq)                    (saw (* freq 1.3348398541700344))])]      (-> osc          (bpf level 0.6)          (* env amp)          pan2)))

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:

(definst da-funk [freq 440 dur 1.0 amp 1.0 cutoff 2200 boost 12 dist-level 0.015]    (let [env (env-gen (adsr 0.3 0.7 0.5 0.3) (line:kr 1.0 0.0 dur) :action FREE)          freq (/ freq 2)          level (+ (* freq 0.25)                   (env-gen (adsr 0.5 0.3 1 0.5) (line:kr 1.0 0.0 (/ dur 2)) :level-scale cutoff))          osc (mix [(saw freq)                    (saw (* freq 1.3348398541700344))])]      (-> osc          (bpf level 0.6)          (* env amp)          pan2          (clip2 dist-level)          (* boost)          distort)))


Drums

The drum pattern is a classic 4×4:

Recreating Daft Punk's Da Funk with Overtone and Leipzig

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:

(defmethod live/play-note :beat [note]   (when-let [fn (-> (get kit (:drum note)) :sound)]     (fn :amp (:amp note))))

Where kit is a mapping from drum name to actual drum sound preloaded:

{:close-hat {:sound #<buffer[live]: close-hat.aif 0,275313s stereo 7>, :amp 1},  :fat-kick {:sound #<buffer[live]: fat-kick.aif 0,540542s stereo 5>, :amp 1},  :horn {:sound #<buffer[live]: horn.aif 0,213021s stereo 8>, :amp 1},  :kick {:sound #<buffer[live]: kick.aif 0,299833s stereo 0>, :amp 1},  :open-hat {:sound #<buffer[live]: open-hat.aif 0,238000s stereo 2>, :amp 1},  :snare {:sound #<buffer[live]: snare.aif 0,280875s stereo 6>, :amp 1}}

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

(defn tap [drum times length & {:keys [amp] :or {amp 1}}]   (map #(zipmap [:time :duration :drum :amp]                 [%1 (- length %1) drum amp]) times))

Now we are ready to construct the beat:

(def da-beats   (->>     (reduce with       [(tap :fat-kick (range 8) 8)        (tap :kick (range 8) 8)        (tap :snare (range 1 8 2) 8)        (tap :close-hat (sort (concat [3.75 7.75] (range 1/2 8 1))) 8)])     (all :part :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:

(->> da-beats        (tempo (bpm 110))        live/play)

And finally, to mix the synth with drums we need to use with function:

(->> da-funk      (with (times 2 da-beats))      (wherever :pitch, :pitch temperament/equal)      (tempo (bpm 110))      live/play)

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.

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Recreating Daft Punk's Da Funk with Overtone and Leipzig

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
分享按钮