;;;
;;; A very simple ring modulation instrument
;;; (nando, Oct 14 '96)
;;; (nando, Jan 8 '01 -> clm2)

(definstrument rm (start-time duration carrier-freq modulator-freq amplitude
		   &key
		   (amp-env '(0 0 0.5 1 1 0)))
  (let* ((beg (floor (* start-time *srate*)))
	 (end (+ beg (floor (* duration *srate*))))
	 (carrier (make-oscil :frequency carrier-freq))
	 (modulator (make-oscil :frequency modulator-freq))
	 (envelope (make-env :envelope amp-env 
			     :scaler amplitude
			     :duration duration)))
    (run
     (loop for i from beg to end do
       (outa i (* (env envelope)
		  (* (oscil carrier)(oscil modulator))))))))

#|
very slow tremolo
(with-sound()(rm 0 4 440 0.5 0.1))

from tremolo to spectrum

(with-sound() (loop for time from 0 by 1.1 
	    for f from 10 by 10 below 150 
	    with ae = '(0 0 0.1 1 0.9 1 1 0) do
	    (rm time 1.2 440 f 0.1 :amp-env ae)))
|#

