Music 220a, Handout #1

1-Oct-97

Basics of synthesis and LISP

;;; plot a sine wave - copy and paste the output to EnvEd

(defun plot-a-sine-wave 
 (amplitude frequency duration &optional (phase 0)(s-rate 10.0))
 (loop for i from 0 to duration by (/ 1 (* frequency s-rate))
       do (format t "~4,4f ~4,4f " 
		  i (* amplitude (sin (+ (* 2 pi frequency i) phase))))))

;;; synthesize a sine tone (s-l-o-w-l-y-!)

(defun simp (start-time duration frequency amplitude)
  (let* ((beg (floor (* start-time sampling-rate)))
         (end (+ beg (floor (* duration sampling-rate)))))
    (loop for i from beg to end and j from 0 by 1 do
	  (outa i (* amplitude
		     (sin (* frequency two-pi (/ j sampling-rate))))))))
#|
(with-sound () (simp 0 2 440 .5))
|#