;;; -*- Lisp -*-

(definstrument filter-noise (beg dur amp coeffs)
  (let* ((st (floor (* beg sampling-rate)))
	 (noi (make-randh :frequency (* .5 sampling-rate) :amplitude amp))
	 (order (length coeffs))
	 (flA (make-filter :order order
			   :x-coeffs nil
			   :y-coeffs nil))
	 (envs (make-array order :element-type 'envelope))
	 (nd (+ st (floor (* sampling-rate dur)))))
    (loop for e in coeffs and i from 0 do
      (setf (aref envs i) (make-env :envelope e :scaler 1.0 :start-time beg :duration dur)))
    (Run
     (loop for i from st to nd do
       (dotimes (k order)
	 (setf (aref (flt-b flA) k) (env (aref envs k))))
       (outa i (filter flA (randh noi)))))))

