       (if (>= (calculate-rms this channel) threshold)
         (do
           (>> samples-held 0)
+          (maybe-toggle-gate this :open)
           (dequeue-from-buffer this channel))
         (if (<= (<< samples-held) hold)
           (do
             (aswap! samples-held inc)
+            (maybe-toggle-gate this :open)
             input-sample)
-          0.0))))
+          (do
+            (maybe-toggle-gate this :closed)
+            0.0)))))
 
   (add-to-rms [this channel sample]
     (aswap! rms-buffers update channel

  (add-to-rms [this channel sample])
  (calculate-rms [this channel])
  (queue-in-buffer [this channel sample])
  (dequeue-from-buffer [this channel]))

(defrecord Gate [config next buffers rms-buffers samples-held]
  w/IWorkerAudioNode
  (connect [this destination]
    (reset! next destination))

                :next         (atom nil)
                :buffers      (aatom {})
                :rms-buffers  (aatom {})
                :samples-held (aatom 0)
                :state        (aatom :closed)})))
