Create a gist now

Instantly share code, notes, and snippets.

@kn1kn1 /core.clj
Last active Aug 29, 2015

What would you like to do?
Steve Reich's Piano Phase - Overtone (beep)
(ns reich.core
;; Steve Reich's Piano Phase
(def piece [:E4 :F#4 :B4 :C#5 :D5 :F#4 :E4 :C#5 :B4 :F#4 :D5 :C#5])
(definst beep [freq 440 amp 0.1]
(let [env (env-gen (perc 0.1 0.2) :action FREE)]
(* amp (* env (sin-osc freq)))))
(defn player
[t speed notes]
(let [n (first notes)
notes (next notes)
t-next (+ t speed)]
(when n
(at t
(beep (midi->hz (note n))))
(apply-by t-next #'player [t-next speed notes]))))
(def num-notes 1000)
(player (now) 338 (take num-notes (cycle piece)))
(player (now) 335 (take num-notes (cycle piece))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment