[CM] RE: FM how-to question

Bill Schottstaedt bil@ccrma.Stanford.EDU
12 Jun 2003 12:54:36 -0700


On Wed, 2003-06-11 at 15:32, Jon Monroe wrote:
> Hello Bill and others,
> 
> I chose the middle example, and am now getting a weird error message:

The error message you got:

> *** - STRING-EQUAL: argument #<IO: "/usr/src/clm/clm-2/sample.wav" ...

was referring to the line

         (len (sound-frames f))

because sound-frames in Clisp is expecting a filename.  There's no
good reason it couldn't also take an IO struct.  Your code (with one
change) works in the ACL CLM:

               (1+ i)

rather than (1 + i)

But Clisp is a hard case because it has no reasonable foreign function
interface, so your direct outa call within with-sound won't work
in that version of CLM.  The sound-frames problem can be fixed:

  (defun fullname (n)
    (if (stringp n)
	(namestring (full-merge-pathnames n))
      (if (IO? n)
	  (IO-name n)
	(progn
	  (warn "~A should be a filename" n)
	  n))))

(defun sound-frames (arg) 
  (check-header (fullname arg)) 
                (/ last-header-samples last-header-chans))

I made this change (or its equivalent) to today's CLM;
but the only way to get output from the Clisp CLM is to
write an instrument:

(definstrument pm-file (file frequency)
   (let* ((f (open-input file))
	  (reader (make-readin f))
	  (len (sound-frames file))
	  (freq (hz->radians frequency)))
     (run
      (loop for i from 0 to len do
	(outa i (* .5 (cos (+ (* i freq) (readin reader)))))))))

after compiling and loading this, the with-sound is:

(with-sound () (pm-file "sample.wav" 440.0))