Music Sequences

From z64 wiki
Jump to: navigation, search

Overview

The sequenced music in the Zelda 64 games follows a MIDI type format which is a slightly updated version of the format used by earlier games such as Super Mario 64. There are generally three different parts to the sequences:

Sequence Header
This is the part of the sequence that controls things such as master volume, tempo and loop settings.

Channel Header
Controls volume, pan, etc. and points to music data to be played back on each channel.

Music Data
Contains the data for which notes should be played, their velocity, length, etc.

Format

From here, all numbers will be given in hexadecimal unless stated otherwise.

Sequence Header Commands

D3 xx

Seems to be something to do with the sequence type or format; for Super Mario 64, xx is usually 80, for Zelda 64, xx is usually 20.

D5 xx

Unknown. xx usually takes the value of 32. For sequences that don't play any music xx is 46.

D7 xxxx

Enables channels given by xxxx (boolean, each channel is one bit).

9x yyyy

Points to a channel header offset. x is the channel number (0 - F) and yyyy is the offset of that channel's header relative to the start of the sequence file.

DB xx

Master volume control, xx is the volume.

DD xx

Tempo control, xx is the tempo value in beats per minute.

CC yyxx

Unknown. yy starts at zero and increases each time the command appears, xx is (always?) 73.

FD xx / FD yyyy

Timestamp (number of 'ticks' to wait before the next command is read, relative to tempo), variable length. If xx goes above 7F, add 8000 to it to get yyyy.

FB xxxx

Offset to loop from, xxxx is the offset relative to the start of the sequence file.

D6 xxxx

Disables channels given by xxxx.

FF

Marks the end of the sequence header.

Note: some sequences have the following data after the first four bytes of their sequence header:

D7FFFF 8776CCFF7786F3 vv F2 ww C801F3 xx [C801FA yyyy] FB zzzz

vv, ww and xx are unknowns, yyyy and zzzz seem to be pointers to 9x commands for different parts of the sequence within the sequence header. The part in square brackets is repeated in some sequences. Its purpose is currently unknown but it may be to do with continuing playback mid-sequence after returning to the area from a house/shop.

Channel Header Commands

C4

Initialises the channel for music playback.

8x yyyy

Points to music data to be played on the current channel. x is the 'note layer' to be used (8 - B), up to a maximum of four note layers can be loaded per channel. yyyy is the offset of the music data to be played, relative to the start of the sequence file.

DF xx (yy)

Channel volume. xx is the volume value, yy is a timestamp used between control changes (when the volume is changing constantly).

DD xx

Channel pan. xx is the pan amount, 00 = hard left, 3F = centre, 7F = hard right.

E9 xx

Priority. Unknown how it is used, takes the value of xx.

D4 xx

Effects level (echo). xx is the effect amount.

D8 xx (yy)

Vibrato amount, value of xx. Higher values can produce odd sounds. yy is a timestamp used between control changes.

D3 xx (yy)

Pitch bend amount, signed, value of xx. yy is a timestamp used between control changes.

C2 xx

Transposition, signed. xx is the number of semitones to transpose by.

C1 xx

Sets the instrument number, xx, to be used for the current channel.

FD xx / FD yyyy

Timestamp (see sequence header commands).

FF

Marks the end of the channel header.

Music Data

Things get a little more complicated here.

nn tt(tt) vv gg

Play note command, valid when nn >= 00 and nn <= 3F, where:
nn = Note value
tt(tt) = Variable length timestamp
vv = Note velocity
gg = Gate time

nn tt(tt) vv

Play note command, valid when nn >= 40 and nn <= 7F, where:
nn = Note value + 40
tt(tt) = Variable length timestamp
vv = Note velocity
Gate time in this case is the same as was used for the previous play note command.

nn vv gg

Play note command, valid when nn >= 80 and nn <= BF, where:
nn = Note value + 80
vv = Note velocity
gg = Gate time
Timestamp in this case is the same as was used for the previous play note command.

C0 xx / C0 yyyy

Timestamp / rest. Used when no music needs to be played for a set amount of time, xx/yyyy is the variable length timestamp value.

FC xxxx

Jumps to offset xxxx relative to the start of the sequence file and plays the data from there until it reaches the next FF command.

FF

Marks the end of the current music data.

Note: It seems that some of the channel header commands are valid for use in the music data but the only one that's really useful is the C2 command (transposition).

Differences with the Super Mario 64 format

In Super Mario 64, the 8x yyyy command appears as:

9x yyyy

