

;;;   original instrument was written by Christopher Burns

(define *srate* 44100)

(definstrument (soundfile-comb 
    start duration soundfile comb-frequency-envelope comb-resonance-envelope amplitude-envelope)
  (let* ((start-sample (* start *srate*))
         (end-sample (+ start-sample (* duration *srate*)))
         (readin (make-readin soundfile))
         (wavetable (make-src readin))
         (comb-filter (make-comb :size (/ *srate* 100) :scaler 0.8 :max-size *srate*))
         (freq-env (make-env :envelope comb-frequency-envelope
                             :duration duration))
         (res-env (make-env :envelope comb-resonance-envelope
                            :duration duration))
         (amp-env (make-env :envelope amplitude-envelope
                            :duration duration)))
   (do ((sample-number start-sample (+ sample-number 1)))
         ((> sample-number end-sample))
          (set! (mus-feedback comb-filter) (env res-env))
          (outa sample-number (* (env amp-env)
                           (comb comb-filter (src wavetable) 
				 (/ *srate* (env freq-env))))))))
#|
(with-sound (:srate 44100 :statistics #t) 
  (soundfile-comb 0 10 
		  "/Users/danielhensel/1-4.wav" 
		  '(0 220 1 330) 
		  '(0 0.999 1 0.999) 
		  '(0 0 0.9 0.3 1 0)))
|#
