     ;(.connect source (.-destination context))
     ))
 
-(defn save-recording! [app-state audio-recorder audio-context]
-  (.stop audio-recorder)
-  (.getBuffers audio-recorder
-               (fn [buffers]
-                 (om/transact! app-state :recorded-buffers #(conj % (aget buffers 0)))
-                 (.clear audio-recorder))))
+(defn save-recording! [app-state audio-recorder audio-context analyser-node]
+  (let [buffer-length (.-frequencyBinCount analyser-node)
+        data-array (js/window.Uint8Array. buffer-length)]
+    (.getByteTimeDomainData analyser-node data-array)
+    (.stop audio-recorder)
+    (.getBuffers audio-recorder
+                 (fn [buffers]
+                   (om/transact! app-state :recorded-buffers #(conj % (aget buffers 0)))
+                   (.clear audio-recorder)))))
 
-(defn recorder-view [{:keys [audio-recorder is-recording audio-context] :as data} owner]
+(defn recorder-view [{:keys [audio-recorder is-recording audio-context analyser-node] :as data} owner]
   (reify
     om/IDisplayName (display-name [_] "recorder-view")
     om/IRender

    (init-state [_] {:canvas nil
                     :canvas-context nil
                     :canvas-width 400
                     :canvas-height 100})

    om/IDidMount
    (did-mount [_]
      (let [{:keys [canvas-width canvas-height]} (om/get-state owner)
            canvas (om/get-node owner "the-canvas")
            canvas-context (.getContext canvas "2d")]
        (draw-buffer! canvas-width canvas-height canvas-context recorded-buffer)))

    om/IRenderState
    (render-state [_ {:keys [canvas-width canvas-height]}]
      (dom/div nil
        (dom/canvas #js {:width canvas-width :height canvas-height :ref "the-canvas"} "no canvas")))))

(defn buffers-list-view [{:keys [recorded-buffers] :as data} owner]
  (reify
    om/IDisplayName (display-name [_] "buffers-list-view")
    om/IRender
    (render [_]
      (apply dom/div {:className "buffers-list"}
             (om/build-all buffer-view (:recorded-buffers data))))))

(defn mount-om-root []
  (om/root

                          :recorded-buffers []
                          :audio-context audio-context}))

(defn lin-interp [x0 x1 y0 y1]
  (fn [x]
    (+ y0
       (* (/ (- x x0)
             (- x1 x0))
          (- y1 y0)))))

(defn min-arr-val [arr]
  (loop [i 0 min-val (aget arr 0)]
    (if (= i (.-length arr))
      min-val
      (let [cur-val (aget arr i)]
        (if (< cur-val min-val)
          (recur (inc i) cur-val)
          (recur (inc i) min-val))))))

(defn max-arr-val [arr]
  (loop [i 0 max-val (aget arr 0)]
    (if (= i (.-length arr))
      max-val
      (let [cur-val (aget arr i)]
        (if (> cur-val max-val)
          (recur (inc i) cur-val)
          (recur (inc i) max-val))))))

(defn draw-buffer! [width height canvas-context data]
  (let [step (.ceil js/Math (/ (.-length data) width))
        amp (/ height 2)
        min-val (min-arr-val data)
        max-val (max-arr-val data)
        scale (lin-interp min-val max-val (- amp) amp)]
    (.log js/console "min of data: " min-val)
    (.log js/console "max of data: " max-val)
    (aset canvas-context "fillStyle" "silver")
    (.clearRect canvas-context 0 0 width height)
    (doseq [i (range width)]
      (doseq [j (range step)]
        (let [datum (.min js/Math (aget data (+ (* i step) j)) 1)
              height (scale datum)]
          (.fillRect canvas-context i amp 1 height))))))

(defn play-sound [context sound-data]
  (let [audio-tag (.getElementById js/document "play-sound")]
