Simple Physical Modeling on Snd's s7

On physical modeling, it is the actual physics of the instrument, and most certainly, its playing technique what is modeled on the computer. Typically, a physical model of an instrument is an algorithm in which a delay line represents points of one period of its waveform at a desired frequency or pitch. Therefore the length of a delay line corresponds to the number of samples required to produce one period of the sound in addition to some type of modulation or modification process recurring on each cycle of the algorithm. Initial conditions of a given delay line, and parameters on the modification process play a key role determining the character of the sound produced. Research on Physical Modeling focuses on finding and bringing parameters to adjust then and tweak them the way the acoustics of a given instrument really operates. Julius Smith's book on Physical Modeling has explantations and technical details on research done by him and his students at CCRMA and other places in the world. Better explanations, part of his published book on the subject, are found online at his Web page, Introduction to Physical Signal Models, which is a complement to his published book on the subject.

For example a clarinet can be divided into two sections, namely excitation and resonant body. Performer blows and excites a reed that vibrates producing a wave of air that goes inside a pipe which is the resonant body that amplifies the sound of the instrument. Pitch depends on the length of this pipe and is manipulated by the registers of the instrument. As per basic physics, the longer the pipe, the lower the frequency. Here we can see that the behavior of the body can be modeled by how the air column behaves inside its pipe. Thereby air going-in one side of the pipe and going-out on the other side can help us visualize delay occurring between its inlet and outlet. Since we know that the column of air inside the pipe is vibrating at a given frequency, delay lines model this vibration by giving values or the differences on the vibrating column of air at every time the wave goes in one direction and in the opposite direction when is bouncing back. Typically two delay lines represent a wave guide that models a vibrating column of air inside a clarinet's body. The reed which excitates and moves the air inside the resonant body is also modeled by different means.


As and example of a delay line and may be one of the most basic incarnations of physical modeling is the Karplus-Strong algogorithm which models the “Plucked String.” Basically this method loops a short waveform through a filtered delay line to simulate the sound of a hammered or plucked string or some types of percussion. Alex Strong at Stanford's CS department, invented the algorithm, and K. Karplus did the analysis of how it worked. Together they developed software and hardware implementations of the algorithm, including a custom VLSI chip. For more K-S go to its Wiki page, HERE. Furthermore Julius Smith explains the Karplus-Strong algorithm as:

- The Karplus-Strong algorithm, per se, is obtained when the delay-line initial conditions used to “pluck” the string consist of random numbers, or “White Noise”.-

Here we have the code for a “plucked String” Karplus-Strong algorithm that should trigger insights on the subject of physical modeling.

(define* (karplus-strong beg dur freq amplitude (damp 0.5))
  (let* ((s-rate (seconds->samples 1))
	 (len (+ 1 (floor (/ s-rate 100.0))))) ; 100 = lowest freq in samples
    (let ((delayline (make-delayl len (- (/ s-rate freq) 0.5)))
	  (filt (make-onezero))
	  (start (seconds->samples beg))
	  (end (seconds->samples (+ beg dur)))
	  (dout 0.0))
      (do ((i 0 (+ i 1)))
	  ((= i len))
	(set! dout (delayl delayline (+ (* 0.99 dout) (mus-random damp)))))
      (do ((i start (+ i 1)))
	  ((= i end))
	(set! dout (delayl delayline (one-zero filt dout)))
	(outa i (* amplitude dout))))))


Perry Cook and Gary Scavone did research and their dissertation theses on the subject of Physical Modeling at CCRMA. A lot of their research, among others, is embedded into the Synthesis Tool Kit (STK). They describe STK as a set of audio signal processing C++ classes and instruments for music synthesis. Snd's s7 counterpart are a set of instrument primarily following the K-S plucked string (previously described), a bowed string model , a flute and clarinet models as well as a handful of brass and percussion physical models. You can combine these instruments to create programs which make cool sounds using a variety of synthesis techniques.

More on STK

At CCRMA you can copy the file prc95.scm to your /zap directory by issuing the next commands:

         scp /usr/ccrma/lisp/src/snd/prc95.scm /zap/prc95.scm        

Alternatively you can look in the SND distribution for this file and also place it in your /zap or /tmp directories.

Start your STK or rather Physical modeling experimentation with the usual steps for working with SND and scheme

  1. Open a new sound in Snd,

              (new-sound "/zap/test.snd") or (open-sound "/zap/test.snd")        

  2. And now load your STK instruments,

              (load "prc95.scm")        

Careful analysis of the code will make you aware of these instruments and their calls:

Also notice the parameters for the s7 function call.

           (beg dur freq amplitude maxa)       

