[CM] clm instrument compile problem

Michael Klingbeil michael at klingbeil.com
Tue Apr 15 09:11:42 PDT 2008

Thanks for your help and sorry about the other errors in the code I posted (cut and pasting from different versions).

After poking through other instruments, I noticed that gens from arrays were never assigned to temporaries, so I eventually came up with this same solution and all is well.

It seemed to me that if I declared "filter" to be of type mus-any that this should work. I spent quite a while poking through run.lisp and couldn't figure it out. I'm curious...

Bill Schottstaedt wrote:
> I think there's an extra ")" closing the let* prematurely, and
> you're referring to the filters array before it is declared.
> Given those changes, you would have gotten a complaint
> about "filter" because I haven't implemented setf on pointers, mainly
> to keep C level GC sane.  Here's a version that I think works:
> (definstrument combfile (time duration frequency amplitude 
>                              gain filename &key 
>                              (amp-env '(0 1 100 1)) 
>                              (file-start 0.0)) 
>  (if (not duration) (setf duration (- (sound-duration filename) file-start))) 
>  (if (not (listp frequency)) (setf frequency`(0 ,frequency 100 ,frequency))) 
>  (if (not (listp gain)) (setf gain `(0 ,gain 100 ,gain)))   
>  (if (/= *srate* (sound-srate filename)) 
>    (warn "input file sampling rate does not equal output sampling rate!")) 
>  (setf frequency (loop for (x y) on frequency by #'cddr 
>                        collect x 
>                        collect (/ *srate* y))) 
>  (let* ((beg (floor (* time *srate*))) 
>         (end (+ beg (floor (* duration *srate*)))) 
>         (srate (sound-srate filename)) 
>         (freqenv (make-env :envelope frequency 
>                            :duration duration)) 
>         (ampenv (make-env :envelope amp-env 
>                           :duration duration 
>                           :scaler amplitude)) 
>         (gainenv (make-env :envelope gain 
>                             :duration duration)) 
>         (chans (sound-chans filename)) 
>         (maxlen (1+ (ceiling (loop for y in (cdr frequency) by #'cddr 
>                                    maximize y)))) 
>         (filters (make-array chans))
>         (input (make-file->frame filename)) 
>         (frame (make-frame (sound-chans filename))) 
>         (inloc (floor (* file-start srate))))
>    (loop for n from 0 below chans do
> 	 (setf (aref filters n) 
> 	       (make-comb 
> 		:size 0.0 
> 		:scaler (second gain) 
> 		:max-size maxlen)))
> (run 
>   (loop for i from beg to end do 
>          (let (freq amp gain) 
>            (declare 
>             (type :integer i inloc chans) 
>             (type :float freq amp gain) 
>             (type :mus-any input frame) 
>             (type :mus-any* filters)) 
>            (file->frame input inloc frame) 
>            (incf inloc) 
>            ;; apply filter 
>            (setf freq (env freqenv)) 
>            (setf amp (env ampenv)) 
>            (setf gain (env gainenv)) 
>            (loop for n from 0 below chans do 
>                  (setf (mus-feedback (aref filters n)) gain) 
>                  (frame-set! frame n (* amp (comb (aref filters n) (frame-ref frame n) freq)))) 
>            (frame->file *output* i frame))))
>  (close-input input)))

More information about the Cmdist mailing list