Substractive Synthesis and Filters
(definstrument onepole(start-time duration amplitude &key (b1 '(0 0.5 1 0.5))) (multiple-value-bind (beg end) (get-beg-end start-time duration) (let* ((noise (make-randh :frequency (* 0.49 sampling-rate) :amplitude amplitude)) (b1-env (make-env :envelope b1)) (opfilt (make-one-pole :a0 1.0 :b1 0.5))) (Run (loop for i from beg to end do (setf (smpflt-b1 opfilt) (env b1-env)) (outa i (one-pole opfilt (randh noise))))))))
(definstrument onezero(start-time duration amplitude &key (a1 '(0 0.5 1 0.5))) (multiple-value-bind (beg end) (get-beg-end start-time duration) (let* ((noise (make-randh :frequency (* 0.49 sampling-rate) :amplitude amplitude)) (a1-env (make-env :envelope a1)) (ozfilt (make-one-zero :a0 1.0 :a1 0.5))) (Run (loop for i from beg to end do (setf (smpflt-a1 ozfilt) (env a1-env)) (outa i (one-zero ozfilt (randh noise))))))))
(defmacro b1-from-r-freq (r freq) `(- (* 2.0 ,r (cos (in-hz ,freq))))) (defmacro b2-from-r (r) `(* ,r ,r)) (definstrument twopole(start-time duration amplitude &key (freq '(0 20 1 10000)) (r '(0 0.5 1 0.5))) (multiple-value-bind (beg end) (get-beg-end start-time duration) (let* ((noise (make-randh :frequency (* 0.49 sampling-rate) :amplitude amplitude)) (freq-env (make-env :envelope freq)) (r-env (make-env :envelope r)) (ppfilt (make-ppolar :r 0.5 :frequency 440.0))) (Run (loop for i from beg to end do (let* ((freq0 (env freq-env)) (r0 (env r-env))) (setf (smpflt-b1 ppfilt) (b1-from-r-freq r0 freq0)) (setf (smpflt-b2 ppfilt) (b2-from-r r0)) (outa i (ppolar ppfilt (randh noise)))))))))
(defmacro set-formnt(filter freq r) `(let* ((freq ,freq) (r ,r)) (setf (smpflt-a2 (frmnt-tz ,filter)) (- r) (smpflt-b1 (frmnt-tp ,filter)) (- (* 2.0 r (cos (in-hz freq)))) (smpflt-b2 (frmnt-tp ,filter)) (* r r)))) (definstrument simp-formnt(start-time duration amplitude &key (freq '(0 20 1 10000)) (r '(0 0.707 1 0.707))) (multiple-value-bind (beg end) (get-beg-end start-time duration) (let* ((noise (make-randh :frequency (* 0.5 sampling-rate) :amplitude amplitude)) (freq-env (make-env :envelope freq :start-time start-time :duration duration)) (r-env (make-env :envelope r :start-time start-time :duration duration)) (fmfilt (make-formnt :frequency 440 :r 0.99))) (Run (loop for i from beg to end do (set-formnt fmfilt (env freq-env) (env r-env)) (outa i (formnt fmfilt (randh noise))))))))All of these example instrument do some internal contortions to move through envelopes the center frequency, resonance and or assorted internal coefficients. Hope you can figure things out. Believe it or not everything that's being done is documented in the clm manual... :-)
©1997 Fernando Lopez-Lezcano. All Rights Reserved. nando@ccrma.stanford.edu
|