;;; -*- syntax: Lisp; font-size: 16; line-numbers: no; -*-

(define *srate* 44100)

;; additive instrument with 3 oscillators and one global amplitude envelope
(definstrument (additive-3envs start-time duration freq1 freq2 freq3 amp1 amp2 amp3 amplitude-envelope)
  " additive instrument with 3 oscillators and one global amplitude envelope"
  (let* ((start-sample (* start-time *srate*))
	 (end-sample (+ start-sample (* duration *srate*)))
	 (oscillator1 (make-oscil :frequency freq1))
	 (oscillator2 (make-oscil :frequency freq2))
	 (oscillator3 (make-oscil :frequency freq3))
	 (amp-env (make-env :envelope amplitude-envelope
			    :duration duration)))
    (do ((index start-sample (+ index 1)))
         ((> index end-sample))
	  (outa index (* (env amp-env) 
			 (+ (* amp1 (oscil oscillator1))
			    (* amp2 (oscil oscillator2))
			    (* amp3 (oscil oscillator3))))))))
#|
(with-sound  (:scaled-to .99 :statistics #t) 
  (additive-3envs 0 4 110 330 550 0.1 0.2 0.7 '(0 0 0.1 1 0.2 0.7 1 0)))
|#