(define *srate* 44100)

(definstrument (soundfile-move-locsig 
    start-time duration soundfile &key
		(start 0)
		(distance 1)
		(pan 0)
		(channels 2)
		(amplitude-envelope '(0 0 .1 1 .9 1 1 0))
		(panorama-envelope '(0 45 1 45))
		(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 :input f :srate 0.0)) 
	 (loc (make-locsig :degree pan 
			   :distance distance 
			   :channels channels)) 
         (amp-env (make-env :duration duration 
                            :envelope amplitude-envelope))
         (srate-env (make-env :duration duration
                              :envelope srate-envelope
			      :scaler srt))
	 (pan-env (make-env panorama-envelope :duration duration)))
    
     (do ((sample-number start-sample (+ sample-number 1)))
        ((= sample-number end-sample))
	  (move-locsig loc (env pan-env) distance)
          (locsig loc sample-number (* (env amp-env)
				       (src wavetable (env srate-env)))))))

#|
(with-sound (:srate 44100 :channels 2)
  (soundfile-move-locsig 0 3.5 "/Users/danielhensel/1-4.wav" 
			 :channels 2
			 :panorama-envelope '(0 0 1 90)))

(with-sound (:srate 44100 :channels 4 :play nil)
  (soundfile-move-locsig 0 3.5 "/Users/danielhensel/1-4.wav"
			 :channels 4
			 :panorama-envelope '(0 0 1 360)))
|#