 (def MFCC_FREQ_BANDS    13)
 (def DEFAULT_BLOCK_SIZE 512)
 
+(defn- c-double [len]
+  (let [xtract-vs (xtract/new_double-array len)]
+    (doall
+     (map-indexed
+      (fn [idx f] (xtract/double_array_setitem xtract-vs idx (double 0.0)))
+      (range 0 len)))
+    xtract-vs))
+
+(defonce wav-buffer (c-double DEFAULT_BLOCK_SIZE))
+(defonce full-window (xtract/xtract_init_window DEFAULT_BLOCK_SIZE xtract-hann))
+(defonce spectrum-buffer (c-double DEFAULT_BLOCK_SIZE))
+(defonce peaks-buffer  (c-double DEFAULT_BLOCK_SIZE))
+(defonce arg-buffer    (c-double 5))
+(defonce windowed-buffer (c-double DEFAULT_BLOCK_SIZE))
+(defonce mel-filters (xtract/create_filterbank MFCC_FREQ_BANDS DEFAULT_BLOCK_SIZE))
 (defn raise-errors [result]
   (when result
     (cond

        f0-frames (remove (fn [frame] (let [stats (first (vals frame))]
                                        (= (:f0 stats) 0.0)
                                       )) frame-stats)
        n-f0s (count f0-frames)
        f0-totals (reduce (global-stats-reduce fields) {} f0-frames)]

    (let [means
          (-> {}
              (assoc :rms-amplitude          (/ (:rms-amplitude totals) n))
              (assoc :spectral-centroid      (/ (:spectral-centroid totals) n))
              (assoc :spectral-irregularity  (/ (:spectral-irregularity totals) n))
              (assoc :spectral-kurtosis      (/ (:spectral-kurtosis totals) n))
              (assoc :spectral-skewness      (/ (:spectral-skewness totals) n))

              ;;Only over non 0 frequencies
              (assoc :spectral-inharmonicity (/ (:spectral-inharmonicity f0-totals) n-f0s))
              (assoc :midi (/ (:midi f0-totals) n-f0s))
              (assoc :f0   (/ (:f0 f0-totals) n-f0s)))

          maxs {:spectral-centroid (max-for :spectral-centroid frame-stats)}]
      {:mean means
       :max maxs}
  )))

(comment

  (def all-wavs (filter #(.endsWith (.getName %) ".wav") (file-seq (io/file "/Users/josephwilk/Workspace/music/samples"))))
  (doseq [w (take 1000 all-wavs)]
    (try
      (let [wav (.getPath w) ;; "test/fixtures/test.wav" ;;(.getPath wav)
            _ (println wav)
            b-stats (block-stats wav 512)
            g-stats (global-stats b-stats)
            ]
        (println {:file wav :stats g-stats})
        )

      (catch Exception e true)
      ))

  (dotimes [i 1]
    (let [block-stats (block-stats "test/fixtures/test.wav")]

        (raise-errors r)
        (first cents)))))

(defn block-stats
  ([sample-path] (block-stats sample-path DEFAULT_BLOCK_SIZE))
  ([sample-path block-size]
