      (if loop-flag
        (set! (.-loop source) true)
        (set! (.-loop source) false))
-     (set! (.-buffer source) buff)
+     (set! (.-buffer source)
+           (if (keyword? buff) (get-sound buff) buff))
      (.connect source gain)
      (.connect gain (.-destination audio-context))
      (set! (.-gain.value gain) g)

(def audio-context (if js/window.AudioContext (js/window.AudioContext.) (js/window.webkitAudioContext.)))

(def default-gain 0.7)

(defn load-sound
  "Initiates a download of the url as a sound. Returns a channel.

    (.send req)
    c))

(defn register-sound
  [url]
  (when (apply or (map #(string/end-with? url %)
                       [".ogg" ".mp3" ".wav"]))
    (go
      (swap! !sounds
             assoc (string/url-keyword url)
             (<! (load-sound url))))))

(defn get-sound [key]
  (key @!sounds))

(defn play-sound
  "pass this a buffer, and an optional gain parameter, and the
  sound will be played to the speakers"
