Fork me on GitHub
#overtone
<
2018-05-12
>
rodrigojuarez12:05:34

Hi, I needed some help with overtone, I want to read an mp3 file and get the amplitude, but I’m a little bit lost with the library

rodrigojuarez12:05:47

Basically after that I want to display the data with quil

hlolli19:05:34

@rodrigo.juarez.inf

(def amp-atom (atom []))

(defn msg-handler [msg]
  (swap! amp-atom conj (nth (:args msg) 2)))

(on-event "/amp" msg-handler 1)

(demo (let [sample "/home/hlolli/samples/xx/note-060.wav"
            signal (play-buf:ar 1 (load-sample sample) :action FREE)
            peaks  (amplitude:ar signal 0 0)]
        (send-reply:ar 1 "/amp" [peaks] 1)))
Just a quick braindump, here you'll get all the amps into an atom. Don't evaluate on-event more than once or you'll get duplicates of everything.

hlolli19:05:02

you could also change the msg-handler to feed the data directly into quill (realtime), but the idea here is that you need send-reply to connect the two worlds of supercollider synth and overtone.

rodrigojuarez21:05:52

Yeah, what I want is basically the real time visualisation as you said

hlolli21:05:57

ah buffer-read, didn't know about that one, even easier, no need to record. But if you want realtime then I guess you need to dump the data into the update of your sketch. And send it at the fps rate, as for example 44100 Hz would mean 44040 numbers go to waste every second (on 60 fps).

hlolli21:05:05

so an idea would be to use (impule 60) and send that signal to the trigger parameter of send-reply, just need to choose the right signal to analyze, for amp and fft, fft is bit math, you would be sending window stored in a vector. Maybe this is no problem for you.