;;;
;;; A very simple wavetable instrument
;;; (nando, Oct 8 '96)
;;; (nando, Jan 8 '01 -> clm2)

(definstrument dowave (startime duration frequency amplitude harmonics)
  (multiple-value-bind (beg end) (times->samples startime duration)
    (let* (
	   ;; create a wavetable valled "waveform" with the harmonics
	   (waveform (partials->wave harmonics))
	   ;; create the table lookup unit generator
           (s (make-table-lookup :frequency frequency :wave waveform))
	   ;; add a simple amplitude envelope...
           (amp-env (make-env :envelope '(0 0 0.5 1 1 0)
			      :duration duration
			      :scaler amplitude)))
      (run
       (loop for i from beg to end do
	     (outa i (* (env amp-env)(table-lookup s))))))))
