;;; -*- syntax: Lisp; font-size: 16; line-numbers: no; -*-
(define *srate* 44100)

(definstrument (sine-env start-time duration frequency amplitude-envelope)
  (let* ((start-sample (* start-time *srate*))
         (end-sample (+ start-sample (* duration *srate*)))
         (oscillator (make-oscil :frequency frequency))
         (amp-env (make-env :envelope amplitude-envelope
                            :duration duration)))
    (do ((index start-sample (+ index 1)))
         ((> index end-sample))
          (outa index (* (env amp-env) (oscil oscillator))))))

; beep with smooth fade-in and fade-out 
(with-sound (:output "sine-env.aiff") (sine-env 0 5 220 '(0 0 0.5 1 1 0)))

