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