;;;
;;; Simple real-time demonstration of one pole filter
;;; nando, July 12 1998, updated Oct 27 1998
;;;

(defparameter onezero-a0 (control-allocate))
(defparameter onezero-a1 (control-allocate))
(defparameter onezero-amp (control-allocate))
(defparameter onezero-on-off (control-allocate))

(defpinstrument onezero-forever (&optional (tester t))
  (let* ((noise (make-randh :frequency (* 0.49 sampling-rate)))
	 (ozfilt (make-one-zero :a0 1.0 :a1 0.5))
	 (ampf (make-fcontrol onezero-amp))
	 (a0f (make-fcontrol onezero-a0))
	 (a1f (make-fcontrol onezero-a1))
	 (sample 0.0))
      (Run
       (loop for i from 0 do
	 (if (= (control onezero-on-off) 0.0) (loop-finish))
	 (setf (smpflt-a1 ozfilt)(fcontrol a1f)
	       (smpflt-a0 ozfilt)(fcontrol a0f)
	       sample (* (fcontrol ampf)(one-zero ozfilt (randh noise))))
	 (outa i sample)
	 (if tester (setf (tester-in) sample))))))

(make-controller "onezero" 2048
                 '(onezero-on-off "play" :toggle t)
                 '(onezero-a0 "a0" :slider -1.0 1.0)
                 '(onezero-a1 "a1" :slider -1.0 1.0)
                 '(onezero-amp "amplitude" :slider 0.0 0.75))
