[CM] Snd, CLM and make-oscil

Richard Liston liston@cc.gatech.edu
Sat, 13 Mar 2004 19:33:48 -0500


I'm trying to create a sine wave with a phase shift. To generate the
wave I've been using scm-simp from
http://www-ccrma.stanford.edu/software/snd/snd/clm.html

(definstrument (scm-simp start-time duration frequency amplitude)
  (let* ((beg (inexact->exact (floor (* start-time (mus-srate)))))
         (dur (inexact->exact (floor (* duration (mus-srate)))))
         (s (make-oscil :frequency frequency)))
    (run
      (lambda ()
        (do ((i 0 (1+ i)))
            ((= i dur))
          (outa (+ i beg) (* amplitude (oscil s)) *output*))))))


In Snd I can then do (with-sound () (scm-simp 0 3 660 .5)).

To do a phase shift I define a new instrument by tweaking scm-simp:

(definstrument (scm-sine-with-phase start-time duration frequency amplitude iphase)
  (let* ((beg (inexact->exact (floor (* start-time (mus-srate)))))
         (dur (inexact->exact (floor (* duration (mus-srate)))))
         (s (make-oscil :frequency frequency :initial-phase iphase)))
    (run
      (lambda ()
        (do ((i 0 (1+ i)))
            ((= i dur))
          (outa (+ i beg) (* amplitude (oscil s)) *output*))))))


But now when I call with-sound I get an error:

>(with-sound () (scm-sine-with-phase 0 3 660 .5 0))
vct-set!: wrong-type-arg: Wrong type argument in position 3 (expecting "a number"): #<unspecified>
>wrong-type-arg


Make-oscil seems happy enough when I call it separately with essentially
the same args. I did a backtrace but I'm not yet too proficient at
reading it:

>(bt)
In unknown file:
   ?: 6* [#<procedure #f (() # #)>]
   2: 7* [scm-sine-with-phase 0 3 660 0.5 3.14159265358979]
   2: 8  (let* ((beg #) (dur #) (s #)) (run (lambda () #)))
   5: 9  [run #<procedure #f (() (do # # #))>]

I'm kind of surprised at the 5th arg of scm-sine-with-phase, even though
I invoked this a few times earlier with an arg of "pi" there. Any ideas
what's up here?

Cheers,
Richard