Next Chapter
Previous Chapter
Table of Contents

Working with CLM

In this chapter we learn how to link Stella to new CLM instrument definitions. This chapter assumes some familiarity with Lisp, CLOS and the CLM system. To perform the examples you must have built Common Music with the CLM syntax enabled.

About Common Lisp Music (CLM)

Common Lisp Music, by William Schottstaedt (bil@ccrma.stanford.edu), is a powerful sound synthesis language implemented in Lisp and C. CLM is essentially a toolbox for instrument building. Although it comes with a number of instruments ready to use, most composers use CLM to define their own instruments. Visit the CLM home page for more information.

Given the potential for creating new instruments, we want to learn how extend Common Music to recognize new CLM instrument definitions.

definstrument

When used within Common Music, CLM's definstrument defines a CLM instrument and a Common Music event object for working with the instrument. With the exception of time, the slot declarations for the new object are the same as instrument's lambda parameter list. By default, Common Music assumes that time is passed to the instrument in its first parameter, no matter what the name the instrument calls it. See definstrument for more information.

The code for a working instrument can be found in the file fm.ins in the tutorial directory. Copy this file to your home directory before working with the examples.

CL

CLM instrument definitions must be compiled. Use the cl command to compile and load instrument or lisp source files:

Stella [Top-Level]: cl /user/hkt/fm

; --- Compiling file /user/hkt/fm.ins ---
; Compiling FM
; Writing fasl file "/user/hkt/fm.fasl"
; Fasl write complete
; Fast loading /user/hkt/fm.fasl.

Stella [Top-Level}: 
Now try out the new fm instrument:

Stella [Top-Level}: (with-sound () (fm 0 1 440 .25))
After waiting a few seconds you should hear something. If not, check to see if the volume is muted.

At this point we are ready to compose with the new instrument. The next example defines an algorithm that generates fm notes. The algorithm uses the pitches pattern macro because CLM instruments expect frequency values to be in Hz.

(algorithm test fm (length 10 amp .3 )
  (setf freq (item (pitches c4 d ef f g in heap)))
  (setf rhythm (between .1 .4))
  (setf dur (+ rhythm .2)))
Now test the new instrument by writing to a sound file and a score file:

Stella [Top-Level]: open /tmp/test.snd
Stream: #<File:"/tmp/test.snd">
Stella [Top-Level]: mix test 0
File:/tmp/test.snd
Channels: 1
Srate: 22050.0
Reverb: None
0.000... 0.173... 0.549...0.728... 0.932...
1.298... 1.574... 1.840... 2.155... 2.551...Done!

Stella[Top-Level]: open test.clm
Stream: #<File:"test.clm">
Stella [Top-Level]: mix test 0
Play file test.clm?(<cr>=Yes) <cr>
Channels: 1
Srate: 22050.0
Reverb: None

Stella [Top-Level]:

Next Chapter
Previous Chapter
Table of Contents