Where x is the 'note layer' to use (0 - 3) and yyyy is the offset to load music data from relative to the start of the sequence file.
Super Mario 64 does not use the E9 (priority) command and does not seem to be compatible with the way Zelda 64 does control changes. There may be other differences but this has not been looked into fully as of yet.

Tips for converting from MIDI

Zelda note value = MIDI note value - 0x15
Zelda timestamp = (MIDI timestamp/0x80)*0x18

Instrument Sets

There is no master instrument index in Zelda 64 as there is for MIDI sequences, instead there are different instrument sets that contain the instruments needed to play each sequence. The instrument set a sequence uses is not defined in the sequence itself but is defined externally at the following offsets:
OoT Debug ROM: 0xBCC5BE + (seq_number*2)
MM (U) Decompressed: 0xC77A62 + (seq_number*2)

Here's a list of which sequences use which instrument sets:

OoT instrument sets list

Sequences that use instrument set number 0x00, Ocarina songs:

0x44
0x45
0x46
0x47
0x48
0x49

Sequences that use instrument set number 0x01, Actor Sounds:

none

Sequences that use instrument set number 0x02, Nature Sounds:

0x01

Sequences that use instrument set number 0x03, Hyrule Field:

0x02
0x03
0x04
0x05
0x06
0x07
0x08
0x09
0x0A
0x0B
0x0C
0x0D
0x0E
0x0F
0x10
0x11
0x12
0x13
0x14
0x15
0x16
0x17
0x19
0x1A
0x1B
0x1F
0x21
0x23
0x2B
0x2D
0x31
0x32
0x38
0x3B
0x43
0x4A
0x51
0x52
0x53
0x54
0x62
0x6C

Sequences that use instrument set number 0x04, Deku Tree:

0x1C

Sequences that use instrument set number 0x05, Market:

0x1D
0x3E

Sequences that use instrument set number 0x06, Title Screen:

0x1E

Sequences that use instrument set number 0x07, Jabu Jabu's Belly:

0x26

Sequences that use instrument set number 0x08, Kakariko Village (guitar):

0x27
0x4C

Sequences that use instrument set number 0x09, Fairy Fountain:

0x28
0x29
0x3A
0x3D
0x4B
0x4F
0x57
0x66
0x6A

Sequences that use instrument set number 0x0A, Fire Temple:

0x2A

Sequences that use instrument set number 0x0B, Dodongo's Cavern:

0x18

Sequences that use instrument set number 0x0C, Forest Temple:

0x2C

Sequences that use instrument set number 0x0D, Lon Lon Ranch:

0x2F

Sequences that use instrument set number 0x0E, Goron City:

0x30

Sequences that use instrument set number 0x0F, Kokiri Forest:

0x3C

Sequences that use instrument set number 0x10, Spirit Temple:

0x3F

Sequences that use instrument set number 0x11, Horse Race:

0x40
0x41
0x42

Sequences that use instrument set number 0x12, Warp songs (ocarina songs 2):

0x25
0x33
0x34
0x35
0x36
0x37
0x59

Sequences that use instrument set number 0x13, Goddess Cutscene:

0x4D
0x56
0x5D

Sequences that use instrument set number 0x14, Shooting Gallery:

0x4E

Sequences that use instrument set number 0x15, Zora's Domain:

0x50

Sequences that use instrument set number 0x16, Shop:

0x55

Sequences that use instrument set number 0x17, Ice Cavern:

0x58

Sequences that use instrument set number 0x18, Shadow Temple:

0x5B

Sequences that use instrument set number 0x19, Water Temple:

0x5C

Sequences that use instrument set number 0x1A, Blank?:

none

Sequences that use instrument set number 0x1B, Gerudo Valley:

0x5F

Sequences that use instrument set number 0x1C, Lakeside Laboratory:

0x60

Sequences that use instrument set number 0x1D, Kotake and Koume's Theme:

0x61

Sequences that use instrument set number 0x1E, Ganon's Castle (organ):

0x2E

Sequences that use instrument set number 0x1F, Inside Ganon's Castle:

0x63

Sequences that use instrument set number 0x20, Ganondorf Battle/Boss Battle 2:

0x5E
0x64
0x65
0x6B

Sequences that use instrument set number 0x21, Ending sequence 1:

0x67
0x69

Sequences that use instrument set number 0x22, Ending sequence 2:

0x68

Sequences that use instrument set number 0x23, Game Over/Fanfares:

0x20
0x22
0x24
0x39

Sequences that use instrument set number 0x24, Owl:

0x5A

Majora's Mask instrument sets list

Sequences that use instrument set number 0x00, Ocarina songs:

