Actions

SCHG

Music Hacking

From Sonic Retro

Revision as of 18:18, 4 December 2010 by Andlabs (talk | contribs)
Sonicretro-round.svg This article needs cleanup.

This article needs to be edited to conform to a higher standard of article quality.
After the article has been cleaned up, you may remove this message. See How to Edit a Page for help.

The contents of this page became too big and MediaWiki started acting up. General information about SMPS has been moved to Sega Retro. Sonic-related information will stay here. If this page becomes too big, it will need to be split apart further.

Sonic 1

Music Locations

  • Music Pointers: $71A9C
  • Sound Effect Pointers: $78B44

DAC Samples

  • DAC sample setup index: $D6

Each DAC pointer is listed one after another, and a single entry for one DAC sample is $8 bytes. The format is as follows:

Offset Size Description
$00-$01 Word Location of the DAC sample in decompressed driver.
  • NOTE: Value is little endian, so swap the bytes to get the real value.
$02-$03 Word Size of the compressed DAC sample in decompressed driver.
  • NOTE: Value is little endian, so swap the bytes to get the real value.
$05 Byte Sample rate/pitch. The lower the value, the faster the sample will play.
$06-$08 3 Bytes Unused/redundant.

Sonic 1 has 3 DAC sample slots - one for the kick, one for the snare, and one for the Timpani. The other pitches of Timpani ($88-$8B) are defined by a special table, located at $71CC4, and are fully editable to suit other samples using the Timpani slot ($83).

The DAC sample definitions within songs:

Value Sample
$81 Kick
$82 Snare
$83 Hi-Timpani
$84 Noise
$85 Noise
$86 Noise
$87 Sega Sound
$88 Hi-Timpani
$89 Mid-Timpani
$8A Low-Timpani
$8B Low-Timpani


Sonic 2 Beta

Music Locations

  • Music Pointers (These add to $F0000, for 98-9F): $F0000
  • Music Pointers (These add to $F8000): $F8000
    • Pointer to Music Pointers at $F8000: $EC79D
  • Sound Effect Pointers (These add to $F8000): $FF000
    • Pointer to Sound Effect Pointers: $EC08E

DAC Samples

  • Pointers to DAC Samples in Sonic 2 Beta: $ECDA6

Specifics...

  • $ECDA6 - Sample 81 pointer
  • $ECDA8 - Sample 81 length
  • $ECDAA - Sample 82 pointer
  • $ECDAC - Sample 82 length (skip FF)
  • $ECDAF - Sample 83 pointer
  • $ECDB1 - Sample 83 length
  • $ECDB3 - Sample 84 pointer
  • $ECDB5 - Sample 84 length (skip FF)
  • $ECDB8 - Sample 85 pointer
  • $ECDBA - Sample 85 length
  • $ECDBC - Sample 86 pointer
  • $ECDBE - Sample 86 length -- This one is tricky. You need to skip the second FF, as the first FF is valid.

