diff 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
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/run/sound.clj	Sat Jun 23 20:34:14 2012 -0500
     1.2 +++ b/clojure/com/aurellem/run/sound.clj	Sat Jun 23 23:10:31 2012 -0500
     1.3 @@ -17,4 +17,29 @@
     1.4    (println (frequencies (sound-data))))
     1.5  
     1.6  
     1.7 -        
     1.8 \ No newline at end of file
     1.9 +(import javax.sound.sampled.AudioFormat)
    1.10 +(import com.aurellem.gb.WaveWriter)
    1.11 +
    1.12 +(def probable-format (AudioFormat. 44100 16 2 true false))
    1.13 +
    1.14 +(defn test-writing-file! [n]
    1.15 +  (set-state! (play-midi pony-csv))
    1.16 +  (let [target-file
    1.17 +        (File. "/home/r/proj/vba-clojure/test-sound.wav")
    1.18 +        writer (WaveWriter. target-file)]
    1.19 +    (dorun
    1.20 +     (for [y (range n)]
    1.21 +       (do
    1.22 +         (let [quanta 30]
    1.23 +           (run-moves @current-state (repeat quanta []))
    1.24 +           (let [data (sound-data)
    1.25 +                 step-section
    1.26 +                 (byte-array (take (* 2940 quanta) data))]
    1.27 +             
    1.28 +             (.process writer step-section probable-format))))))
    1.29 +     (.cleanup writer)
    1.30 +     (Thread/sleep 1000)
    1.31 +     (clojure.java.shell/sh
    1.32 +      "aplay"
    1.33 +      (.getCanonicalPath target-file))))
    1.34 +      
    1.35 \ No newline at end of file