diff clojure/com/aurellem/run/sound.clj @ 525:fa7676dbf6f2

sound recording test now works.
author Robert McIntyre <rlm@mit.edu>
date Sun, 24 Jun 2012 13:12:51 -0500
parents 7ef5c73ea8fa
children 2620d6318e8d
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/run/sound.clj	Sat Jun 23 23:10:31 2012 -0500
     1.2 +++ b/clojure/com/aurellem/run/sound.clj	Sun Jun 24 13:12:51 2012 -0500
     1.3 @@ -7,8 +7,9 @@
     1.4    (:require clojure.string)
     1.5    (:import [com.aurellem.gb.gb_driver SaveState])
     1.6    (:import java.awt.image.BufferedImage)
     1.7 -  (:import java.io.File))
     1.8 -
     1.9 +  (:import java.io.File)
    1.10 +  (:import javax.sound.sampled.AudioFormat)
    1.11 +  (:import com.aurellem.gb.WaveWriter))
    1.12  
    1.13  (defn sound-test []
    1.14    (step (mid-game))
    1.15 @@ -16,10 +17,6 @@
    1.16    (run-moves @current-state (repeat 10 []))
    1.17    (println (frequencies (sound-data))))
    1.18  
    1.19 -
    1.20 -(import javax.sound.sampled.AudioFormat)
    1.21 -(import com.aurellem.gb.WaveWriter)
    1.22 -
    1.23  (def probable-format (AudioFormat. 44100 16 2 true false))
    1.24  
    1.25  (defn test-writing-file! [n]
    1.26 @@ -30,16 +27,26 @@
    1.27      (dorun
    1.28       (for [y (range n)]
    1.29         (do
    1.30 -         (let [quanta 30]
    1.31 +         (let [quanta 1]
    1.32             (run-moves @current-state (repeat quanta []))
    1.33 -           (let [data (sound-data)
    1.34 +           (let [
    1.35 +                 
    1.36 +                 data (sound-data)
    1.37 +                 bytes (* 2 (com.aurellem.gb.Gb/getSoundFrameWritten))
    1.38                   step-section
    1.39 -                 (byte-array (take (* 2940 quanta) data))]
    1.40 -             
    1.41 -             (.process writer step-section probable-format))))))
    1.42 +                 (byte-array
    1.43 +                  (take (* bytes quanta) data))
    1.44 +
    1.45 +
    1.46 +                 ]
    1.47 +             (com.aurellem.gb.Gb/setSoundFrameWritten 0)
    1.48 +             (.process writer
    1.49 +                       ;;data
    1.50 +                       step-section
    1.51 +                       probable-format))))))
    1.52       (.cleanup writer)
    1.53       (Thread/sleep 1000)
    1.54       (clojure.java.shell/sh
    1.55        "aplay"
    1.56        (.getCanonicalPath target-file))))
    1.57 -      
    1.58 \ No newline at end of file
    1.59 +