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

(definstrument (soundfile-varstart start-time duration soundfile &key
					     (start 0)
					     (amplitude-envelope '(0 0 .1 1 .9 1 1 0))
					     (srt 1)
					     (srate-envelope '(0 1 1 1)))
  (let* ((start-sample (* start-time *srate*))
         (end-sample (+ start-sample (* duration *srate*)))
	 (input-start (* *srate* start))      
       	  (f (make-readin soundfile :start input-start))
         (wavetable (make-src f))
         (amp-env (make-env :duration duration 
                            :envelope amplitude-envelope))
         (srate-env (make-env :duration duration
                              :envelope srate-envelope
			      :scaler srt)))
    (do ((sample-number start-sample (+ sample-number 1)))
        ((= sample-number end-sample))
          (outa sample-number (* (env amp-env)
                                 (src wavetable (env srate-env)))))))

(with-sound (:srate 44100 :output "playback-varstart.aiff")
  (soundfile-varstart 0 3  "/Users/danielhensel/1-4.wav" :start 1))
|#
