comparison 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
comparison
equal deleted inserted replaced
525:fa7676dbf6f2 526:2620d6318e8d
1 (ns com.aurellem.gb.gb-driver 1 (ns com.aurellem.gb.gb-driver
2 (:import com.aurellem.gb.Gb) 2 (:import com.aurellem.gb.Gb)
3 (:import java.io.File) 3 (:import java.io.File)
4 (:import javax.sound.sampled.AudioFormat)
4 (:import org.apache.commons.io.FileUtils) 5 (:import org.apache.commons.io.FileUtils)
5 (:import (java.nio IntBuffer ByteOrder))) 6 (:import (java.nio IntBuffer ByteOrder)))
6 7
7 ;; Savestates 8 ;; Savestates
8 9
191 (store-fn store) 192 (store-fn store)
192 (update-state))) 193 (update-state)))
193 ([new-data] 194 ([new-data]
194 (store-data @current-state new-data)))) 195 (store-data @current-state new-data))))
195 196
196 (let [store (byte-array Gb/SOUND_SIZE)] 197 (def gb-sound-format
197 (defn sound-data 198 "44100 hertz, linear PCM, 2 channels with 16 bits per sample."
198 ([](sound-data @current-state)) 199 (AudioFormat. 44100 16 2 true false))
200
201 (let [store (byte-array Gb/MAX_SOUND_BYTES)]
202 (defn sound-bytes
203 "Returns a byte array containting the sound samples
204 generated this step."
205 ([](sound-bytes @current-state))
199 ([state] 206 ([state]
200 (set-state! state) 207 (set-state! state)
201 (Gb/getFrameSound store) 208 (Gb/getFrameSound store)
202 store))) 209 (let [actual-bytes (* 2 (Gb/getSoundFrameWritten))]
203 210 (Gb/setSoundFrameWritten 0)
204 (let [store (byte-array (* 1470 2))] 211 (byte-array (take actual-bytes store))))))
205 (defn sound-data-2
206 ([](sound-data-2 @current-state))
207 ([state]
208 (set-state! state)
209 (Gb/getFrameSound2 store)
210 store)))
211 212
212 (def memory 213 (def memory
213 (cpu-data Gb/GB_MEMORY #(Gb/getMemory %))) 214 (cpu-data Gb/GB_MEMORY #(Gb/getMemory %)))
214 215
215 (def ram 216 (def ram