Mercurial > vba-clojure
annotate 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 |
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@523 | 10 (:import java.io.File)) |
rlm@523 | 11 |
rlm@523 | 12 |
rlm@523 | 13 (defn sound-test [] |
rlm@523 | 14 (step (mid-game)) |
rlm@523 | 15 (println (frequencies (sound-data))) |
rlm@523 | 16 (run-moves @current-state (repeat 10 [])) |
rlm@523 | 17 (println (frequencies (sound-data)))) |
rlm@523 | 18 |
rlm@523 | 19 |
rlm@524 | 20 (import javax.sound.sampled.AudioFormat) |
rlm@524 | 21 (import com.aurellem.gb.WaveWriter) |
rlm@524 | 22 |
rlm@524 | 23 (def probable-format (AudioFormat. 44100 16 2 true false)) |
rlm@524 | 24 |
rlm@524 | 25 (defn test-writing-file! [n] |
rlm@524 | 26 (set-state! (play-midi pony-csv)) |
rlm@524 | 27 (let [target-file |
rlm@524 | 28 (File. "/home/r/proj/vba-clojure/test-sound.wav") |
rlm@524 | 29 writer (WaveWriter. target-file)] |
rlm@524 | 30 (dorun |
rlm@524 | 31 (for [y (range n)] |
rlm@524 | 32 (do |
rlm@524 | 33 (let [quanta 30] |
rlm@524 | 34 (run-moves @current-state (repeat quanta [])) |
rlm@524 | 35 (let [data (sound-data) |
rlm@524 | 36 step-section |
rlm@524 | 37 (byte-array (take (* 2940 quanta) data))] |
rlm@524 | 38 |
rlm@524 | 39 (.process writer step-section probable-format)))))) |
rlm@524 | 40 (.cleanup writer) |
rlm@524 | 41 (Thread/sleep 1000) |
rlm@524 | 42 (clojure.java.shell/sh |
rlm@524 | 43 "aplay" |
rlm@524 | 44 (.getCanonicalPath target-file)))) |
rlm@524 | 45 |