Function
(drunkn width {keyword value}*)
Returns a random value constrained to lie between n-widthand n+width according to keyword arguments specified to the function. Calling the function with previous values of n implements random walks (brown noise).
drunk supports the following
keyword arguments:
:mode {keyword | number}
:reflect | value is reflected back into bounds |
:limit | nearest boundary value is returned |
:reset | value is centered between boundaries |
:jump | value randomly positioned |
:stop | returns false as value of function |
:low number
:mode.
:high number
:mode.
:avoid number
:state state*random-state*.
;; The drunk function. (loop repeat 10 for r = 60 then (drunk r 3) collect r) ⇒ (60 62 61 60 58 60 62 63 65 67) (drunk 40 2 :low 60 :high 72) ⇒ 63 (drunk 40 2 :low 60 :high 72 :mode ':stop) ⇒ #f ;; Random walk for keynum and amplitude. (define (stagger len low high step) (let ((k (/ (- high low) 2)) (a (between .1 .9))) (process repeat len for r = (pick 1/8 1/4) set k = (drunk k step :high high :low low :mode ':jump) set a = (drunk a .1 :low .2 :high .9 :mode .5) output (new midi :time (now) :duration (* r 1.5) :keynum k :amplitude a) wait r))) (events (list (stagger 80 40 80 3) (stagger 60 20 40 7) (stagger 40 70 90 5)) "test.mid" '(0 4 6)) ⇒ "test.mid"