CCRMA

CLM instruments: Granular Synthesis and Sampling Rate Conversion, the Loop macro


Lecture Slides

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


CLM

  • Some with-sound options (see the complete description in the clm manual, at file:///usr/ccrma/lisp/src/clm/clm.html:

    :channels
    number of output channels
    :srate
    sample rate for output soundfile
    :reverb
    name of the reverb instrument
    :decay-time
    decay time of the reverb
    :statistics
    print some statistics about the clm run
    :output
    name of the output soundfile

  • some CLM unit generators:

    • oscil
    • env
    • outa and friends
    • locsig

  • some CLM instruments:

  • The loop macro:

    • basic syntax
    • for ... from ... by ... below
    • for ... in
    • repeat
    • collect
    • do

  • Common Music:

    • what is CM?
    • relationship with CLM
    • basic CM: processes, events
    • useful CM macros: hertz...

  • Algorithmic Techniques: within a note (generating complex envelopes)

Granular Synthesis

Overview of granular synthesis techniques.


Examples

Here's a fairly comprehensive granular synthesis instrument written in clm (grani.ins) and geared towards granulation of soundfiles.

Here is the header of the instrument and a short description of its parameters (see the source code for the parameter defaults):

(definstrument grani 
    (start-time duration amplitude file
		&key
		(grains grani-grains)
		(amp-envelope grani-amp-envelope)
		(grain-envelope grani-grain-envelope)
		(grain-envelope-end grani-grain-envelope-end)
		(grain-envelope-transition grani-grain-envelope-transition)
		(grain-duration grani-grain-duration)
		(grain-duration-spread grani-grain-duration-spread)
		(grain-duration-limit grani-grain-duration-limit)
		(srate grani-srate)
		(srate-spread grani-srate-spread)
		(srate-linear grani-srate-linear)
		(srate-base grani-srate-base)
		(srate-error grani-srate-error)
		(grain-start grani-grain-start)
		(grain-start-spread grani-grain-start-spread)
		(grain-density grani-grain-density)
		(grain-density-spread grani-grain-density-spread)
		(reverb-amount grani-reverb-amount)
		(reverse grani-reverse)
		(where-to grani-where-to)
		(where-bins grani-where-bins)
		(grain-distance grani-grain-distance)
		(grain-distance-spread grani-grain-distance-spread)
		(grain-degree grani-grain-degree)
		(grain-degree-spread grani-grain-degree-spread))

Mandatory parameters

start-time
starting time in seconds
duration
duration of the note in seconds
amplitude
amplitude of the note
file
the complete pathname of the soundfile you want to use as source material for the grains

Some of the optional parameters

After the name of the parameter I specify the type of parameter. Most of the key parameters can be either numbers (for a constant value) or an envelope.

amp-envelope [envelope]
amplitude envelope for the whole note
grain-envelope [envelope]
amplitude envelope for each individual grain
grain-envelope-end [envelope or nil]
a second amplitude envelope for each individual grain. If specified, grain-envelope-transition can be used to interpolate between both envelopes over the duration of the note.
grain-envelope-transition [envelope]
interpolation envelope for the grain envelope (used only if grain-envelope-end has been specified).
grain-duration [number or envelope]
duration in seconds of each individual grain
grain-duration-spread [number or envelope]
random deviation from grain-duration
grain-duration-limit [number]
minimum duration in seconds of a grain
srate [number or envelope]
sample rate conversion factor. The value for each grain is either a constant if the parameter is a number or is determined by the value of the envelope at the point in time where the grain starts. The sample rate conversion factor is a constant within the grain. If not overriden by the sampling rate conversion factor is specified in semitones (positive values transpose the sound up and negative values transpose down).
srate-spread [number or envelope]
random deviation the value of srate
srate-linear [t or nil]
defines the type of envelope used for the sampling rate conversion factor:
nil (the default): "srate" is expressed in fractional semitones above or below the original sampling rate (0 = no change in sampling rate conversion). The exponential envelope is approximated by a linear segment representation. The error bounds of the approximation can be set by srate-error. The base of the exponential curve can be changed by srate-base.
t: "srate" is the linear sampling rate conversion factor (1 = no change in sampling rate).
srate-error [number]
error bound for the exponential conversion
srate-base [number]
base for the exponential conversion. "2" will express the envelope in octaves. "(expt 2 (/ 12)" will express the envelope in semitones.
grain-start [number or envelope]
point in the input file where the samples are going to be read from. "0" represents the start of the input soundfile, "1" represents the end. An envelope can be used to produce arbitrary mappings over time.
grain-start-spread [number or envelope]
random deviation from the value of grain-start.
grain-density [number or envelope]
number of grains per second that will be created.
grain-density-spread [number or envelope]
random deviation from the value of grain-density.
reverse [t or nil]
"t" means the input soundfile will be read backwards (each grain will read backwards but of course this is independent from grain-start, for example we could be advancing forwards in the file but reading the samples backwards).
reverb-amount [number]
amount of sound to be sent to the reverb output stream.
grain-distance [number or envelope]
distance to the listener position (for locsig)
grain-distance-spread [number or envelope]
random deviation from the value of grain-distance
grain-degree [number or envelope]
angular position (for locsig)
grain-degree-spread [number or envelope]
random deviation from the value of grain-degree

Some examples...

  • Just a silly stuttering gong:
    (with-sound()(grani 0 8 2 
                        "/usr/ccrma/web/html/courses/220b/lectures/2/sounds/small-gong.snd"))
    
  • Smaller grains:
    (with-sound()(grani 0 8 3 
                        "/usr/ccrma/web/html/courses/220b/lectures/2/sounds/small-gong.snd"
                        :grain-duration 0.06 :grain-density 40 
                        :grain-density-spread 5 :grain-start '(0 0.3 1 0.4)))
    
  • Smaller grains, downsampled by an octave:
    (with-sound()(grani 0 8 3 
                        "/usr/ccrma/web/html/courses/220b/lectures/2/sounds/small-gong.snd" 
                        :grain-duration 0.06 :grain-density 40 
                        :grain-density-spread 5 :grain-start '(0 0.1 1 0.22) 
                        :srate -12))
    
  • Smaller grains, downsampled by a 0.3x factor. Note that we change the position were we start sampling the input file and create a big spread there so that we are actually jumping around randomly:
    (with-sound()(grani 0 8 3 
                        "/usr/ccrma/web/html/courses/220b/lectures/2/sounds/small-gong.snd" 
                        :grain-duration 0.06 :grain-density 40 :grain-density-spread 5 
                        :grain-start '(0 0.1 1 0.22) :grain-start-spread 0.2 :srate -12))
    
  • Three notes spread in the stereo field:
    (with-sound(:channels 2 :statistics t)
    (grani 0 8 0.4 "/usr/ccrma/web/html/courses/220b/lectures/2/sounds/tubular-bell.snd" 
           :grain-duration 0.06 :grain-density 20 :grain-density-spread 2 :srate 0)
    (grani 0 8 0.4 "/usr/ccrma/web/html/courses/220b/lectures/2/sounds/tubular-bell.snd" 
           :grain-duration 0.08 :grain-density 20 :grain-density-spread 2 :srate 5  
           :grain-degree 0)
    (grani 0 8 0.4 "/usr/ccrma/web/html/courses/220b/lectures/2/sounds/tubular-bell.snd" 
           :grain-duration 0.05 :grain-density 35 :grain-density-spread 3
           :srate -5 :grain-degree 90))
    

    Try replacing the turkish-cymbal-1.snd soundfile instead of the tubular-bell...


Here's the "one-cut" instrument, a soundfile mangling machine... (cut.ins). The included "one-cut" instrument can cut portions of an input soundfile and sample rate convert them. The sampling rate conversion is not limited to being a number, but can be affected by an envelope and sinusoidal and noise modulation components (periodic and random vibrato). The amplitude and frequency of the vibrato can be controlled through envelopes. Here are some parameter examples you can paste into a with-sound.

Mandatory parameters

start-time
starting time in seconds
amp
global amplitude multiplier
the duration of the output soundfile will be determined by the duration of the segment that is extracted from the input soundfile and the average sampling rate conversion factor over the duration of the segment.

Some of the optional parameters

After the name of the parameter I specify the type of parameter.

soundfile [string]
name of the input soundfile
sound-start [number]
start time of the segment of the input file to process, expressed as a fraction of the duration of the input file (0 = start of file, 1 = end of file)
sound-end [number]
end time of the segment of the input file to process, expressed as a fraction of the duration of the input file (0 = start of file, 1 = end of file)
sound-start-time [number]
start time of the segment of the input file to process, expressed in seconds (use instead of sound-start if you want to "think" in seconds)
sound-end-time [number]
end time of the segment of the input file to process, expressed in seconds (use instead of sound-end if you want to "think" in seconds)
duration [number or nil]
duration can be used to shorten the time of the output soundfile. If duration is less than the expected duration of the output soundfile then the output is forced to be shorted (the end is but). The default is "nil" (ie: don't force anything)
sample-rate [number]
sampling rate conversion ratio, 2.0 will play soundfile segment twice as fast as normal, 0.5 twice as slow and oso on and so forth
amp-func [envelope]
amplitude envelope
vib-osc-freq [number]
sinusoidal sampling rate conversion modulation (ie: vibrato) frequency. Numbers from 2 to 8 Hertz for best effect. No real limits for weird effects
vib-osc-freq-dev [number]
deviation in Hz of the amount of modulation
vib-osc-amp [number]
amplitude of the sinusoidal modulation
vib-osc-amp-func [envelope]
envelope for the frequency of the sinusoidal vibrato component
vib-noi-freq [number]
bandwidth of the random noise component for sampling rate conversion modulation
vib-noi-amp [number]
amplitude of random sampling rate conversion modulation
vib-noi-amp-func [envelope]
amplitude envelope for random sampling rate conversion modulation
vib-osc-freq-func [envelope]
frequency envelope for the sinusoidal component of the modulation
degree [number]
"locsig" angle between speakers (0 = left speaker, 90 = right speaker in two channel environments)
distance [number]
"locsig" distance parameter (1 = original amplitude, >1 = attenuated signal)
reverb-amount [number]
amount of sound to be sent to the reverb output stream.

Some loop macro examples, from the class

So here they are, keystroke by keystroke (including typos) "what the instructor typed in" guide to the loop macro and its use in (very coarse) control of clm instruments. Some comments were added to the code to make it clearer. You will need to compile and load the fm-violin instrument to make this examples work.

If you're slightly out of your mind you can actually look at the whole thing...

Here's a pointer to the Steele's Common Lisp book chapter on the loop macro

Bidimensional automata

xlife is installed in all machines, just type "man xlife" for the instructions on how to run it and "xlife" to run the program itself. Most probably the most interesting part is loading up interesting patterns that other folks have discovered. There are tons of those in /usr/lib/xlife/ (check out the PATTERNS readme in that directory).

Example lisp code by Scott Wilson that creates two dimensional cellular automata. And an addition by me that can read ".l" files with patterns for xlife. You can find patterns in /usr/lib/xlife/.


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