Mercurial > vba-clojure
diff clojure/com/aurellem/run/music.clj @ 537:04f61ade7879
allow repositioning of music data.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 25 Jun 2012 14:50:28 -0500 |
parents | 2de44c6184ee |
children | cd557c922cec |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/run/music.clj Mon Jun 25 14:23:16 2012 -0500 1.2 +++ b/clojure/com/aurellem/run/music.clj Mon Jun 25 14:50:28 2012 -0500 1.3 @@ -325,7 +325,12 @@ 1.4 (def music-1 0x11) 1.5 (def music-2 0x16) 1.6 1.7 -(defn music-kernel [wave-duty-1 wave-duty-2] 1.8 +(defn music-kernel 1.9 + [voice-1-address 1.10 + voice-2-address 1.11 + noise-address 1.12 + voice-1-wave-duty 1.13 + voice-2-wave-duty] 1.14 (flatten 1.15 [;; global initilization section 1.16 (clear-music-registers) 1.17 @@ -342,8 +347,8 @@ 1.18 1.19 ;; initialize frame 1 1.20 0x21 1.21 - 0x00 1.22 - 0xA0 ;; set HL to 0xA000 == music-start 1 1.23 + (reverse (disect-bytes-2 voice-1-address)) 1.24 + ;; set HL to voice-1-address 1.25 0x0E 1.26 0x00 ;; 0->C 1.27 0x06 1.28 @@ -357,8 +362,8 @@ 1.29 1.30 ;; initialize frame 2 1.31 0x21 1.32 - 0x00 1.33 - 0xB0 ;; set HL to 0xB000 == music-start 2 1.34 + (reverse (disect-bytes-2 voice-2-address)) 1.35 + ;; set HL to voice-2-address 1.36 1.37 0xF5 ;; push AF 1.38 0xC5 ;; push CB 1.39 @@ -367,8 +372,8 @@ 1.40 1.41 ;; initialize frame 3 (noise) 1.42 0x21 1.43 - 0x00 1.44 - 0xA9 ;; 0xA9OO -> HL 1.45 + (reverse (disect-bytes-2 noise-address)) 1.46 + ;; set HL to noise-address 1.47 1.48 0xF5 ;; push AF 1.49 0xC5 ;; push CB 1.50 @@ -378,11 +383,11 @@ 1.51 1.52 0xE8 ;; SP + 12; activate frame 1 1.53 12 1.54 - (music-step music-1 wave-duty-1 false) 1.55 + (music-step music-1 voice-1-wave-duty false) 1.56 1.57 0xE8 ;; SP - 6; activate frame 2 1.58 (->signed-8-bit -6) 1.59 - (music-step music-2 wave-duty-2 false) 1.60 + (music-step music-2 voice-1-wave-duty false) 1.61 1.62 0xE8 ;; SP - 6; activate frame 3 1.63 (->signed-8-bit -6) 1.64 @@ -581,14 +586,14 @@ 1.65 (map #(get % :duty 0) duty-info))})) 1.66 1.67 (defn midi-bytes [^File midi-file] 1.68 - (let [voice-1-target 0xA000 1.69 - voice-2-target 0xB000 1.70 - noise-target 0xA900 1.71 + (let [voice-1-target 0xC400 1.72 + voice-2-target 0xC800 1.73 + noise-target 0xCC00 1.74 program-target 0xC000 1.75 mini-midi (midi->mini-midi midi-file) 1.76 - long-silence (flatten (note-codes 20 0 5000)) 1.77 + long-silence (flatten (note-codes 20 0 3000)) 1.78 long-noise-silence 1.79 - (interleave (range 100) (repeat 0x00) (repeat 255)) 1.80 + (interleave (range 20) (repeat 0x00) (repeat 255)) 1.81 voice-1 (flatten (:voice-1 mini-midi)) 1.82 wave-duty-1 ((:duty mini-midi) 0 0) 1.83 1.84 @@ -596,7 +601,11 @@ 1.85 wave-duty-2 ((:duty mini-midi) 1 0) 1.86 1.87 noise (flatten (:noise mini-midi)) 1.88 - kernel (music-kernel wave-duty-1 wave-duty-2)] 1.89 + kernel (music-kernel 1.90 + voice-1-target 1.91 + voice-2-target 1.92 + noise-target 1.93 + wave-duty-1 wave-duty-2)] 1.94 1.95 {:voice-1 {:address voice-1-target 1.96 :data (concat voice-1 long-silence)} 1.97 @@ -605,7 +614,7 @@ 1.98 :noise {:address noise-target 1.99 :data (concat noise long-noise-silence)} 1.100 :kernel {:address program-target 1.101 - :data (music-kernel wave-duty-1 wave-duty-2)}})) 1.102 + :data kernel}})) 1.103 1.104 (defn play-midi [^File midi-file] 1.105 (let [bytes (midi-bytes midi-file)]