#|
(definstrument simp (start-time duration frequency amplitude 
		             &key (amp-env '(0 0 50 1 100 0)))
  (let* ((beg (floor (* start-time *srate*)))
         (end (+ beg (* duration *srate*)))
         (s (make-oscil :frequency frequency))
         (amp (make-env :envelope amp-env :scaler amplitude
                        :duration duration)))
    (run 
     (loop for i from beg to end do
       (outa i (* (env amp) (oscil s)))))))
|#


#|
;; manual computation of sine wave; no oscil unit generator

(definstrument simp (start-time duration freq amplitude 
		             &key (amp-env '(0 0 50 1 100 0)))
  (let* ((beg (floor (* start-time *srate*)))
         (end (+ beg (* duration *srate*)))
         (amp (make-env :envelope amp-env :scaler amplitude
                        :duration duration))
	 (phase 0)) 
    (run 
     (loop for i from beg to end
	do
	(outa i (* (env amp) (sin phase)))
	(setf phase (+ phase (* 2 pi (/ freq *srate*)))) ))))

|#


#|
;; Gliss with manual starting and ending frequencies

(definstrument simp (start-time duration freq  amplitude 
		             &key (amp-env '(0 0 50 1 100 0))
			          (freq-end 440) )
  (let* ((beg (floor (* start-time *srate*)))
         (end (+ beg (* duration *srate*)))
         (amp (make-env :envelope amp-env :scaler amplitude
                        :duration duration))
	 (phase 0)
	 (delta-freq (/ (- freq-end freq) (* duration *srate*))))
    (run 
     (loop for i from beg to end
	do
	(outa i (* (env amp) (sin phase)))
	(setf phase (+ phase (* 2 pi (/ freq *srate*))))
	(setf freq (+ freq delta-freq))))))

|#

;; Gliss with frequency envelope

(definstrument simp (start-time duration freq-env  amplitude 
		             &key (amp-env '(0 0 50 1 100 0)))
  (let* ((beg (floor (* start-time *srate*)))
         (end (+ beg (* duration *srate*)))
         (amp (make-env :envelope amp-env :scaler amplitude
                        :duration duration))
	 (freq (make-env :envelope freq-env :duration duration))
	 (phase 0))
    (run 
     (loop for i from beg to end
	do
	(outa i (* (env amp) (sin phase)))
	(setf phase (+ phase (* 2 pi (/ (env freq) *srate*)))) ))))


