CCRMA

Substractive Synthesis and Digital Filters


Lecture Slides

A series of gif images of the lecture slides... (only accesible from within Stanford University)


Substractive Synthesis

Basic concepts.


Filters

Definition
input -> operation -> output; anything is a filter... usually applied to devices that boost or attenuate regions of the spectrum.
Characterization
amplitude versus frequency response curve
  • lowpass
  • highpass
  • bandpass
  • bandreject (notch)
  • shelving
Cutoff Frequency
half power point (0.707 or -3dB)
Center Frequency
[maximum|minimum] amplitude in a [bandpass|bandreject]
Stopband vs Passband
Bandwidth
Slope
Q and Gain
Comb and Allpass Filters

Examples

Here is a bunch of very simple instruments that use the stock filters that come with the clm distribution ("/usr/ccrma/lisp/src/clm").


onepole.ins

A simple One Pole filter (filtering white noise)...

(definstrument onepole(start-time duration amplitude
				  &key
				  (b1 '(0 0.5 1 0.5)))
  (multiple-value-bind (beg end) (times->samples start-time duration)
    (let* ((noise (make-rand :frequency (* 0.49 *srate*) 
			      :amplitude amplitude))
	   (b1-env (make-env :envelope b1
			     :duration duration))
	   (opfilt (make-one-pole :a0 1.0 :b1 0.5)))
      (run
       (loop for i from beg to end do
	     (setf (mus-b1 opfilt) (env b1-env))
	     (outa i (one-pole opfilt (rand noise))))))))

onezero.ins

A simple One Zero filter (filtering white noise)...

(definstrument onezero(start-time duration amplitude
				  &key
				  (a1 '(0 0.5 1 0.5)))
  (multiple-value-bind (beg end) (times->samples start-time duration)
    (let* ((noise (make-rand :frequency (* 0.49 *srate*) 
			      :amplitude amplitude))
	   (a1-env (make-env :envelope a1
			     :duration duration))
	   (ozfilt (make-one-zero :a0 1.0 :a1 0.5)))
      (run
       (loop for i from beg to end do
	     (setf (mus-a1 ozfilt) (env a1-env))
	     (outa i (one-zero ozfilt (rand noise))))))))

ppolar.ins

A simple Two Pole filter with resonance based on the ppolar clm ug (filtering white noise)...

(defmacro b1-from-r-freq (r freq) 
   `(- (* 2.0 ,r (cos (hz->radians ,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) 
      (times->samples start-time duration)
    (let* ((noise (make-rand :frequency (* 0.49 *srate*) 
			     :amplitude amplitude))
	   (freq-env (make-env :envelope freq
			       :duration duration))
	   (r-env (make-env :envelope r
			    :duration duration))
	   (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 (mus-b1 ppfilt) (b1-from-r-freq r0 freq0))
	       (setf (mus-b2 ppfilt) (b2-from-r r0))
	       (outa i (two-pole ppfilt (rand noise)))))))))

formnt.ins

A simple Two Pole / Two Zero formant filter (filtering white noise)...

(defmacro set-formnt(filter freq r)
  `(let* ((freq ,freq)
	  (r ,r))
     (setf (mus-a2 (identity ,filter)) (- r)
	   (mus-b1 (identity ,filter)) (- (* 2.0 r (cos (hz->radians freq))))
	   (mus-b2 (identity ,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) 
      (times->samples start-time duration)
    (let* ((noise (make-rand :frequency (* 0.5 *srate*) :amplitude amplitude))
	   (freq-env (make-env :envelope freq
			       :duration duration))
	   (r-env (make-env :envelope r
			    :duration duration))
	   (fmfilt (make-formant :frequency 440 :radius 0.99)))
      (run
       (loop for i from beg to end do
	     (set-formnt fmfilt (env freq-env) (env r-env))
	     (outa i (formant fmfilt (rand 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... :-)

butterworth.cl

A pair of quite good low pass, high pass, band pass and reject filters from the clm distribution. Just copy the file butterworth.cl. Take a look at the docs. Here's an example instrument (butter.ins), courtesy of Juan Pampin.

moog.lisp

Tim Stilson's implementation of a 24db/octave Moog low pass filter, with variable resonance... back to that warm analog sound! Find the source in moog.lisp. There's also a simple example instrument (moog-filter.ins) that can filter a soundfile (and also defines a very handy with-moog that uses sound-let to do its magic). If you really want to read all the gory details on how the magic works go to Tim Stilson's Home Page and follow the link that points to his papers.

addflt.ins

Take a look at a more sophisticated example that is included in the clm distribution, a multiple resonante filter instrument called addflt.ins

Adding filtering to instruments

Two approaches to adding filtering to instruments.

In the first one we modified the code of the original v.ins (Bill's fm-violin) and added a moog filter based of Tim Stilson's moog filter. Needless to say, for this to work we have to first compile and load the moog filter code moog.lisp. After that, compiling and loading the modified vmoog.ins fm violin file will generate a mutant fm-violin that understands two additional parameters, freq-env: the frequency envelope for the cutoff frequency of the moog filter and res-env: an envelope that controls the resonance of the filter.

We can also create a general purpose moog filter instrument that processes a soundfile. The code can be found in moog-filter.ins. One way to use this instrument to process arbitrary clm instrument output is to use a sound-let to create a temporary soundfile that holds the notes that are to be filtered. Better still, we can create a custom macro that adds some syntactic sugar and makes things look better. See the "with-moog" macro in the previous file plus an example on how to use it.

There are several other filtering unit generators in CLM. See:


©1998, 2001-2003 Fernando Lopez-Lezcano. All Rights Reserved.
nando@ccrma.stanford.edu