Resource Interchange File Format (RIFF)

From ModdingWiki
(Redirected from RIFF)
Jump to navigation Jump to search

The Resource Interchange File Format (RIFF) is a structured file container designed by Microsoft in 1991, heavily based on the Interchange File Format (IFF) designed by Electronic Arts in 1985. As the IFF standard was developed on big-endian machines like the Commodore 64 and the Amiga, RIFF was produced as a little-endian alternative for Intel computers.

Structure

The file format is arranged as a series of chunks, with some inner chunks nested within the outer chunks. Beyond the initial "root" level objects, the nesting is entirely user-defined depending on the file format.

FOURCC

The FOURCC data type is used to identify each chunk type. It must conform to the following rules:

  • Alphanumeric characters only (A-Z, 0-9)
  • It cannot have embedded spaces, however if it is less than four characters then it should be padded with trailing spaces
  • Uppercase FOURCC codes are used for registered (official) types, while lowercase is used for prototype/unofficial types

Chunk

A chunk is defined as follows:

Type File format Description
FOURCC chunkID Chunk name
UINT32LE lenChunk Length of chunk data, in bytes. Does not include the pad byte.
BYTE[lenChunk] content Actual data of the chunk
BYTE pad Optional padding byte, only present if lenChunk is not a multiple of 2.

Standard chunks

Most of the chunk types and their content are specific to the data being stored, however there are two chunks that are well-defined for all RIFF files. These are the master chunk RIFF and the LIST chunk. All files contain only the RIFF chunk at the root level, and can include zero or more LIST chunks within the RIFF chunk (as well as other chunks of course.) These standard chunks follow the same structure as above, however the content for each chunk is defined as follows:

Type File format Description
FOURCC formatID Code specifying layout of child chunks
CHUNK[] chunk One or more additional chunks

The point of thinking of the format in this way is that there is a RIFF chunk at the start of the file, and the first four bytes of that chunk's data (formatID in the above table) tell you the file format. The rest of the content in the RIFF chunk is just made up of more chunks, and the content of each of those chunks is format specific.

Put another way, a RIFF file is arranged like so:

  • RIFF <len> <riff-format-id>
    • Zero or more chunks
    • Zero or more: LIST <len> <list-format-id>
      • Zero or more chunks
    • Zero or more chunks

The point here is that only the RIFF and LIST chunks can have subchunks in the official spec. However there is nothing stopping anyone from declaring that their own format has certain chunks that can contain subchunks as well.

RIFF types

The riff-format-id above (first four bytes of the RIFF chunk's content) specifies the type of file format. Known formats are:

riff-format-id File format Description
ACON Animated cursor (*.ani) Animated icon to use for mouse cursor
AVI AVI video (*.avi) Note code is padded with a space
DSMF DSIK Module Format (*.dsm) Module format from Digital Sound Interface Kit ! Unregistered FOURCC?
PAL ? RIFF Palette (note code is padded with a space)
RDIB ? RIFF Device Independent Bitmap
RMID RMI Format (*.rmi) RIFF MIDI music
RMMP ? RIFF Multimedia Movie
WAVE WAV Format (*.wav) Digital audio

LIST types

The list-format-id specifies the type of data in the LIST chunk. The only known formatID is INFO which stores metadata about the file in question. The subchunks within the INFO chunk all store various metadata attributes as ASCII text (with a single null byte to terminate the string.) Common subchunk FOURCCs are:

list-format-id Description
IART Artist name
ICOP Copyright string
ICRD Creation date as a string in YYYY-MM-DD format
ICMT Comments
INAM Name/title of the work
ISFT Software used to create the file

There are many more - see the standard and subsequent updates for a full list.

External links