Music 220B
Simple Envelope Follower
Following the input signal amplitude
This CLM instrument is a simple example of an envelope follower. In this case the parameter we are trying to follow is the amplitude of the input signal (coming from the mic input).
;;; follow.cl
;;; a simple envelope follower
;;; need tester, try to load it (or report error)
(if (not (member 'tester *clm-instruments*))
(load "tester"))
(defparameter follow-on 1400)
(defparameter follow-amp 1401)
(defparameter follow-out 1402)
(defpinstrument follow (&key (window-length 600.0) ;;; length of window in samples
(decay 0.99) ;;; decay time constant
(tester nil))
(let* ((window-scale (/ 5.0 window-length))
(amp-f (make-fcontrol follow-amp)) ;;; input amp control
(counter 0)
(output 0.0)
(sum 0.0))
(run
(loop for i from 0 do
(when (= (control follow-on) 0.0)(loop-finish))
(let* ((input (* (fcontrol amp-f)(rec-any 0))))
(incf counter)
(incf sum (abs input))
(setf sum (* sum decay))
(setf output (* sum window-scale))
(setf (control follow-out) output)
;;; plot the envelope in the tester's graph
(if tester (setf (tester-in) output))
(outa i input))))))
Testing the instrument
Once follow.cl is Compiled and Loaded, remember to allocate memory for the controllers (if you haven't done this before):
(open-controls 2048)
Now you can start the GUI in an Xterm, remember to start the tester as well!
follow &
Try whispering into the mic changing intensity and see how the printed values follow your changes (at the left corner of the GUI). Using the tester you can see the envelope shape in the signal window.
(with-psound (:srate 22050 :rec-line 0 :rec-chans 1)
(tester)
(follow :tester t))
Try changing the values of the instrument's parameters window-length and decay and see how they affect the envelope following. For example:
(with-psound (:srate 22050 :rec-line 0 :rec-chans 1)
(tester)
(follow :window-length 400 :tester t))
or
(with-psound (:srate 22050 :rec-line 0 :rec-chans 1)
(tester)
(follow :decay 0.9999 :tester t))

©1998 by Juan Pampin, juan@ccrma.stanford.edu