Given the potential for creating new instruments, we want to learn how extend Common Music to recognize new CLM instrument definitions.
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.
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