Mercurial > vba-clojure
diff clojure/com/aurellem/gb/gb_driver.clj @ 526:2620d6318e8d
sound recording complete.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sun, 24 Jun 2012 13:34:15 -0500 |
parents | fa7676dbf6f2 |
children |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/gb/gb_driver.clj Sun Jun 24 13:12:51 2012 -0500 1.2 +++ b/clojure/com/aurellem/gb/gb_driver.clj Sun Jun 24 13:34:15 2012 -0500 1.3 @@ -1,6 +1,7 @@ 1.4 (ns com.aurellem.gb.gb-driver 1.5 (:import com.aurellem.gb.Gb) 1.6 (:import java.io.File) 1.7 + (:import javax.sound.sampled.AudioFormat) 1.8 (:import org.apache.commons.io.FileUtils) 1.9 (:import (java.nio IntBuffer ByteOrder))) 1.10 1.11 @@ -193,21 +194,21 @@ 1.12 ([new-data] 1.13 (store-data @current-state new-data)))) 1.14 1.15 -(let [store (byte-array Gb/SOUND_SIZE)] 1.16 - (defn sound-data 1.17 - ([](sound-data @current-state)) 1.18 +(def gb-sound-format 1.19 + "44100 hertz, linear PCM, 2 channels with 16 bits per sample." 1.20 + (AudioFormat. 44100 16 2 true false)) 1.21 + 1.22 +(let [store (byte-array Gb/MAX_SOUND_BYTES)] 1.23 + (defn sound-bytes 1.24 + "Returns a byte array containting the sound samples 1.25 + generated this step." 1.26 + ([](sound-bytes @current-state)) 1.27 ([state] 1.28 (set-state! state) 1.29 (Gb/getFrameSound store) 1.30 - store))) 1.31 - 1.32 -(let [store (byte-array (* 1470 2))] 1.33 - (defn sound-data-2 1.34 - ([](sound-data-2 @current-state)) 1.35 - ([state] 1.36 - (set-state! state) 1.37 - (Gb/getFrameSound2 store) 1.38 - store))) 1.39 + (let [actual-bytes (* 2 (Gb/getSoundFrameWritten))] 1.40 + (Gb/setSoundFrameWritten 0) 1.41 + (byte-array (take actual-bytes store)))))) 1.42 1.43 (def memory 1.44 (cpu-data Gb/GB_MEMORY #(Gb/getMemory %)))