Created
February 24, 2012 13:45
-
-
Save jamii/1901031 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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