Where beg is start time of sound, dur is the duration of the sound, freq is the frequency in Hertz of the sound, amplitude is attack intensity or initial pressure of the sound and maxa is the overall maximum amplitude of the Physical Model. Note that there is a ratio between amplitude and maxa. You can read more about these parameters on the STK web pages, in the various paper written on the subject by Perry Cook and Gary Scavone or you can simply read the code to figure them out.

You can listen to another rendition of the K-S plucked string algorithm by typing the following function call on Snd's listener:

         (with-sound () (plucky 0 2 505 .7 1.0))       

In this case the start time is zero, duration of sound is 2 seconds, frequency is 505Hz and amp is 0.7 while maximum output is function of 1.0.

Try the following plucked sound:

         (with-sound () (plucky 0 0.3 643.4317 .2 1.0))       

and try to perceive the difference. Now to get a natural clarinet sound we might type the following function call:

         (with-sound () (clarinet 0 2 500 .5 0.6))       

A very long and low clarinet sound might be:

         (with-sound () (clarinet 0 3 220 .5 0.8))       

If it sounds like a clarinet, try to play expression markings by changing the amplitude and maxa ratio. And what about if you want to add vibrato ?

Next, here is a sequence of pipes (may be flute) sounds:

(define (pipes)
  (with-sound ()
	      (flute 0 .5 261.62555 .6 1.2)
	      (flute 1 .8 391.99542 .4 1.1)
	      (flute 2 1.4 523.2511 .4 1.1)
	      (flute 3.5 .5 261.62555 .6 1.2)
	      (flute 4 .8 391.99542 .4 1.1)
	      (flute 5 1.4 523.2511 .7 1.1)
	      (flute 7 .4 698.4565 .8 1.2)
	      (flute 7.8 1.6 391.99542 .2 1.0)
	      (flute 9 4 261.62555 .3 0.8)

In this case we are defining a scheme function called “pipes” which carries the score for the physical model. This is sort of like the “SKINI” protocol for the C++ version of STK. Please note the different start times and durations and very important!! don't take for granted that start times are function of durations themselves.

In order to make sound you type the following function call on the scheme listener.


Try to experiment changing the order of those sound and make them sound more like a magic pan flute.


Delay lines are the building stones for physical models of this kind. But in fact they can be used to model a variety of acoustical phenomena for example the Doppler Effect. For instance, this kind of sound is typical when you hear a train is getting closer to you, and when it passes by. In more technical terms, a Doppler shift is an apparent change in acoustic frequency content of a sound source due to motion of the source relative to the listener. It is known that if the length of a delay line is changed as time goes by, the frequency of the sound passing through is also changed. Therefore, we can also model Doppler effects with delay lines. Among the most interesting musical applications is the Leslie Speaker. The Leslie speaker is described as follows:

The Leslie is a popular audio processor used with electronic organs and other instruments. It employs a rotating horn and rotating speaker port to “choralize” the sound. Since the horn rotates within a cabinet, the listener hears multiple reflections at different Doppler shifts, giving a kind of chorus effect. Additionally, the Leslie amplifier distorts at high volumes, producing a pleasing “growl” highly prized by keyboard players.

On the summer of 2002 Stefania Serafin, Patty Huang, Jonathan Abel and others, did careful experimentation and measurements to get the right parameters to model a Leslie speaker. Their research was published on DAFX-2002 proceedings but as a Julius Smith courtesy, it is also found HERE. There is a Snd's s7 implementation of the Leslie effect using time varying delay lines. In this case and to fully appreciate the effect Stereo sound must be used. On this mix there is a panned mixture of a sound source split into two channels, each one with its own stereo placement, path filtering, and Doppler shift. For demonstration purposes this s7 function, instrument or effect makes use of a “wave-train” unit generator to outline characteristics of this sound. Readers should be encouraged to grab this code (leslie.cms) and hack it to read input from an external sound file or for another types of synthesis. To try the Leslie intrument on Snd, here are the steps:

  1. On the listener, load the instrument into Snd:

             (load "leslie.cms")        

  2. A simple function call to the instrument using default values:

             (with-sound (:channels 2)  (rotates 0 1 800))       

  3. A function tweaking the speed parameter:

             (with-sound (:channels 2)  (rotates 0 8 300 :speedsl 1.0))       

  4. A function call with an envelope changing speed of the rotating horn:

             (with-sound (:channels 2)  (rotates 0 3 800 :velenv '(0 0.05 100 1)))       

  5. Another call using a triangular envelope changing speed of the horn:

             (with-sound (:channels 2)  (rotates 0 5 1000 :velenv '(0 0.25 50 1 100 0.3)))       

    Although frequency shifts are subtle, sound tends to be perceived as spacious. Try other functions call of your choice with other parameters and perhaps look at the code to see how delay lines are implemented in Snd s7.

More to come !!! on Physical Modeling in Snd.

© Copyright 2001-2022 CCRMA, Stanford University. All rights reserved.
Created and Mantained by Juan Reyes