(define *srate* 44100)
; soundfile-playback instrument

(definstrument (soundfile 
    start-time duration soundfile amplitude-envelope &optional (srt-conv 1.0))
  (let* ((start-sample (* start-time *srate*))
         (end-sample (+ start-sample (* duration *srate*)))
       	 (sf (make-readin soundfile))
         (wavetable (make-src sf))
         (amp-env (make-env :duration duration :envelope amplitude-envelope)))
    (do ((sample-number start-sample (+ sample-number 1)))
        ((= sample-number end-sample))
                               (outa sample-number (* (env amp-env)
                                 (src wavetable))))))
#|
(with-sound (:srate 44100 :statistics #t) 
  (soundfile 0 4 "/Users/danielhensel/1-4.wav" '(0 0 0.1 1 0.9 1 1 0) .7))
|#