A-more-powerful SND

Snd can use either s7 (a Scheme interpreter), ruby and even Forth as internal scripting languages. For example to create a new sound from an s7 instrument, we can start with the outstanding Birds instrument written by Bill Shottstaedt, and also known as “bird.scm”. Try typing the following commands on Snd's listener. You might need to copy “bird.scm” into your working directory.

  1. (load "bird.scm")

  2. (make-birds)

  3. (play)

At first code might be intimidating but to get acquainted with s7 language, a simple “hello-world” sine instrument in s7-Scheme might look like:

(define (sine-snd beg dur freq amp)
  (let ((start (seconds->samples beg))	
	(len (seconds->samples (+ beg dur)))		
	(phase-inc (hz->radians freq)))
    (do ((i start (1+ i)))
	((= i len))
      (outa i (* amp (sin (* i phase-inc)))))))

You can copy and paste this instrument to your favorite text editor although we recommend an emacs like editor (here you cab have SND as an inferior-lisp process). Once saved as yoursine.scm you can load it to the interpreter by typing:

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

  2. (load "yoursine.scm")

This definition of sine has the following parameters in the lambda list: beg as for offset or beginning of sound,dur for durations of the sound freq for frequency and amp for amplitude or volume of the sound which in this case should be less than one. Therefore to create a sound file with a simple 1000Hz sine tone you type:

  1. (with-sound () (sine-snd 0 5 800 0.7))
    To listen to the sound !!! on the listener type,
  2. (play)

If you want successive beep tones then you can type something like:

(with-sound () 
	    (do ((i 0 (+ i 1))) 
		((= i 5))
	      (sine-snd i 0.5 777 0.5)))

and then:


Take a look at the code for another “sine” instrument, this time using s7's oscil unit generator, producing same results as above. -It might be easier to understand for people used to Music-N software synthesis packages-.

(define (simpler beg dur freq amp)
  (let* ((start (seconds->samples beg))	
	 (len (seconds->samples (+ beg dur)))		
	 (s (make-oscil :frequency freq)))

    (do ((i start (1+ i)))
	((= i len))
      (outa i (* amp (oscil s))))))

On the listener function calls for this instrument also involve beginning or offset of sound, duration, frequency, and intensity volume or amplitude. To get sound you use “(with-sound ()())” macro to trigger the the instrument. Copy-and-paste this code to a new file and then load it with the listener into Snd's s7. Once loaded:

  1. (load “simpler.scm”)
  2. (with-sound () (simpler 0 3 800 0.7))
  3. (play)
  4. (with-sound () (simpler 0 10 1000 0.5)) ;;; 1000Hz. Tone
  5. (play)

Above we can see waveform of a sinusoidal sound generated with “sine-snd” or with the “simpler” instrument code definition on s7.

Look at the waveform of this sound and see if you can change its envelope. HINT: On the “edit” menu of Snd's main edit window, there is an “Edit envelope” option that opens another window with an envelope editor, see image below. In many cases is better to get an envelope to modify a sound this way. You can create fade-in or fade-out and even cross fades. Envelopes is a good way of manipulating a sound. reasons enough to get familiar with this kind of editing on Snd.

snd-env.png WIDTH="400" HEIGHT="364"
Edit envelope window with an enveloped waveform of the sinusoidal sound. The envelope editor here is a graphical-user-interface where you click to select breakpoints. On this case you have a waveform behind the envelope. Envelopes can be used for amplitude (this case), moving filtering parameters or sample rate conversion.


A basic Signal Processing instrument to do “Fourier Convolution” instrument which can be found on examples.scm as part of the SND distribution is written as follows. Copy and paste this code to a .scm file in your home directory or in the /zap directory and save it as “myconvolve.scm

(define (cnvtest snd0 snd1 amp)
  (let* ((flt-len (framples snd0))
	 (total-len (+ flt-len (framples snd1)))
	 (cnv (make-convolve :filter (channel->float-vector 0 flt-len snd0)
			     :input (make-sampler 0 snd1))) )
    (do ((i 0 (+ i 1)))
	((= i total-len))
      (outa i (* amp (convolve cnv)))
  1. On the SND listener load myconvolve.scm by typing

              (load " /myconvolve.scm") or (load "/zap/myconvolve.scm")        
  2. Then go ahead and open your source sound file which will be sound 0 or (snd0) by,

              (open-sound  "/zap/source.snd")          
  3. Open your impulse sound file which will be sound 1 or (snd1) typing,

              (open-sound  "/zap/impulse.snd")         
  4. Perform “Fourier Convolution” on these two sounds as follows (pay attention to the amplitude factor which is the third field in the definition of cnvtest.

              (with-sound () (cnvtest 0 1 0.65))         
  5. To listen to your convolved file make sure that the region or soundfile selected on the SND window is the impulse soundfile window and on the listener type:


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