annotate 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
rev   line source
rlm@523 1 (ns com.aurellem.run.sound
rlm@523 2 (:use (com.aurellem.gb saves gb-driver util constants
rlm@523 3 items vbm characters money
rlm@523 4 rlm-assembly))
rlm@523 5 (:use (com.aurellem.run util music title save-corruption
rlm@523 6 bootstrap-0 bootstrap-1))
rlm@523 7 (:require clojure.string)
rlm@523 8 (:import [com.aurellem.gb.gb_driver SaveState])
rlm@523 9 (:import java.awt.image.BufferedImage)
rlm@525 10 (:import java.io.File)
rlm@525 11 (:import javax.sound.sampled.AudioFormat)
rlm@525 12 (:import com.aurellem.gb.WaveWriter))
rlm@523 13
rlm@523 14 (defn sound-test []
rlm@523 15 (step (mid-game))
rlm@523 16 (println (frequencies (sound-data)))
rlm@523 17 (run-moves @current-state (repeat 10 []))
rlm@523 18 (println (frequencies (sound-data))))
rlm@523 19
rlm@524 20 (def probable-format (AudioFormat. 44100 16 2 true false))
rlm@524 21
rlm@524 22 (defn test-writing-file! [n]
rlm@524 23 (set-state! (play-midi pony-csv))
rlm@524 24 (let [target-file
rlm@524 25 (File. "/home/r/proj/vba-clojure/test-sound.wav")
rlm@524 26 writer (WaveWriter. target-file)]
rlm@524 27 (dorun
rlm@524 28 (for [y (range n)]
rlm@524 29 (do
rlm@525 30 (let [quanta 1]
rlm@524 31 (run-moves @current-state (repeat quanta []))
rlm@525 32 (let [
rlm@525 33
rlm@525 34 data (sound-data)
rlm@525 35 bytes (* 2 (com.aurellem.gb.Gb/getSoundFrameWritten))
rlm@524 36 step-section
rlm@525 37 (byte-array
rlm@525 38 (take (* bytes quanta) data))
rlm@525 39
rlm@525 40
rlm@525 41 ]
rlm@525 42 (com.aurellem.gb.Gb/setSoundFrameWritten 0)
rlm@525 43 (.process writer
rlm@525 44 ;;data
rlm@525 45 step-section
rlm@525 46 probable-format))))))
rlm@524 47 (.cleanup writer)
rlm@524 48 (Thread/sleep 1000)
rlm@524 49 (clojure.java.shell/sh
rlm@524 50 "aplay"
rlm@524 51 (.getCanonicalPath target-file))))
rlm@525 52