NW > Sound > Sequence Sound (FSEQ)

This file contains a sequence sound. A sequence sound specifies which notes should be played at what time using instruments from a bank file.

Block idDescription
0x5000Data block
0x5001Label block

Data Block

OffsetSizeDescription
0x04Identifier ("INFO")
0x44Block size
0x8Data

A sequence track consists of a stream of commands. These are stored in the data block. Every command starts with a single byte that specifies the type of the command, which is usually followed by one or more parameters (depending on the command).

Time is divided into beats, which are futher divided into ticks. The default number of beats per minute is 120, and the default number of ticks per beat is 48.

Some commands operate on variables. These are accessed by index, and can be divided into the following categories:

VariableDescription
0 - 15Local variables (per sequence file)
16 - 31Global variables (shared for all sequence files)
32 - 47Track variables (per sequence track)

Command Table

Variable Length Int

Some commands take an integer of variable length. This integer is parsed as follows:

def read_varint():
    value = 0
    while True:
        byte = read_u8()
        value = (value << 7) | (byte & 0x7F)
        if not byte & 0x80:
            return value

Note Command

All commands between 0 and 127 play a note. The command number specifies the 'key'.

TypeDescription
Uint8Velocity
VarintLength

Sleep Command

TypeDescription
VarintNumber of ticks

Change Instrument Command

TypeDescription
VarintInstrument index

Start Track Command

TypeDescription
Uint8Track index
Uint24Start offset

Jump Command

This is a simple control flow command.

TypeDescription
Uint24Offset into data block

Set Ticks Per Beat Command

TypeDescription
Uint8Ticks per beat

Set Beats Per Minute Command

TypeDescription
Uint16Beats per minute

Alloc Tracks Command

This command specifies the number of tracks that are allocated for this sequence sound. If present, this command must be the first command in the data block.

TypeDescription
Uint16Track mask

End Command

This command stops the current track.

Extended Command

This command starts with a single byte that indicates the type of its subcommand.

SubcommandDescription
0x80 - 0x8BVariable operation
0x90 - 0x95Variable comparison

Variable Operation

TypeDescription
Uint8Variable index
Int16Value

Command IDDescription
0x80var = value
0x81var = var + value
0x82var = var - value
0x83var = var * value
0x84var = var / value
0x85var = var << value (negative value shifts to right instead)
0x86var is set to random value between 0 and value
0x87var = var & value
0x88var = var | value
0x89var = var ^ value
0x8Avar = ~value
0x8Bvar = var % value

Variable Comparison

TypeDescription
Uint8Variable index
Int16Value

This command compares a variable with a given value and writes the result (0 or 1) into the internal condition register of the command processor.

Command IDDescription
0x90var == value
0x91var >= value
0x92var > value
0x93var <= value
0x94var < value
0x95var != value

Label Block

OffsetSizeDescription
0x04Identifier ("LABL")
0x44Block size
0x84Number of labels
0xCReferences to labels (0x5100)

Label

All labels are aligned to 4 bytes.

OffsetSizeDescription
0x08Reference into data block (0x1F00)
0x84Name length without null terminator
0xCNull-terminated label name