Created
January 2, 2012 16:21
-
-
Save jennifersmith/1551277 to your computer and use it in GitHub Desktop.
Triangle and organ cornet stop
This file contains hidden or 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
(defcgen triangle-osc [freq phase {:default 0.0} harmonics {:default 40}] | |
(:ar (let | |
[ | |
harmonic-numbers (take harmonics (iterate (partial + 2) 1)) | |
cosines (set (map #(- (* 4 %) 1) (range 1 harmonics))) ;; every 4n -1 is | |
;; there a better way?! | |
] | |
(klang [ | |
(map #(* freq %) harmonic-numbers ) ;; harmonics | |
(map #(/ 1.0 (* % %)) harmonic-numbers) ;; inverse square ampl | |
(map #(+ phase %) (map #(if (cosines %) (. Math PI) 0.0 ) harmonic-numbers )) ;; conditional phase shift by pi | |
]) | |
)) | |
) | |
(defcgen organ-env [dur {:default 1.0} vol {:default 1.0}] | |
( :kr | |
(* vol | |
(env-gen (asr 0.1 1.0 0.5) (line:kr 1.0 0.0 dur) :timeScale dur :action FREE ))) | |
) | |
(definst organ-cornet [freq 440 dur 1.0 vol 1.0] | |
(* | |
(organ-env :dur dur :vol vol) | |
(apply + | |
(map | |
#(triangle-osc (* freq %)) (range 1 5)) ) | |
0.25 | |
) | |
) | |
;; (organ-cornet 440) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment