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

(define *srate* 44100)
(define (additive-1env start-time duration frequency1 frequency2 frequency3 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 frequency1))
         (oscillator2 (make-oscil :frequency frequency2))
         (oscillator3 (make-oscil :frequency frequency3))
         (amp-env (make-env :envelope amplitude-envelope
                            :duration duration)))
    
     (do ((index start-sample (+ index 1)))
         ((> index end-sample))
       (outa index (* 0.33                ; scaled output (output must be <= 1)
                    (env amp-env) 
                    (+ (oscil oscillator1)
                       (oscil oscillator2)
                       (oscil oscillator3)))))))

(with-sound (:output "test.wav" )(additive-1env 0 4 110 330 550 '(0 0 0.1 1 0.2 0.7 1 0)))