Skip to content

Instantly share code, notes, and snippets.

@stuntgoat
Created February 26, 2014 08:28
Show Gist options
  • Save stuntgoat/9225787 to your computer and use it in GitHub Desktop.
Save stuntgoat/9225787 to your computer and use it in GitHub Desktop.
(defsynth foo [freq 200 dur 1]
"
defines the foo synth. Taken from the Overtone example
https://github.com/overtone/overtone/blob/master/src/overtone/examples/getting_started/basic.clj
"
(let [src (saw [freq (* freq 1.01) (* 0.99 freq)])
low (sin-osc (/ freq 2.1))
filt (lpf src (line:kr (* 10 freq) freq 10))
env (env-gen (perc 0.1 dur) :action FREE)]
(out 0 (pan2 (* 0.8 low env filt)))))
(defn fun
"
A helper function that accepts 2 arguments `time` and `freq`;
it plays `freq` at `time`. `time` is a Unix timestamp. ie 1393403168019
http://en.wikipedia.org/wiki/Unix_time
"
[time freq]
(at time
(foo freq 1))
)
(defn cycle-plus
"returns a lazy sequence of `start` added to each consecutive
item in `args`, which is a collection or a lazy sequence."
[start args]
(lazy-seq
(cons start (cycle-plus (+ start (first args)) (drop 1 args)))
)
)
;; Below we call the function that accepts a time and a frequency 1000 times with consecutive items from
;; 2 lazy sequences. The first repeatedly adds 100 and 333 milliseconds to the current time. The second
;; alternates the frequency, in Hertz, in the vector given.
;;
;; call function 1000 times repeat every ms repeat frequencies
(map #(fun %1 %2) (take 1000 (cycle-plus (now) (cycle [100 333]) )) (cycle [200 220 300 270 280 600 220 430 800 500 333]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment