[CM] translating spirals into music CLM

Juan I Reyes juanig@ccrma.Stanford.EDU
Thu, 12 Jul 2007 18:30:42 -0400


> There's also an example of shepard tones in the ws.scm section
> of sndscm.html, complete with a purty picture that took me about 10
> times longer to make than the sound.

Here is my CLM rendition of Shepard Tones based on Bill's ws.scm and
from Charles Dodge's  Computer Music text. 

(definstrument shepard (beg dur amp &key
			    (incr .000001)
			    )
  (let* ((start (floor (* beg *srate*)))
	 (end (+ start (floor (* dur *srate*))))
	 (x 0.0)
	 (arr (make-array 12))) ;; we'll create  a 12 oscil bank
    ;;
    (do ((i 0 (1+ i)))          ;; initialize oscils
	((= i 12))
      (setf (aref arr i) (make-oscil :frequency 0.0)) )
    ;;
    (run
     (loop for i from start to end do
       (let ((y 0.00)
	     (oscbank 0.0))
	 ;; sum signal of twelve oscillators
	 (do ((i 0 (1+ i)))
	     ((= i (length arr)))
	   ;; get amplitude and oscillator phase offset
	   (let ((phoffset (+ x (/ i 12))))
	     (if (> phoffset 1) (setf phoffset (- phoffset 1)))
	     (setf y (- 4.0 (* 8.0 phoffset)))
	     (incf oscbank (* (exp (* -0.5 y y))
			  (oscil (aref arr i)
				 (hz->radians (expt 2.0 (*  (- 1 phoffset) 12.0))))))
	                          ;; to go up        ;;;(*  phoffset 12.0)
	     ))
	 (incf x incr)
	 (outa i (* amp oscbank)) )))
    ))

;;;(with-sound () (shepard 0 10 0.1))