annotate clojure/com/aurellem/exp/music.clj @ 521:bad7b7430245

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