Basic Description
RIFFs are capable of holding various types of data. The file extension for RIFFs is dependent on its content.Examples are:
- ANI for animated cursors
- AVI for videos
- BND file bundles
- DXR Macromedia Director Files (notice: Network byte order!)
- PAL for color palette information
- RDI for bitmaps
- RMI for MIDI
- WAV for digital audio
Basic File Format
The price for the flexibility of holding different types of data is a file structure, that isn't easy to understand. A RIFF is - more or less - a hierarchical structure. The 'directory entries' are defined by chunks. Every chunk contains either data or a list of chunks. This document will occasionally refer to the analogy of a file system, every chunk is either a file or a subdirectory. All chunks have the same structure:Name | Size | Description | |
---|---|---|---|
ID | 4 byte | four ASCII character identifier, padded with ASCII 32 (space) if less than 4 characters | |
Size | 4 byte | size of Data | |
Data | Size bytes | the 'payload' |
Structure of the 'RIFF', 'RIFX', and 'LIST' chunks
The first chunk is the root entry and must have a ID of 'RIFF' or 'RIFX', the prior being the most common version. 'RIFX' specifies 'Motorola' byte order (most significant byte first), whereas 'RIFF' specifies 'Intel' byte ordering (least significant byte first). This document will stick to 'RIFF'. That first chunk contains all other chunks of the file in its Data. Its Size field will therefore always contain a value of filesize - 8.The structure of Data is dependent on its ID. There are two directory- IDs, 'RIFF' and 'LIST'. They contain a 4-byte ASCII header, leaving the following structure:
Name | Size | Description | |
---|---|---|---|
ID | 4 byte | four ASCII character identifier | |
Size | 4 byte | size of Data | |
Data | Size bytes | the 'payload' | |
HeaderID | 4 bytes | 'Name' of the list | |
Data Size | 4 bytes | List of chunks |
Structure of the 'JUNK' chunk
To align RIFF chunks to certain boundaries (i.e. 2048bytes for CD-ROMs) the RIFF specification includes a JUNK chunk. Its contents are to be skipped when reading. When writing RIFFs, JUNK chunks should not have odd number as Size.Name | Size | Description | |
---|---|---|---|
ID | 4 byte | four ASCII character identifier 'JUNK' | |
Size | 4 byte | size of Data | |
Data | Size bytes | nothing | |
unused | 1 byte | present if Size is odd |
The 'INFO' List
RIFF files may include a 'LIST' chunk with a HeaderID of 'INFO'. All chunks listed in this 'directory' should be pure ASCII chunks, and give various information on the file.Name | Description | |
---|---|---|
IART | artist | |
ICOP | copyright | |
INAM | name |
Knowing these structures, one can implement a program that produces a hierarchical list of the file's contents. RIFFview!does this. A simple RIFF could look like this:
That's all for generic RIFFs. All other chunks are part of a special file type. For an interpretation these look at the page with their corresponding file type.
RIFF | first chunk, the 'root directory' | |||
data | some data | |||
JUNK | some padding to align the next chunk | |||
LIST | a list of chunks 'subdirectory' | |||
data | a 'file' in the list | |||
data | another 'file' | |||
data | another 'file' in the 'root directory' |
Portability
RIFFs were designed with mainly one target platform in mind: MS-Windows. The existence of huge numbers of RIFF files (i.e. WAV Collections) made it necessary to read them on other platforms. The RIFX was included in the RIFF specs to for portability purposes, but many RIFF decoders are not capable of reading those files (DaubNet RIFF Viewer V1.3 now can!) , so it may be wise for RIFF encoders to stick to that byte order, even on systems with Motorola byte order.Trademarks, Patents and Royalties
To my knowledge: none.Note that the format of certain chunks contained in RIFFs may very well be patented.
(please read the disclaimer)
Cross-Checking Software
This section is for programmers, who wish to cross-check their implementation with others. This is an incomplete list of programs, which are available as freeware / shareware / try-before-buy etc.The following software is able to decode RIFFs:
DaubNet RIFF Viewer for Win95: Download (freeware)
The is no generic RIFF encoder. Look at the more specific file types for encoders.