             (js/Array.prototype.reverse.call (.getChannelData buffer 1)))
           ; (.linearRampToValueAtTime (.-gain gain-node) 1 0)
           ; (.linearRampToValueAtTime (.-gain gain-node) 0 5)
-          ; (set! (.-buffer convolve-node) buffer)
+          (set! (.-buffer source) buffer)
           (set! (.-value (.-gain gain-node)) gain)
           (set! (.-value (.-playbackRate source)) rate)
-          (set! (.-buffer source) buffer)
-          (set! (.-type biquad-node) "notch")
-          (set! (.-value (.-frequency biquad-node)) 1000)
-          (set! (.-Q biquad-node) 1)
-          (set! (.-gain biquad-node) 1)
-          (set! (.-curve distort-node) (distortion-curve 400))
-          (set! (.-oversample distort-node) "4x")
-          (.connect source analize-node)
-          (.connect analize-node distort-node)
-          (.connect distort-node biquad-node)
+          ; (set! (.-Q biquad-node) 1)
+          ; (set! (.-gain biquad-node) 1)
+          ; (set! (.-type biquad-node) "notch")
+          ; (set! (.-value (.-frequency biquad-node)) 1000)
+          (.connect source biquad-node)
           (.connect biquad-node gain-node)
-          ; (.connect biquad-node convolve-node)
-          ; (.connect convolve-node gain-node)
           (.connect gain-node (aget ac "destination"))
           (.start source (.-currentTime ac) position)
           (js/setTimeout


(def ac (new window/AudioContext))

(defn distortion-curve [amount]
  (let [k (+ amount 3)
        pi (.-PI js/Math)
        n-samples 44100
        deg (/ pi 180)]
    (map
      #(let [x (/ (* 2 %) (- n-samples 1))]
          (/ (* k x 20 deg)
          (* (.abs js/Math x) (+ amount pi))))
      (range 44100))))

(defn play-clip [url position duration rate gain reverse]
  (let [xhr (new window/XMLHttpRequest)
        source (.createBufferSource ac)
        gain-node (.createGain ac)
        analize-node (.createAnalyser ac)
        distort-node (.createWaveShaper ac)
        biquad-node (.createBiquadFilter ac)
        convolve-node (.createConvolver ac)]
    (.open xhr "get" url true)
    (set! (.-responseType xhr) "arraybuffer")
    (set! (.-onload xhr) (fn []

    (.send xhr)))

(def url "http://static.kevvv.in/sounds/callmemaybe.mp3")

(defn n-loops [times seconds func]
  (when (< 0 times)
    (func times)
    (js/setTimeout
      #(n-loops (dec times) seconds func)
      (* 1000 seconds)
    )
  )
)

(n-loops 15 5 #(play-clip url (- 16 %) 10 % 1 (odd? %)))
