Make a custom Ocarina Song!All absolute addresses are for the Debug ROM. For other ROMs, use the search to find the right places. The relative offsets should be about the same.
Things you will need:
Hex editor (XVI32 is a good choice)
mml2m64 (more specifically z64seqrip and z64parser, which come with it)
N64 checksum fixer (GZRT works fine)
Changing the name of the song--Search for the text string that forms the name of the song (eg "Sun's Song" or "Song of Storms"). Replace all instances with the new name for your song.
--The start menu uses sprite text. Because of this, changing the name of the song on the start menu is beyond the scope of this tutorial.
Changing the Effect Actor--Open the Debug ROM up in a hex editor and go to BCAE14. Alternatively, search for 01 99 01 98.
--The 7 pairs of bytes correspond to the 7 songs. In order, they are
Saria's Song: BCAE14
Epona's Song: BCAE16
Zelda's Lullaby: BCAE18
Sun's Song: BCAE1A
Song of Time: BCAE1C
Song of Storms: BCAE1E
Scarecrow's Song: BCAE20
--Change the pair of bytes for the desired song to the actor number of the desired actor. Follow this link to the Actor List. If the actor you want isn't on that list, find an instance of said actor in the game, open up the corresponding map with UoT, and copy the actor number from there.
http://glitchkill.proboards.com/index.cgi?board=gdg55y&action=display&thread=463&page=1--The actor will be summoned with variable 0000 (Song of Time summons with variable 0001). Additionally, the actor can only be summoned in areas with its corresponding group. For example, summoning a cucco will work in Kakariko village, but not in Hyrule Field.
Changing the Activaton Sequence--Open the Debug ROM in your hex editor and go to BA8DA0. Alternatively, search for 06 00 04 03.
--The songs are stored in consecutive blocks of 9 bytes. They are in the following order.
Minuet of Forest: BA8DA0
Bolero of Fire: BA8DA9
Serande of Water: BA8DB2
Requiem of Spirit: BA8DBB
Nocturne of Shadow: BA8DC4
Prelude of Light: BA8DCD
Saria's Song: BA8DD6
Epona's Song: BA8DDF
Zelda's Lullaby: BA8DE8
Sun's Song: BA8DF1
Song of Time: BA8DFA
Song of Storms: BA8E04
Scarecrow's Song: BA8E0C
--The 9 bytes that make up each song consist of a first byte that tells the game how many notes are in the song, and then 8 bytes that represent the activation sequence. Each byte corresponds to a button press, as follows.
00 A
01 Cv
02 C>
03 C<
04 C^
Changing the playback notes--Open the Debug ROM in your hex editor and go to BA8120. Alternatively, search for 02 00 00 12 56.
--The songs are stored in consecutive blocks of 160 bytes, in the following order
Minuet of Forest:BA8120
Bolero of Fire: BA81C0
Serande of Water: BA8260
Requiem of Spirit: BA8300
Nocturne of Shadow: BA83A0
Prelude to Light: BA8440
Saria's Song: BA84E0
Epona's Song: BA8580
Zelda's Lullaby: BA8620
Sun's Song: BA86C0
Song of Time: BA8760
Song of Storms: BA8800
--Each note consists of 8 bytes. You can have up to 19 notes in the playback sequence, as the last note must be an end rest.
--Byte 1 controls the pitch of the note, as well as the note displayed. It is simply the number of half-steps between the note and Middle-C. The 5 default notes are listed below. FF indicates a rest, ie, no note is played.
02 A (D)
05 Cv (F)
09 C> (A)
0B C< (B)
0E C^ (D)
FF Rest
--Byte 2 is always 00 in game-defined songs. It seems to have no purpose. Odd.
--Bytes 3 and 4 are the duration of the note, in input frames. A value of 60 (0x3C) will give a note that lasts exactly 1 second.
--This is an unsigned short integer, so the maximum number of frames a note can last is 65535 (0xFFFF). Such a note would last over 18 minutes.
--If you don't want to calculate your own note durations, the following are a good choice.
06 Sixteenth note
0C Eighth note
18 Quarter note
30 Half note
48 Dotted Half note
60 Whole Note
--A rest of 00 duration signals the end of the song.
--If you want to have two consecutive notes with the same first byte, put a 01 duration rest between them. Otherwise, the song won't work.
--Bytes 5 and 6 are the volume, in the form of a short integer. Most ocarina songs use volumes between 5000 and 6000.
--Byte 7 is the pitch adjustment from the control stick. It is a signed byte. 7F is a whole step up, while 80 is a whole step down. Fractional steps up and down can be achieved with smaller values.
--Byte 8 is the vibrato from the control stick. Still investigating this.
--The playback sequence is what shows up when you learn the song and when the song plays on the start menu. Keep in mind that if you use sharp or flat notes in the playback sequence, you will have to match them when learning the song and when playing it on the start menu.
Editing the Sequence fileFirstly, you'll want to download mml2m64. We won't actually be using it, but we will be using the tools that come with it. It's also a nice thing to have anyways, as you can also use it to insert songs into the game. Additionally, you will need something that can fix the game's checksum. If you don't already have one in mind, GZRT is a perfectly good choice.
I'll also warn you now that this is going to be a lot harder than the other steps. If this is your first time doing this, I recommend you use the Song of Storms, as it is the easiest to work with.
--Use z64seqrip to extract the Sequence files. This part isn't wholly necessary, but it does make things easier. Refer to the readme file included with mml2m64 to find out how to use this.
--Find the file corresponding to the song you are modding. The song numbers can be found here. If you are using the Song of Storms, it is number 49.
http://web.archive.org/web/20080213144845/http://zso.krahs-emag.com/codes/codeinfo.html--The music track, which is what you're going to be editing, is encoded in a file format somewhat similar to the playback sequence above. There are 4 parameters for each note, which always appear in the following order.
Command -- This specifies both what note to play and the type of note. See below for more.
Timestamp -- This is the length of the note, in input frames. This works the same as the note length in the playback sequence.
Velocity -- This seems to allow for tempo adjustments (eg, ritardando). Most songs use values in the 70-7F range.
Duration -- This affects how much time the note actually plays. It allows you to make staccato and legato. The larger this is, the shorter the resulting note.
To figure out the Command value, first find your pitch value. The pitch value is the number of half-steps your note is above A1. Equivalently, it is 39 (0x27) plus the number of half-steps your note is above Middle C. The command value then depends on which of the 4 parameters you will be specifying.
0X00 + Pitch value -- All 4 parameters specified.
0X40 + Pitch value -- Duration is not included. The sequencer uses the default value
0X80 + Pitch value -- Timestamp is not included. The sequencer uses the previous value
0XC0 (fixed value) -- Rest. Velocity and Duration are not included.
0xFF (fixed value) -- End of track. No other parameters are included.
--For a simple yet effective way to translate your song into a sequence file, convert each note into pitch values and lengths using the same method as you did in the playback sequence. Then do the following.
Command Value: Add 0x67 to the pitch value. Use C0 for rests.
Timestamp: Simply copy the length.
Velocity: Use 0x78. Leave this out if the note is a rest.
Add C0 01 FF to the end of your sequence to complete it. If you are modifying Epona's Song, the Song of Time, or the Sun's Song, add a second C0 01 FF to the end of your sequence.
--Use the z64parser to interpret the sequence file. The thing we want from this is the offset of the music track. Scroll down to the bottom to find it. It should be the very first thing in the first line after the Music Track header (for the Song of Storms, it will be 0x96). Open the file in a hex editor and insert your sequence at that location.
--Your sequence need not take up the same amount of space as the original song's sequence, but it can't go past the end of the file. If your sequence doesn't take up the whole file, any values after its end will be ignored, so you can use them however you like. This is a good place to put your name, to mark that you made this track. However, don't delete any bytes from the end. It is best to keep the new file the same length as the original.
--If you want to change the tempo or master volume, go to the header section of the parsed music file. It will tell you the offset where these are stored. For the Song of Storms, the volume is at 0x0A, and the tempo is at 0xC.
--To insert your newly formed zseq file into the ROM, open the original zseq file, your new zseq file, and the ROM in hex editors. Search the ROM for the last 16 bytes of the original zseq file; this should immediately take you to the ROM's zseq file's location in memory. Now scroll up until you find the beginning of the zseq file. The file on the ROM will be the same length as the original zseq file. Now, starting with the beginning of the ROM's zseq file, block off a number of bytes equal to the number of bytes in the original zseq file, and delete them. Now, insert your zseq file into the ROM exactly where you deleted the ROM's file.
--There is one last thing you need to do. The sound files are part of the ROM's checksum, which you have now changed. Run your ROM through your chosen checksum fixer, and you're done.
Credit to the excellent people at glitchkill for most of the stuff not pertaining to the MIDI format.