comparison clojure/com/aurellem/run/sound.clj @ 524:7ef5c73ea8fa

working on recording sound. almost have it, but there is still unexplained popping sounds.
author Robert McIntyre <rlm@mit.edu>
date Sat, 23 Jun 2012 23:10:31 -0500
parents d00096b6bf17
children fa7676dbf6f2
comparison
equal deleted inserted replaced
523:d00096b6bf17 524:7ef5c73ea8fa
15 (println (frequencies (sound-data))) 15 (println (frequencies (sound-data)))
16 (run-moves @current-state (repeat 10 [])) 16 (run-moves @current-state (repeat 10 []))
17 (println (frequencies (sound-data)))) 17 (println (frequencies (sound-data))))
18 18
19 19
20 20 (import javax.sound.sampled.AudioFormat)
21 (import com.aurellem.gb.WaveWriter)
22
23 (def probable-format (AudioFormat. 44100 16 2 true false))
24
25 (defn test-writing-file! [n]
26 (set-state! (play-midi pony-csv))
27 (let [target-file
28 (File. "/home/r/proj/vba-clojure/test-sound.wav")
29 writer (WaveWriter. target-file)]
30 (dorun
31 (for [y (range n)]
32 (do
33 (let [quanta 30]
34 (run-moves @current-state (repeat quanta []))
35 (let [data (sound-data)
36 step-section
37 (byte-array (take (* 2940 quanta) data))]
38
39 (.process writer step-section probable-format))))))
40 (.cleanup writer)
41 (Thread/sleep 1000)
42 (clojure.java.shell/sh
43 "aplay"
44 (.getCanonicalPath target-file))))
45