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

(defparameter onepole-a0 (control-allocate))
(defparameter onepole-b1 (control-allocate))
(defparameter onepole-amp (control-allocate))
(defparameter onepole-on-off (control-allocate))

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

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