;;;
;;; A very simple additive synthesis instrument
;;; (nando, Oct 8 '96)

(definstrument doadd (start-time duration frequency amplitude
		      &key
		      (partial1 1.0)(amp1 0.3)
		      (partial2 2.0)(amp2 0.3)
		      (partial3 3.0)(amp3 0.3)
		      (env '(0 0 0.5 1 1 0)))
  (multiple-value-bind (beg end) (get-beg-end start-time duration)
    (let* ((sine1 (make-oscil :frequency (* partial1 frequency)))
	   (sine2 (make-oscil :frequency (* partial2 frequency)))
	   (sine3 (make-oscil :frequency (* partial3 frequency)))
	   (amp-env (make-env :envelope env 
			      :scaler amplitude
			      :start-time start-time 
			      :duration duration)))
      (Run
       (loop for i from beg to end do
	     (outa i (* (env amp-env)
			(+ (* amp1 (oscil sine1))
			   (* amp2 (oscil sine2))
			   (* amp3 (oscil sine3))))))))))
