             [clojure2d.color :as c]
             [clojure.java.io :refer :all]
             [clojure2d.math.joise :as j]
-            [clojure2d.math.vector :as v])
+            [clojure2d.math.vector :as v]
+            [criterium.core :as bench]
+            [clojure2d.math.random :as r])
   (:import [clojure2d.pixels Pixels]
            [clojure2d.math.vector Vec2 Vec3]))
 

    (/ tinterval (+ tau tinterval))))

(defmethod make-effect :simple-lowpass [_ conf]
  (let [alpha (calc-filter-alpha (:rate conf) (:cutoff conf))]
    (fn
      ([^double sample ^double prev]
       (let [s1 (* sample alpha)
             s2 (- prev (* prev alpha))
             nprev (+ s1 s2)]
         (StateWithS. nprev nprev)))
      ([] 0.0))))

(defmethod make-effect :simple-highpass [_ conf]
  (let [lpfilter (make-effect :simple-lowpass conf)]
    (fn
      ([^double sample state]
       (let [^StateWithS res (lpfilter sample state)]
         (StateWithS. (- sample (.sample res)) (.state res))))
      ([]
       (lpfilter)))))

;; BIQUAD FILTERS


;; state management functions and transducer operations
;; minimizing destructuring as much as possible...

(deftype StateWithS [^double sample state]
  Object
  (toString [_] (str sample))) ; sample and effect state, StateWithF or vector of StateWithF
(deftype StateWithF [f state]) ; effect and its state

(defn- next-effect