0x32
0x33
0x34
0x35
0x47
0x48
0x49
0x4A
0x51
0x5A
0x5B
0x5C
0x5D
0x5E
0x5F
0x61
0x7A

Sequences that use instrument set number 0x01, Actor Sounds:

none

Sequences that use instrument set number 0x02, Nature Sounds:

0x01

Sequences that use instrument set number 0x03, Termina Field:

0x02
0x03
0x08
0x09
0x0F
0x14
0x19
0x1A
0x1B
0x1D
0x1F
0x21
0x25
0x2B
0x31
0x38
0x3D
0x75

Sequences that use instrument set number 0x04, Lost Woods:

0x3E

Sequences that use instrument set number 0x05, Mini Game:

0x0E
0x27
0x2E

Sequences that use instrument set number 0x06, Fairy Fountain:

0x18
0x28
0x29
0x52

Sequences that use instrument set number 0x07, Romani Ranch:

0x2F

Sequences that use instrument set number 0x08, Horse Race:

0x40
0x41
0x42
0x72

Sequences that use instrument set number 0x09, Bremen Mask March:

0x53
0x55

Sequences that use instrument set number 0x0A, Game House:

0x46

Sequences that use instrument set number 0x0B, Zora's Domain:

0x36

Sequences that use instrument set number 0x0C, Shop:

0x44

Sequences that use instrument set number 0x0D, Ghost Shop:

0x2C

Sequences that use instrument set number 0x0E, Kotake And Koume:

0x43

Sequences that use instrument set number 0x0F, Game Over/Fanfares:

0x20
0x22
0x24
0x37
0x39
0x77
0x78
0x79

Sequences that use instrument set number 0x10, Owl:

0x45

Sequences that use instrument set number 0x11, Majora's Mask:

0x04
0x1E
0x69
0x6A
0x6B
0x7B

Sequences that use instrument set number 0x12, The Four Giants:

0x2D
0x4B
0x4C
0x4E
0x4F
0x54

Sequences that use instrument set number 0x13, Zora Music:

0x4D
0x58
0x59
0x62
0x63
0x64
0x67
0x68
0x6C
0x6D
0x6E

Sequences that use instrument set number 0x14, Woodfall Dungeon:

0x1C

Sequences that use instrument set number 0x15, Snowhead:

0x13
0x65

Sequences that use instrument set number 0x16, UFO Attack:

0x0D
0x66

Sequences that use instrument set number 0x17, Clock Tower:

0x05
0x0B
0x3A
0x57
0x60

Sequences that use instrument set number 0x18, Sword Game:

0x50

Sequences that use instrument set number 0x19, Clock Town:

0x06
0x07
0x12
0x15
0x16
0x17
0x23

Sequences that use instrument set number 0x1A, Ikana Canyon:

0x3B

Sequences that use instrument set number 0x1B, Song of Healing angry mask seller:

0x0A

Sequences that use instrument set number 0x1C, Southern Swamp:

0x0C

Sequences that use instrument set number 0x1D, Great Bay:

0x10

Sequences that use instrument set number 0x1E, Ikana Canyon:

0x11

Sequences that use instrument set number 0x1F, Kamaro's Dance:

0x2A

Sequences that use instrument set number 0x20, Milk Bar:

0x3C
0x56

Sequences that use instrument set number 0x21, Ikana Castle:

0x6F
0x70
0x7C
0x7D
0x7E

Sequences that use instrument set number 0x22, Kamaro's Song (flute):

0x71

Sequences that use instrument set number 0x23, Introduction:

0x76

Sequences that use instrument set number 0x24, Credits:

0x74

Sequences that use instrument set number 0x25, Credits 2:

0x7F

Sequences that use instrument set number 0x26, Goron City:

0x26
0x30
0x3F

Sequences that use instrument set number 0x27, Garo's Song:

0x73


Note: All the names for instrument sets given are based on when/what area they are used in.

Pointer table

At offset 0x001386A0 in code.zasm (Debug ROM only; other offsets for other ROMs, and the offset will need to be relative to the start of the ROM instead of code.zasm) is a halfword containing the number of sequences (0x006E), 14 bytes of padding and then the pointer table. The pointer table has the following format:

struct PointerTableEntry
{
  u32 relative_offset;     /* offset relative to start of audioseq file */
  u32 length;              /* length in bytes */
  u32 seq_type;            /* 0x02000000, 0x02010000, 0x02020000 */
  u32 padding;             /* NULL */
} SequencePointers[SeqCount];

Credits

messiaen, DeathBasket - Sequence format
messiaen - pointer table format
DeathBasket - Instrument set lists for OoT and MM
DeathBasket - Writing this