Difference between revisions of "BRSEQ (File Format)"

From Custom Mario Kart
Jump to navigation Jump to search
Line 59: Line 59:
 
|-
 
|-
 
| 0x89 || Byte[3] || Jump to the given offset (relative to the start of the sound data)
 
| 0x89 || Byte[3] || Jump to the given offset (relative to the start of the sound data)
 +
|-
 +
| 0x8a || Byte[3] || Call the given offset (push stack)
 
|-
 
|-
 
| 0xa0 || Cmd + Short[2] || Executes the command of following byte with a random number between the two provided shorts as first argument
 
| 0xa0 || Cmd + Short[2] || Executes the command of following byte with a random number between the two provided shorts as first argument
Line 71: Line 73:
 
|-
 
|-
 
| 0xa5 || Cmd + * + Short || Same as 0xa1, with time factor.
 
| 0xa5 || Cmd + * + Short || Same as 0xa1, with time factor.
 +
|-
 +
| 0xb1 || Byte || Release (time between a key release and zero amplitude)
 
|-
 
|-
 
| 0xc1 || Byte || Volume
 
| 0xc1 || Byte || Volume
 
|-
 
|-
| 0xd3 || Byte || Sustain (I.e. how long a piano keeps making a sound after releasing a key)
+
| 0xc8 || Byte || Tie enable
 +
|-
 +
| 0xd0 || Byte || Portamento time
 +
|-
 +
| 0xd1 || Byte || Attack (time until full amplitude is reached)
 +
|-
 +
| 0xd2 || Byte || Decay (time until the sustain amplitude is reached after full amplitude)
 +
|-
 +
| 0xd3 || Byte || Sustain level
 
|-
 
|-
 
| 0xc9 || Byte || Use portamento (pitch sliding time). Use of argument unknown.
 
| 0xc9 || Byte || Use portamento (pitch sliding time). Use of argument unknown.
 
|-
 
|-
 
| 0xf0 || Byte + Byte + Short || Extended command (see table below)
 
| 0xf0 || Byte + Byte + Short || Extended command (see table below)
 +
|-
 +
| 0xfd || - || Return (pop stack)
 
|-
 
|-
 
| 0xff || - || End of input
 
| 0xff || - || End of input

Revision as of 12:39, 24 February 2023

Under Construction
This article is not finished. Help improve it by adding accurate information or correcting grammar and spelling.

BRSEQ (Binary Revolution SEQuence) is a sub file format found in BRSAR files from games like Mario Kart Wii. It corresponds to the music data represented in a MIDI-like file, but in binary. Commands that process changes in attributes such as sound generation and volume change over time are described on this kind of file. Since the sequence data is simply a set of commands, sounds are actually producing using bank data (stored in BRBNK sub files) that corresponds to the sound source data.

File Format

File Header

The file starts with a file header that is 0x20 bytes long.

Offset Type Description
0x00 String File magic. Always RSEQ in ASCII.
0x04 UInt16 Byte order mark (BOM): The value is always 0xFEFF. If value 0xFFFE is read, then the false endian is used. Mario Kart Wii uses nearly always big endian (bytes 0xFE,0xFF).
0x06 UInt16 Version number of the file format.
0x08 UInt32 Length of the file in bytes.
0x0C UInt16 Length of this header in bytes.
0x0E UInt16 Number of sections.
0x10 UInt32 Offset to DATA section.
0x14 UInt32 Length of DATA section.
0x18 UInt32 Offset to LABL section.
0x1C UInt32 Length of LABL section.
0x20 End of this file header

DATA

The DATA starts with a header.

Offset Type Description
0x00 String Section magic. Always DATA in ASCII.
0x04 UInt32 Length of this section.
0x08 UInt32 Length of this header (always 0x0C).

After the header, the sound data is specified. It contains a series of bytes that represent different commands and parameters for the sound. The known commands and the format of their parameters are listed below. The 'Midi' type is a variable length argument whereby the most significant bit is used to tell the reader if the next byte should also be considered. A value of 1aaaaaaa 0bbbbbbb for example is converted to aaaaaaabbbbbbb.

Command Arguments Description
<0x80 Byte + Midi Plays a note. The command is the key (pitch), the first argument the velocity (how hard the key is struck) and the midi variable is the time the key is held.
0x81 Midi Sets the program number to use (sound idx in the bank file?)
0x89 Byte[3] Jump to the given offset (relative to the start of the sound data)
0x8a Byte[3] Call the given offset (push stack)
0xa0 Cmd + Short[2] Executes the command of following byte with a random number between the two provided shorts as first argument
0xa1 Cmd + Byte Executes the command of following byte with the value of a variable at the provided index as argument
0xa2 Cmd + * Process the following command only if a preceding comparison was true
0xa3 Cmd + * + Short Add a time factor (ex. fade-in) to operations that support it. The time is provided as an additional short that follows the next command's arguments.
0xa4 Cmd + * + Short Same as 0xa0, with time factor.
0xa5 Cmd + * + Short Same as 0xa1, with time factor.
0xb1 Byte Release (time between a key release and zero amplitude)
0xc1 Byte Volume
0xc8 Byte Tie enable
0xd0 Byte Portamento time
0xd1 Byte Attack (time until full amplitude is reached)
0xd2 Byte Decay (time until the sustain amplitude is reached after full amplitude)
0xd3 Byte Sustain level
0xc9 Byte Use portamento (pitch sliding time). Use of argument unknown.
0xf0 Byte + Byte + Short Extended command (see table below)
0xfd - Return (pop stack)
0xff - End of input

There also exist a number of extended commands. These typically take the form of F0 AA BB CC CC, with AA being the command and B and C being the first and second argument to this command. Preceding 0xa* commands can change the data format of C.

Command Description
0x80 Variable at index B is set to C (Var[B] = C)
0x81 Var[B] += C
0x82 Var[B] -= C
0x83 Var[B] *= C
0x84 Var[B] /= C
0x85 Var[B] = Var[B] << C (reversed if C is negative)
0x86 Var[B] = random between 0 and C
0x87 Var[B] &= C
0x88 Var[B] OR= C
0x89 Var[B] ^= C
0x8a Var[B] = ~C
0x8b Var[B] %= C
0x90 Var[B] == C (comparison)
0x91 Var[B] >= C
0x92 Var[B] > C
0x93 Var[B] <= C
0x94 Var[B] < C
0x95 Var[B] != C

LABL

Offset Type Description
0x00 String Section magic. Always LABL in ASCII.
0x04 UInt32 Length of this section.
0x08 UInt32 N = Number of sound labels.
0x0C UInt32[N] Offset to label, relative to offset 0x08 in this header.

This is the label structure.

Offset Type Description
0x00 UInt32 Offset to the sound data this label uses. Relative to the end of the DATA header.
0x04 UInt32 L = Length of label string.
0x08 String Label name.

Tools

The following tools can handle BRSEQ files:

  • rseq2midi (Converts BRSEQ to MIDI)