(define *srate* 44100)

(definstrument (ringmodulation
    start-time duration frequency-envelope1 frequency-envelope2 amplitude-envelope)
  (let* ((start-sample (* start-time *srate*))
         (end-sample (+ start-sample (* duration *srate*)))
         (oscillator (make-oscil :frequency 0))
         (rm-oscillator (make-oscil :frequency 0))
         (freq-env1 (make-env :duration duration 
			     :envelope frequency-envelope1 
			     :scaler (hz->radians 1)))
	 (freq-env2 (make-env :duration duration 
			     :envelope frequency-envelope2 
			     :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-env2))
                                    (oscil oscillator (env freq-env1))))))))

#|
(with-sound (:srate 44100 :statistics #t) 
  (ringmodulation 0 20 
		  '(0 220 1 220) 
		  '(0 123 0.5 660 1 277)
		  '(0 0 0.01 1 0.99 1 1 0)))
|#

