diff clojure/com/aurellem/run/music.clj @ 468:85d9fa354f0b

got drums to work.
author Robert McIntyre <rlm@mit.edu>
date Fri, 04 May 2012 06:12:59 -0500
parents ac0ed5c1a1c4
children f28a3baa4c56
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/run/music.clj	Fri May 04 05:17:18 2012 -0500
     1.2 +++ b/clojure/com/aurellem/run/music.clj	Fri May 04 06:12:59 2012 -0500
     1.3 @@ -17,6 +17,9 @@
     1.4  (def sync-test
     1.5    (File. "/home/r/proj/vba-clojure/music/sync-test.mid"))
     1.6  
     1.7 +(def drum-test
     1.8 +  (File. "/home/r/proj/vba-clojure/music/drum-test.mid"))
     1.9 +
    1.10  
    1.11  (defn raw-midi-text [#^File midi-file]
    1.12    (:out 
    1.13 @@ -520,10 +523,18 @@
    1.14                      (int (* (:duration note-event) 0x100))))
    1.15        abstract-mini-midi)))
    1.16  
    1.17 +(def midi-code->gb-noise-code
    1.18 +  {nil 0xFF
    1.19 +   35 87
    1.20 +   38 20
    1.21 +   39 0
    1.22 +   })
    1.23 +
    1.24 +
    1.25  (defn noise-codes [code volume duration]
    1.26    (assert (<= 0 volume 0xF))
    1.27    (if (<= duration 0xFF)
    1.28 -    [(if (nil? code) 0xFF code)
    1.29 +    [(midi-code->gb-noise-code code code)
    1.30       (bit-shift-left volume 4)
    1.31       duration]
    1.32      (vec
    1.33 @@ -583,7 +594,6 @@
    1.34           (music-kernel wave-duty-1 wave-duty-2))
    1.35          (PC! program-target))))
    1.36  
    1.37 -
    1.38  (defn test-noise []
    1.39    (let [noise-pattern
    1.40          (concat (interleave (range 0x100) (repeat 0xF0) (repeat 255))
    1.41 @@ -595,7 +605,8 @@
    1.42          (PC! 0xC000))))
    1.43  
    1.44  (defn test-play-noise [noise-code]
    1.45 -  (println "playing-noise" noise-code)
    1.46 +  (Thread/sleep 300)
    1.47 +  (println "playing noise:" noise-code)
    1.48    (run-moves
    1.49     (let [noise-pattern
    1.50           (interleave (repeat 10 noise-code) (repeat 0xF0) (repeat 255))]
    1.51 @@ -603,13 +614,11 @@
    1.52           (set-memory-range 0xA900 (flatten noise-pattern))
    1.53           (set-memory-range 0xC000 (music-kernel 0 0))
    1.54           (PC! 0xC000)))
    1.55 -   (repeat 128 [])))
    1.56 +   (repeat 20 [])))
    1.57  
    1.58  (defn test-all-noises []
    1.59    (dorun (map test-play-noise (range 0x100))))
    1.60  
    1.61 -
    1.62 -
    1.63  (def C4 (partial note-codes 261.63))
    1.64  (def D4 (partial note-codes 293.66))
    1.65  (def E4 (partial note-codes 329.63))