(define *srate* 44100)

(definstrument (soundfile-ringmod 
    start-time duration soundfile frequency-envelope amplitude-envelope)
  (let* ((start-sample (* start-time *srate*))
         (end-sample (+ start-sample (* duration *srate*)))
         (readin (make-readin soundfile))
         (wavetable (make-src readin))
         (rm-oscillator (make-oscil :frequency 0))
         (freq-env (make-env :duration duration 
			     :envelope frequency-envelope 
			     :scaler (hz->radians 1)))
         (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)
                                 (* (oscil rm-oscillator (env freq-env))
                                    (src wavetable)))))))

#|
(with-sound (:srate 44100 :statistics #t) 
  (soundfile-ringmod 0 60 
		     "/Users/danielhensel/1-4.wav"  
		     '(0 220 0.5 440 1 110) 
		     '(0 0 0.01 1 0.99 1 1 0)))
|#