These pointers are 4 bytes in size. First two bytes are the pointer to the sample (the pointers add to E0000, little endian, and don't follow the music pointer format. Simple 16-bit absolute), and the other two bytes are the length of the sample (also little endian). If you see an FF, skip it and move on to the next byte.

  • DAC Master List in Sonic 2 Beta: $ECDC1

These work similarly to the master playlist in concept.. The format is two bytes per sample. First byte defines the sample ID, and the second byte defines the rate that the sample is played at. The lower the rate value, the faster the sample is played. This is used to make certain samples (like toms) appear to have different pitches (high tom, low tom, etc). If you see an FF, skip it and move on to the next byte. If you touch the FF, you fuck the entire sound driver. Don't. :P

The DAC sample definitions within songs:

Value Sample
$81 Kick
$82 Snare
$83 Clap
$84 Scratch
$85 Hi-Timpani
$86 Hi-Tom
$87 Silent
$88 Hi-Timpani
$89 Mid-Timpani
$8A Low-Timpani
$8B Low-Timpani
$8C Mid-Tom
$8D Low-Tom
$8E Floor-Tom
$8F Clap


Sonic 2 Final

Music Locations

Sonic 2 Final

  • Music Pointers (These add to F8000): F8000
    • Specifics...
Pointer ID Address Sound Test ID Song name
81 $F84F6 08 Casino Night Zone (2 Player)
82 $F88C4 02 Emerald Hill Zone
83 $F8DEE 05 Metropolis Zone
84 $F917B 09 Casino Night Zone
85 $F9664 0B Mystic Cave Zone
86 $F9A3C 03 Mystic Cave Zone (2 Player)
87 $F9D69 07 Aquatic Ruin Zone
88 $FA36B 0A Death Egg Zone
89 $FA6ED 12 Special Stage
8A $FAAC4 11 Option Screens
8B $FAC3C 15 Ending
8C $FB124 14 Final Battle
8D $FB3F7 0E Chemical Plant Zone
8E $FB81E 13 Boss
8F $FBA6F 0D Sky Chase Zone
90 $FBD8C 04 Oil Ocean Zone
91 $FC146 0F Wing Fortress Zone
92 $FC480 0C Emerald Hill Zone (2 Player)
93 $FC824 01 2 Player Results Screen
94 $FCBBC 16 Super Sonic
95 $FCE74 06 Hill Top Zone
96 $FD48D 18 1-Up
97 $FD193 19 Title Screen
98 $FD35E 1A Stage Cleared
99 $FD57A 1B Game Over
9A $F8359 17 Invincibility
9B $FD6C9 1D Got an Emerald
9C $F803C 10 Hidden Palace Zone
9D $F823B 1F Underwater Timing
9E $FD797 1E Credits
  • Pointer to Music Pointers at $F8000: $EC810
  • Music Pointers (These add to F8000 and are for 98-9F, excluding continue): $F802A
    • Specifics...
Pointer ID Address Sound Test ID Song name
01 0F0002 1C Continue
  • Sound Effect Pointers (These add to F8000): $FEE91
    • Pointer to Sound Effect Pointers: $EC09C

DAC Samples

  • Pointers to DAC Samples in Sonic 2 Final: $ECF7C

Specifics...

  • $ECF7C - Sample 81 pointer
  • $ECF7E - Sample 81 length
  • $ECF81 - Sample 82 pointer
  • $ECF83 - Sample 82 length
  • $ECF85 - Sample 83 pointer
  • $ECF87 - Sample 83 length
  • $ECF8A - Sample 84 pointer
  • $ECF8C - Sample 84 length
  • $ECF8E - Sample 85 pointer
  • $ECF90 - Sample 85 length
  • $ECF93 - Sample 86 pointer
  • $ECF95 - Sample 86 length
  • $ECF97 - Sample 87 pointer
  • $ECF99 - Sample 87 length

These pointers are 4 bytes in size. First two bytes are the pointer to the sample (the pointers add to E0000, little endian, and don't follow the music pointer format. Simple 16-bit absolute), and the other two bytes are the length of the sample (also little endian). If you see an FF, skip it and move on to the next byte.

  • DAC Master List in Sonic 2 Final: $ECF9C

These work similarly to the master playlist in concept.. The format is two bytes per sample. First byte defines the sample ID, and the second byte defines the rate that the sample is played at. The lower the rate value, the faster the sample is played. This is used to make certain samples (like toms) appear to have different pitches (high tom, low tom, etc). If you see an FF, skip it and move on to the next byte. If you touch the FF, you fuck the entire sound driver. Don't. :P

The DAC sample definitions within songs:

Value Sample
$81 Kick
$82 Snare
$83 Clap
$84 Scratch
$85 Timpani
$86 Tom
$87 Bongo
$88 Hi-Timpani
$89 Mid-Timpani
$8A Low-Timpani
$8B Low-Timpani
$8C Mid-Tom
$8D Low-Tom
$8E Floor-Tom
$8F Hi-Bongo
$90 Mid-Bongo
$91 Low-Bongo

Master Playlist

Sonic 2 has a special "master playlist" that defines what music ID plays in what slot. It works by taking a base address - generally the start of a music bank - and, for each increment of the value, it reads ahead another word in the current ROM bank. So, say, $00 would be the first word in the bank ($00-$01), $01 would be the next ($02-$03), and so on. The base address for this bank, in both Sonic 2 Beta AND final, is $F0000, and the addressing range spans as far as the value can allow, which is two Z80 ROM banks ($10000 bytes).

However, as a simple guide to understanding how it works (at least, for the casual hacker), all values for the original, untouched music (for the most part, anyway) subtract $1 from the value. So, to change Track 81 to Track 82, change $80 to $81. $80 is $81, $81 is $82, etc. These values go up to slot $9F, or $1F (visually, anyway - the game still uses $80 > values internally) in the final version of the game. The only exception to this is in Sonic 2 Beta, where some songs use the upper $8000 bytes of the bank start address to store music (making the values for calling said music start with $00). The locations for the master playlist are as follows:

  • Master Playlist in Sonic 2 Beta: $ECE9F
  • Master Playlist in Sonic 2 Final: $ECF36

As previously mentioned, track 81 is represented by $80, 82 is reresented by $81, etc. If you see an $FF, skip it and move on to the next byte - these are compression bytes for the driver, and touching them will bork the decompressor in-game, and prevent the sound driver from booting. The "master playlist" is only in Sonic 2 (Beta/Final) as far as I know. If I find it in any other games, I will update this section.

Music Compression

In Sonic 2 Final, there is a compression applied to all music data in the game except for the credits. This format has been dubbed the saxman compression, named after the person who cracked the format. I will not note how to manually decompress this format -- Refer to saxman's hacking guide to do so. The music can be decompressed by using Magus' Sega Data Compressor. Refer to the pointer format to edit the music properly.

Real-Time Music Editing

Offset Z80 RAM Location Purpose
$001669 11F5 Master Playlist
$000C16 07A2 Pointer for Master Playlist
$000DF9 0985 Pointer for Sound Effects list


Sonic 3 and Knuckles

This section is at SCHG:Sonic_3_&_Knuckles/Music Editing.


Sonic 3D

Music Locations

  • Music Pointers (These add to $C0000): $D3233
  • Music Pointers (These add to $C8000): $D3245
  • Music Pointers (These add to $D0000): $D325D
    • Specifics...
Music ID Music Pointer Song name
These add to $C0000:
01 2480 Green Grove 1
02 8F91 Green Grove 2
03 A0A8 Rusty Ruin 1
04 E7B9 Rusty Ruin 2
05 95C7 Volcano Valley 2
06 4AD0 Volcano Valley 1
07 39D7 Spring Stadium 1
08 72E3 Spring Stadium 2
09 91F0 Diamond Dust 1
These add to $C8000:
0A 2480 Diamond Dust 2
0B DE8B Gene Gadget 1
0C BD96 Gene Gadget 2
0D A8A0 Panic Puppet 2
0E E0A8 The Final Fight
0F B396 Ending
10 55BB Bonus Stage
11 8FC6 Panic Puppet 1/Level Select Screen
12 12D0 Boss Theme 1
13 20D6 Boss Theme 2
14 98DD Intro
15 D9E1 Credits
These add to $D0000:
16 2480 Game Over
17 7F82 Congratulations: You have found the secret Level Select screen" screen
18 9886 Bonus Stage End
19 158B Extra Life
1A 658C Chaos Emerald Gain
1B 558D Invincibility
1C 2791 Main Menu
  • Sound Effect Pointers (These add to $D8000): $D3297

DAC Samples

Location and format of the DAC sample table is unknown.

The DAC sample mapping is identical to that of Sonic 3 with many of the later samples removed.

Real-Time Music Editing

Offset Z80 RAM Location Purpose
$001AD0 165C Music Pointers
$001778 1304 Pointer for Music Pointers
$00177A 1306 Pointer for Sound Effect Pointers
$001AD0 165C Music Pointers
$001B34 16C0 Sound Effect Pointers


Knuckles' Chaotix

Locations

  • Music Pointers (These add to $40000): $76AE9
  • Music Pointers (These add to $48000): $76B05
  • Music Pointers (These add to $50000): $76B33
Address Song
$40000 Door Into Summer
$40D61 Electoria
$41904 Speed of Sound
$428a6 Seascape
$4349a Midnight Greenhouse
$44220 New Moon
$4509c Labyrinth
$4536b Trial and Error
$45DEE Walkin'
$461be Hyper-Hyper
$468e5 Evening Star
$46Fe8 Moonrise
$474e3 Overture
$477f0 This Horizon
$48000 Take Off
$4836a Combination
$48a39 Take a Nap
$48c96 Surging Power
$4915d Mechanical Dance
$4951d Tube Panic
$49fb0 Crystal Nightmare
$4a58c Child's Song
$4ac3c Soda Pop
$4b082 Pendulum
$4b6f5 Silver Screen
$4bBFF Tachy Touch
$4c44e Chaotic World
$4c8fa Surprise!
$4cd0d Nice Meeting You
$4d0ef Have a Happy Day
$4d34c Reach the Goal
$4d53f High Five
$4d67a Decision
$4d81d From Party to Party
$4d9f4 Have Some Fun
$4dc41 Oriental Legend
$4e33d Steel Heart
$50000 Tribute
$509ac Destructive Power
$50c6a Just Another Day
$5400b Decision 2nd
  • Sound Effect Pointers (These add to $50000): $76B3B
  • PWM Table: $58000

PWM Samples

The note equivalents:

Value Sample
$81 Electric Kick
$82 Electric Snare
$83 Splash Cymbal
$84 Ride Bell
$85 High Tom
$86 Mid Tom
$87 Low Tom
$88 Electric Hi-Hat
$89 Crash Cymbal
$8A Clap
$8B Acoustic Kick
$8C Acoustic Snare
$8D Bell
$8E Fingers Snapping
$8F Cowbell
$90 High Click
$91 Low Click
$92 High Bongo
$93 Low Bongo
$94 High Timpani
$95 Low Timpani
$96 Silence


Sonic Crackers

Music Locations

  • Music Pointers: $0633F
    • Specifics...
Sound ID Song Location
$81 Electoria $10000
$82 Walkin' $1088C
$83 Hyper-Hyper $10BDA
$84 Evening Star $11210
$85 Moonrise $1172B
$86 Game Over $11B10

DAC Samples

Value Sample
$81 Kick
$82 Snare
$83 Tom
$84 Tom
$85 Tom
$86 Voice sample "Let's go!"
$87 Voice sample "Hey!"
$88 Beep/screech


Tricks of the Trade

Music porting

Ah, yes. Music porting. An infamous practice that many want to achieve. This section will explain the various methods of porting music from one game to another. If something is not possible, it will be noted.

Sonic 1 -> Sonic 2 Beta

This is one of the easier jobs in my opinion, but it can be a bit tough at first. The trick is to convert the pointer format from S1 to S2B format. First, you have to convert the header pointers. This is the easiest part, as all the pointers are simple relative pointers. So here's what you do...

First off, mark the location you want to place the music at in pointer form. EX: F8000 goes to 8000, which goes to 0080, etc etc. Then, take this base location and add the relative values to it. So if I was placing my music at F9CDE, and my voice pointer was 0312, I would add 312 bytes to F9CDE. This gives me F9FF0. I then take this and convert it into pointer form. An easy way to do so in this case is to simply remove the F. This leaves me with 9FF0, which I then byteswap. This leaves me with the final converted pointer of F09F. Do this for every pointer in the header, as the rest you can leave intact.

The next job is to convert all the pointers in the coordination flags that have them. There are 3 flags in total that do so: F6, F7, and F8. Become familiar with the syntax; Know which is the pointer and which is not. Converting proceeds as follows...

We'll start with an example of sorts. As I noted before, with coordination flag pointers in S1, signed values are used. FFFF is 0, etc. The math works in the same way as our last job, but this time we use different variables. Our base location is found out by marking the offset of the byte where the actual pointer is. In the case of F6 and F8, the byte after F6/F8. In the case of F7, skip two bytes after the F7 to where the pointer is. This is all in my syntax breakdowns, BTW.

Now that we have our base location, we can convert the pointer. Now remember, instead of 0000 being zero, in this case FFFF is zero. So if we want to convert our pointer easily, we have to make our pointer as simple as the header pointers. For negative jumps (below FFFF), we take the pointer value and subtract it from FFFF. This will leave us with a simple relative value. For example, if my S1 pointer was FFE6, I would subtract FFE6 from FFFF. This gives me 19 as a result, meaning this pointer is meant to locate data 19 bytes before our base location. Now we have to convert this into S2B form. Take your base location and subtract your result relative value (19 in my case) from it. For example, if my base location was FEE90 (90EE), I would subtract 19 bytes from it (my result value from the above operation). That would give me the offset of FEE77. I then convert this into pointer form, giving me the final converted pointer of 77EE.

For positive values (above FFFF), things are a bit simpler. Simply take the positive value and subtract 1 from it. Then, add it to your base location. So if my pointer was 0090, I subtract 1 from it. This gives me 8F. I then add this value to my base location, which was FEE90. FEE90 + 8F = FEF1F. Then, convert this into S2B pointer form. This gives me the final converted pointer of 1FEF. Fun, eh? =P

Remember to do this with ALL pointers in the song. You won't get off correcting two or three, I'll tell you that much. :P

Points to note

Always remember to change the music pointer to point to your new music. Otherwise you'll have done this all for nothing. Also, S1 voices are not entirely compatible with S2 voices. You may have to apply new voices to the song to make it sound right. This is why the instruments in Esrael's port of Marble zone sounded different; he had to make new ones.

Porting between Sonic 3K/3D/Crackers/Chaotix

This job is much simpler, as all pointers use the same format. There are two methods of porting this music between each other...

  1. Simply put the music in the "same" location according to pointer format. For example, having music at C0000 or C8000 would be the same as having it at 10000 or 18000. All the result pointers would be 0080. Get it? =P Simple copy and paste, and nothing else needs to be done. Just change the music pointer to point to the new music and presto! Ported music. This method limits your customization as where to put the music though, and I don't recommend it unless you are porting whole music banks or it is incredibly convenient. It is easier though, so hey. =P
  2. Modify all pointers inside the music (header and coordination flags) to go along with the new location you put it at. Here's a simple way to do so...

First off, take your original location, which is the beginning of the song. Then, work out where you are going to put the song. Convert both these values into pointer format. Now, work out the difference between these two values. For example, if the original location was F802A (2A80 in pointer format), and I wanted to put it at FD980 (80D9 in pointer format), then I would subtract my new location from my original location. So in my case, FD980 - F802A. This gives me 5956. Now, this will be your modifying value for each pointer. You add this location to each pointer in the song to get your converted pointer.

Let me give an example of a negative value. My original location was FA000 and my new location was F9027. This time, we switch the operation. FA000 - F9027 = FD9. This time, you subtract this value from each pointer in the song to get the converted pointer. So remember, if you are moving a song to a location before the original location, subtract. If you are moving it to a location beyond the original, add.

Points to note

If Sonic 3 music has D817 as the voice pointer, then it cannot be ported outside of S3K without being given a new voice set. Sonic 3K is the only game with this universal voice bank, and specifying it in any other game will have no effect.

Porting from Sonic 2 Beta to Sonic 3K/3D/Crackers/Chaotix

This is a very simple job, provided you have a good eye for detail. The trick is to replace the differing coordination flags between the two games. This is a simple task, and you can do it in two simple steps.

  1. Run a search in the song for coordination flag E3. This is the S2 flag to return. We need to replace this with the Sonic 3K/etc equivalent, F9. Change all valid instances of E3 to F9. This will fix awkward jumps in the song that were hindering porting before.
  1. Run another search in the song for coordination flag E9. This is the S2 flag to add a value to the current channel pitch. We need to replace this with the Sonic 3K equivalent, FB. Change all valid instances of E9 to FB. This will fix certain lagging in some songs, lack of pitch change, and even crashing.

When I mention valid instances, I mean that the values of E9 or E3 are not part of another coordination flag. Make sure you know the format of most coordination flags, as to avoid making fatal mistakes that may destroy your entire port.

Points to note

Some voices may be wrong. You will have to fix this manually, provided you know how.

Porting from Sonic 3K/3D/Crackers/Chaotix to Sonic 2 Beta

Just do the opposite of the method above; replace F9 with E3 and FB with E9.


Sonic Community Hacking Guide
General
Sonic Music Hacking Guide | SonED2 Manual
Game-Specific
Sonic the Hedgehog (16-bit) | Sonic the Hedgehog (8-bit) | Sonic Eraser | Sonic CD (prototype 510) | Sonic CD | Sonic CD (PC) | Sonic CD (2011) | Sonic 2 (Nick Arcade prototype) | Sonic 2 (Simon Wai prototype) | Sonic 2 (16-bit) | Sonic 2 (8-bit) | Sonic 2 & Knuckles | Dr. Robotnik's Mean Bean Machine | Sonic Triple Trouble | Sonic 3 | Sonic & Knuckles | Sonic the Hedgehog 3 & Knuckles | Sonic & Knuckles Collection | Sonic Crackers | Sonic 3D: Flickies' Island | Chaotix | Sonic R PC | Sonic Jam 6 | Sonic Advance | Sonic Advance 2 | Sonic Advance 3 | Sonic Battle | Sonic Adventure | Sonic Adventure DX: Director's Cut | Sonic Adventure DX: PC | Sonic Adventure (2010) | Sonic Shuffle | Sonic Adventure 2 | Sonic Adventure 2: Battle | Sonic Adventure 2 (PC) | Sonic Heroes | Shadow the Hedgehog | Sonic Riders | Sonic the Hedgehog (2006) | Sonic & Sega All-Stars Racing | Sonic Unleashed (Xbox 360/PS3) | Sonic Colours | Sonic Generations | Sonic Lost World | Sonic Forces
Legacy Guides
The Nemesis Hacking Guides The Esrael Hacking Guides
ROM: Sonic 1 | Sonic 2 | Sonic 2 Beta | Sonic 3

Savestate: Sonic 1 | Sonic 2 Beta/Final | Sonic 3

Sonic 1 (English / Portuguese) | Sonic 2 Beta (English / Portuguese) | Sonic 2 and Knuckles (English / Portuguese)
Move to Sega Retro
Number Systems (or scrap) | Assembly Hacking Guide | Subroutine Equivalency List | 68000 Instruction Set | 68000 ASM-to-Hex Code Reference | VDP Documentation | Official Sega 32X Documentation | Official Mega-CD Documentation | Official Sega Mega Drive Documentation