BRSEQ (File Format)

From Custom Mario Kart
Jump to navigation Jump to search
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 Offset to data (Relative to start of this header).

Commands

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 VLQ 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 + VLQ 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.
0x80 VLQ Wait. Parameter describes the time (48 = quarter note)
0x81 VLQ Sets the program number to use (Instrument ID inside Bank File)
0x88 Byte + UInt24 Start another track. First argument is track number, the second one is the offset (relative to the start of the sound data)
0x89 Int24 Jump to the given offset (relative to the start of the sound data)
0x8a Int24 Call the given offset (push stack)
0xb0 Byte Time base (quarter note resolution)
0xb1 Byte Envelope Hold
0xb2 Byte Monophonic
0xb3 Byte Velocity Range (Not supported by Mario Kart Wii)
0xc0 Byte Pan
0xc1 Byte Volume
0xc2 Byte Main Volume
0xc3 Byte Transpose
0xc4 Byte Pitchbend
0xc5 Byte Pitchbend Range
0xc6 Byte Priority
0xc7 Byte Note Wait enable
0xc8 Byte Tie enable
0xc9 Byte Use portamento (pitch sliding time). Argument is the start key
0xca Byte Modulation Depth
0xcb Byte Modulation Speed
0xcc Byte Modulation Type
0xcd Byte Modulation Range
0xce Byte Portamento Speed
0xcf Byte Portamento Time
0xd0 Byte Attack (time until full amplitude is reached)
0xd1 Byte Decay (time until the sustain amplitude is reached after full amplitude)
0xd2 Byte Sustain level
0xd3 Byte Release (time between a key release and zero amplitude)
0xd4 Byte Loop start (Count)
0xd5 Byte Volume 2 (Total volume = Volume 1 * Volume 2)
0xd6 Byte Print variable (variable index; used for debugging)
0xd7 Byte Surround Pan
0xd8 Byte LPF cut-off frequency
0xd9 Byte FXSend A
0xda Byte FXSend B
0xdb Byte Main Send
0xdc Byte Initial Pan
0xdd Byte Mute enable
0xde Byte FXSend C
0xdf Byte Damper
0xe0 Int16 Modulation Delay
0xe1 Int16 Change Tempo (Default: 120)
0xe3 Int16 Sweep
0xf0 Byte + Byte + Int16 Extended command (see table below)
0xfc - End loop.
0xfd - Return (pop stack)
0xfe Int16 Allocate tracks (bitmask, starting from the lowest order bit as Track 0 up to Track 15; Track 0 ignored since it's always allocated)
0xff - End of input

Extended Commands

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 = 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

Prefix Commands

Prefix Commands define modifiers that allow settings to be made with a greater degree of freedom. Prefix Commands can be chained together.

Command Arguments Description
0xa0 Byte[2] Executes the command of following byte with a random number between the two provided shorts as first argument.
0xa1 Byte Executes the command of following byte with the value of a variable at the provided index as argument.
0xa2 - Process the following command only if a preceding comparison was true.
0xa3 * + Int16 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 * + Int16 Same as 0xa0, with time factor.
0xa5 * + Int16 Same as 0xa1, with time factor.

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)