View difference between Paste ID: hMT9zsVd and i0f9uuYh
SHOW: | | - or go back to the newest paste.
1
(defn update-spectrum [mesh]
2
  (s/>->> [:p] [:spectrum-data]
3
       #(if (and (:updated %2) (minim/playing? %1))
4
          (let
5-
            [data (:data %2); (minim/get-realtime-data % 800) ;
5+
            [data (:data %2)
6
             l-data (:left data)
7
             r-data (:right data)
8-
             ; [ VARIANT-1 ]
8+
             ; [ VARIANT-1 ] --------------------------------------
9
             vertices (mapv (fn [x]
10
                             ; (println "r = " x " len =" (count l-data))
11
                             [(spec-x x (nth l-data x)) (spec-y x (nth r-data x)) 0]) (range 360)
12
                           ;[(spec-x x x) (spec-y x (nth r-data x)) (/ (- x) 5)]) (range 1000)
13
                           )
14-
             ; [ VARIANT-2 ]
14+
             ; [ VARIANT-2 ] --------------------------------------
15
;             f (fn [x]  [(spec-x x (nth l-data x)) (spec-y x (nth r-data x)) 0])
16
;             vertices (reduce (fn [c d] (into c [(spec-x d (nth l-data d)) (spec-y d (nth r-data d)) 0])) [] (range 360))
17
            ; _ (println vertices)
18-
             ; [ VARIANT-3 ]
18+
             ; [ VARIANT-3 ] --------------------------------------
19
;            max-x 360
20
;            vertices (doall (loop [acc [] x 0]
21
;                       (if (< max-x x) acc
22
;                         (let
23
;                           [v [(spec-x x (nth l-data x)) (spec-y x (nth r-data x)) 0]]
24
;                           (recur (concat acc v) (+ x 1))))))
25-
        ;;   position-buffer (vb-position vertices)
25+
26
             ]
27
          (update-vertex-buffer! mesh vb-type-position vertices)
28-
        ;;    (vertex-buffer! mesh position-buffer)
28+
29
            (start-spectrum-data-gatherer %1)))))
30
31
32
(defn update-vertex-buffer! [mesh|geom vb-type lazy-data]
33
  (let [data (apply concat lazy-data)
34
        ;_ (println "data =" lazy-data)
35
        vb (vertex-buffer?? mesh|geom vb-type)
36
        nio-buffer (.getData vb)]
37
    (if (> (count data) (.capacity nio-buffer))
38
      ; if the existing buffer length is shorter than data length, re-create the buffer
39
      (let
40
        [mesh (resolve-mesh mesh|geom)
41
         new-buffer (create-float-buffer data)]
42
        (vertex-buffer! mesh vb-type 3 new-buffer))
43
      ; if the existing buffer length is enough for data, re-use the buffer
44
      (do
45
        (.rewind nio-buffer)
46
        (.updateData vb (create-float-buffer data)))))