Skip to content

Instantly share code, notes, and snippets.

@jamii
Created February 24, 2012 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamii/1901031 to your computer and use it in GitHub Desktop.
Save jamii/1901031 to your computer and use it in GitHub Desktop.
(ns mechanical-sympathiser.core
(:require [mechanical-sympathiser.sound :as sound]
[mechanical-sympathiser.system :as system]
overtone.core)
(:import (java.util Timer TimerTask)))
(def timer (new Timer))
(defn poll [period poll-fn]
(let [task (proxy [TimerTask] []
(run [] (poll-fn)))]
(. timer (scheduleAtFixedRate task (long 0) (long period)))))
(defn cpus [period]
(let [insts (for [cpu (system/cpus)] (sound/saw-inst))]
(poll period #(cpus-poll insts))))
(defn cpus-poll [insts]
(doseq [[inst cpu] (map vector insts (system/cpus))]
(let [freq (+ 200 (* 50 (:cpu cpu)))
volume (/ (:usr cpu) 100)]
(overtone.core/ctl inst :freq freq :volume volume))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment