view clojure/com/aurellem/run/sound.clj @ 524:7ef5c73ea8fa

working on recording sound. almost have it, but there is still unexplained popping sounds.
author Robert McIntyre <rlm@mit.edu>
date Sat, 23 Jun 2012 23:10:31 -0500
parents d00096b6bf17
children fa7676dbf6f2
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))
13 (defn sound-test []
14 (step (mid-game))
15 (println (frequencies (sound-data)))
16 (run-moves @current-state (repeat 10 []))
17 (println (frequencies (sound-data))))
20 (import javax.sound.sampled.AudioFormat)
21 (import com.aurellem.gb.WaveWriter)
23 (def probable-format (AudioFormat. 44100 16 2 true false))
25 (defn test-writing-file! [n]
26 (set-state! (play-midi pony-csv))
27 (let [target-file
28 (File. "/home/r/proj/vba-clojure/test-sound.wav")
29 writer (WaveWriter. target-file)]
30 (dorun
31 (for [y (range n)]
32 (do
33 (let [quanta 30]
34 (run-moves @current-state (repeat quanta []))
35 (let [data (sound-data)
36 step-section
37 (byte-array (take (* 2940 quanta) data))]
39 (.process writer step-section probable-format))))))
40 (.cleanup writer)
41 (Thread/sleep 1000)
42 (clojure.java.shell/sh
43 "aplay"
44 (.getCanonicalPath target-file))))