view clojure/com/aurellem/exp/music.clj @ 597:2fda49e1d0c5

added dylan's chibi gb image.
author Robert McIntyre <rlm@mit.edu>
date Sat, 01 Sep 2012 18:37:19 -0400
parents ea5ed834be11
children
line wrap: on
line source
1 (ns com.aurellem.exp.music
2 "scratchpad namespace"
3 (:use (com.aurellem.gb gb-driver util constants
4 assembly saves
5 items pokemon status types
6 characters species moves
7 pokedex money rival-name
8 text-speed badges
9 pokemon-presets
10 ))
12 (:import java.io.File)
13 (:import [com.aurellem.gb.gb_driver SaveState]))
18 (defn analyze-music []
19 (clojure.pprint/pprint
20 (map (fn [[addr nums]]
21 [(hex addr) nums])
22 (apply harmonic-compare
23 (map read-state
24 ["song-1" "no-song-1"
25 "song-2" "no-song-2"
26 "song-3" "no-song-3"
27 "song-4"])))))
28 ;; there are only two addresses that alternate between only
29 ;; two unique values:
31 0xC0DE ;; lol code :)
32 0xC0DF
34 ;; perhaps they are the address of the current playing sound?
36 ;; after watching them for a while in different environments,
37 ;; I can tell that they're definately music related, but they
38 ;; _don't_ seem to be the address to the current track.
39 ;; they generally change whenever a substantually different
40 ;; sequence is played. maybe they control some high level
41 ;; setting in the synthesizer? They are only affected by the
42 ;; background music and not by pokemon cries, etc.
44 0xC001 ;; seems to change along with the music, but is much
45 ;; more stable than 0xC0DE and 0xC0DF. It _is_
46 ;; affected by sound effects. When a sound effect happens,
47 ;; is sometimes does not return to its previous value when the sound
48 ;; effect is done.
50 0xC000 ;; does not seem to be affected by music
52 ;; maybe 0xC001 - something is loaded with the actual sounds?
55 ;; replacing just the first 0xFF bytes starting at 0xC001 with those
56 ;; found in celadon changes the music to celadon city.
58 ;; this can't be the actual music because it doesn't have enough
59 ;; information.
61 ;; let's try to narrow down the bytes from the first 0xFF of celadon
62 ;; starting at 0xC001
64 (def celadon-song
65 [202 0 0 255 0 178 117 40 118 158 118 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
66 0 0 0 0 0 0 0 0 0 0 0 202 202 202 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
67 0 0 0 0 128 128 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
68 0 0 0 0 0 0 0 0 0 0 0 0 115 88 32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
69 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
70 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 5 5 1 1 1 1 1
71 1 1 1 1 1 1 1 1 12 12 12 1 1 1 1 1 128 128 128 0 0 0 0 0 5 4 4 0 4 3
72 4 0 178 194 32 0 180 196 32 0 3 0 0 144 1 0 66 31 0 2 2 32 48 0 0 0
73 0 0 0 0 0 0 0 0 0 0])
75 (def jiggly-song
76 [208 0 0 255 0 240 113 7 114 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
77 0 0 0 0 0 0 0 0 208 208 0 0 0 0 0 0 65 72 0 0 0 0 0 0 0 0 0 0 0 0 0
78 0 128 0 0 0 0 0 0 0 105 130 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 16 0 0 0
79 0 0 0 65 81 0 0 0 0 0 0 58 57 0 0 0 0 0 0 8 5 0 0 0 0 0 0 0 0 0 0 0
80 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
81 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 3 1 1 1 1 1 1 1
82 1 1 1 1 1 1 1 13 12 1 1 1 1 1 1 128 0 0 0 88 152 0 0 4 4 4 0 4 4 3 0
83 103 167 32 0 180 196 32 0 0 0 0 144 1 0 66 28 0 31 31 224 255 0 0 0
84 0 0 0 0 0 0 0 0 0 0])
86 (def fight-gym-leader-song
87 [234 0 0 255 0 0 92 43 94 112 95 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
88 0 0 0 0 0 0 0 0 234 234 234 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
89 0 192 192 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 7 0 0 0 0 0 0 33 17 17 0 0 0
90 0 0 68 82 0 0 0 0 0 0 89 90 57 0 0 0 0 0 8 8 0 0 0 0 0 0 0 0 0 0 0 0
91 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
92 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 4 4 1 1 1 1 1 1 1
93 1 1 1 1 1 1 12 12 12 1 1 1 1 1 192 192 192 0 88 152 0 0 7 5 4 0 4 4
94 3 0 179 195 32 0 180 196 32 0 3 0 0 104 1 0 65 176 0 8 8 224 255 0 0
95 0 0 0 0 0 0 0 0 0 0 0])
98 (def fight-gym-leader-song-simp
99 [
101 (Integer/parseInt "00000001" 2) ;; channel-on/off
103 0 ;; no-effect
105 ;; channel 0
106 0 ;; note-counter low 0xC006
107 92 ;; note-counter high 0xC007
109 ;; channel 1
110 43 ;; note-counter low 0xC008
111 94 ;; note-counter high 0xC009
113 ;; channel 2
114 112 ;; note-counter low 0xC00A
115 95 ;; note-counter high 0xC00B
117 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
119 1 ;; if zero, mute channel 0xC026
120 1 ;;
121 1 ;;
124 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
126 ;; square wave duty (only first two bits matter.)
127 ;; channel 0
128 (Integer/parseInt "10000000" 2) ;; 0xC03E
129 ;; channel 1
130 (Integer/parseInt "11000000" 2) ;; 0xC03F
132 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
133 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
134 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
135 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
138 4 4 4;; these change very quickly! 0xC0B6
140 0 0 0 0 0 0 0 0 0 0 0 0 0
142 ;; Tempo
144 ;; channel 0 tempo (higher is slower)
145 12 ;; 0xC0C6
147 ;; channel 1 tempo
148 12 ;; 0xC0C7
150 ;; channel 2 tempo
151 12 ;; 0xC0C8
153 0 0 0 0 0 0 0 0 0 0 0 0 0
155 7 ;; 0xC0D6 (transient pitch channel 0)
157 5 4 0 4 4 3 0
159 ;; volume
160 ;; channel 0 volume (first 4 bits)
161 (Integer/parseInt "11110000" 2) ;; 0xC0DE
162 ;; channel 1 volume (first 4 bits)
163 (Integer/parseInt "11000000" 2) ;; 0xC0DF
164 ;; channel 2 volume (unknown syntax)
165 (Integer/parseInt "00100000" 2) ;; 0xC0E0
167 0 0 0 0 0 0 0 0
169 104 ;; MASTER TEMPO 0xC0E9
171 0 0 0 0 0
174 8 ;; checksum? address?
175 ])
177 (defn change-music
178 ([#^SaveState state start length song]
180 (set-memory-range state (+ 0xC004 start)
181 (take length (drop start song))))
182 ([start length song]
183 (continue! (change-music (read-state "rlm-viridian-forest")
184 start length song))))
188 ;;0 0x90) blend between both, with end theme as well
190 ;; 0x05 0xEA is the limit to completely change song to celadon from
191 ;; viridian forest
193 ;; 0x05 0xEA is also sufficient to change music to celadon from
194 ;; a battle in viridian forest
196 (def minimal-celadon-song
197 (subvec celadon-song 0x05 0xEA))
199 ;; 0xC006 -- appears to be the song note counter.
200 ;; 0cC007 --