Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 38 lines (32 sloc) 1.141 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
(ns overtunes.instruments.organ-cornet
  (:use [overtone.live])
)

;; From https://gist.github.com/1551277 by jennifersmith.

(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 1000} vol {:default 1.0}]
  ( :kr
    (* vol
       (env-gen (asr 0.1 1.0 0.5) (line:kr 1.0 0.0 (/ dur 1000)) :timeScale (/ dur 1000) :action FREE )))
  )

(definst organ-cornet [freq 440 dur 1000 vol 1.0]
  (*
   (organ-env :dur dur :vol vol)
   
   (apply +
    (map
     #(triangle-osc (* freq %)) (range 1 5)) )
   0.25
   )
)
Something went wrong with that request. Please try again.