[CM] Example of using CM with Csound
Larry Troxler
lt at westnet.com
Fri Jan 24 15:39:52 PST 2003
Here is a Csound orchestra and a lisp file that I hope can serve as an
example of using csound with Common Music. Please let me know if there
are any questions or comments about it.
Larry Troxler
-------------- next part --------------
(in-package :cm)
;; Set hook to run csound and generate a wav file
(set-sco-output-hook!
#'(lambda (fil)
(shell "csound -W -d -m0 -o csound.wav fm.orc ~a" fil)))
;; fm instrument class
(defobject fm (i)
(frequency amplitude amplitude-env
(mratio :initform 1) (index :initform 1) index-env sinetable)
(:parameters time dur frequency amplitude amplitude-env
mratio index index-env sinetable))
;; Linear envelope function table generator class
(defobject gen27 (f)
((num :accessor f-num) (size :initform 1025) (gen :initform 27) env)
(:parameters time size gen &rest env))
;; Harmonic sinusoids function table generator class
(defobject gen10 (f)
((num :accessor f-num) (size :initform 8192) (gen :initform 10) strengths)
(:parameters time size gen &rest strengths))
;; Define a sine wave table and envelope tables
(setf sine (new gen10 time 0 num 1 strengths '(1)))
(setf ampenv (new gen27 time 0 num 2 env '(0 0 250 1 750 1 1024 0)))
(setf idxenv (new gen27 time 0 num 3 env '(0 1 1024 0)))
;; output 20 random Fm notes.
(defun random-fm (n)
(process repeat n
output
(new fm :ins 1 :time (now) :amplitude .15
:amplitude-env (f-num ampenv)
:dur .1
:frequency (between 220 880)
:index (interp (now) 0 0 10 10)
:index-env (f-num idxenv)
:sinetable (f-num sine))
wait .25))
;; Write function table generators and our random notes to a csound score file
(events (list sine ampenv idxenv (random-fm 20)) "test.sco")
-------------- next part --------------
sr = 44100
kr = 4410
ksmps = 10
nchnls = 2
; FM instrument
instr 1
idur = p3
ifreq = p4
iamp = p5 * 32767
iampenv = p6
imratio = p7
iidx = p8
iidxenv = p9
isin = p10
kamp oscil1 0, iamp, idur, iampenv
kidx oscil1 0, iidx, idur, iidxenv
a1 foscili kamp, ifreq, 1, imratio, kidx, isin
outs a1, a1
endin
More information about the Cmdist
mailing list