|

Next: Tutorials-and-More about SND
Up: SND
Previous: Ladspa-DSP plug-ins in SND
Snd can use either
guile
(a Scheme interpreter) or
ruby as an internal scripting language. For example to create a new sound
from a Scheme instrument like bird.scm, you type the following
commands on the guile listener provided that ``bird.scm'' is on your
working directory.
- (new-sound "/zap/test.snd") or (open-sound"/zap/test.snd")
- (load "bird.scm")
- (make-birds)
- (play)
|
|
A simple ``hello-world'' sine instrument in Sheme might look like:
(define sine
(lambda (beg dur freq amp)
(let* ((start (floor (* beg (srate))))
(len (floor (* dur (srate))))
(phase-inc (hz->radians freq))
(out-data (make-vct len)))
(do ((i 0 (1+ i)))
((= i len))
(vct-set! out-data i (* amp (sin (* i phase-inc)))
))
(vct->channel out-data start len))))
|
|
You can copy and paste this instrument to your favorite text editor
although we recommend an emacs like editor (and make sure you have
SND as your inferior-lisp process). Once saved as
yoursine.scm you can load it to the interpreter by typing:
- (new-sound "/zap/test.snd") or (open-sound "/zap/test.snd")
- (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:
- (sine 0 5 1000 .5)
To listen to the sound !!! type,
- (play)
|
|
If you want successive beep tones then you can type something like:
(do ((i 0 (1+ i)))
((= i 9))
(sine i 0.5 777 0.5))
|
|
and then:
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
(lambda (snd0 snd1 amp)
(let* ((flt-len (frames snd0))
(total-len (+ flt-len (frames snd1)))
(cnv (make-convolve :filter (channel->vct 0 flt-len snd0)))
(sf (make-sample-reader 0 snd1))
(out-data (make-vct total-len)))
(vct-map! out-data
(lambda ()
(convolve cnv (lambda (dir) (next-sample sf)))))
(free-sample-reader sf)
(vct-scale! out-data amp)
(let ((max-samp (vct-peak out-data)))
(vct->channel out-data 0 total-len snd1)
(if (> max-samp 1.0) (set! (y-bounds snd1) (list (- max-samp) max-samp)))
max-samp))))
|
|
- On the SND listener load myconvolve.scm by typing
(load " /myconvolve.scm") or (load "/zap/myconvolve.scm")
|
|
- Then go ahead and open your source sound file which will be
sound 0 or (snd0) by,
(open-sound "/zap/source.snd")
|
|
- Open your impulse sound file which will be sound 1 or (snd1) typing,
(open-sound "/zap/impulse.snd")
|
|
- 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.
- 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:
Next: Tutorials-and-More about SND
Up: SND
Previous: Ladspa-DSP plug-ins in SND
© Copyright 2001-2006 CCRMA, Stanford University. All rights reserved.
Created and Mantained by Juan Reyes
|