A SoundFont 2 file is built from RIFF chunks. RIFF is a tagged structure: every piece of data has a standard header, so a reader that does not know a chunk can skip it (spec 3.1). Everything is little-endian.
The chunk
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | ckID | The chunk ID (a FOURCC): four ASCII characters |
| 4 | 4 | ckSize | The size of the data in bytes, excluding any pad byte (DWORD) |
| 8 | ckSize | ckDATA | The data, plus a pad byte if needed to align the next chunk to a word |
The chunks RIFF and LIST hold other chunks (sub-chunks) as their data (spec 3.1). A LIST’s data starts with a four-character list type.
The four levels of the structure
The specification writes the structure in four levels (spec 4.1 to 4.4):
| Level | Chunk | Holds |
|---|---|---|
| 0 | RIFF form sfbk | Three LIST chunks, in this order: INFO, sdta, pdta |
| 1 | LIST INFO | ifil, isng, INAM (required) and irom, iver, ICRD, IENG, IPRD, ICOP, ICMT, ISFT (optional) |
| 1 | LIST sdta | smpl (optional: the upper 16 bits of the samples) and sm24 (optional: the lower 8 bits) |
| 1 | LIST pdta | The nine sub-chunks phdr, pbag, pmod, pgen, inst, ibag, imod, igen, shdr, in this order |
| 2 | the sub-chunks | ifil and iver hold a version tag; isng, INAM, irom, ICRD, IENG, IPRD, ICOP, ICMT, ISFT hold zero-terminated strings; smpl holds SHORT samples; the nine tables hold arrays of records |
| 3 | the records | See the pages for each table |
The order of the three lists and the order of the sub-chunks of pdta are fixed. The order of the sub-chunks inside INFO is arbitrary, but the order of the specification is recommended (spec 3.1 and 3.2). A reader ignores unknown INFO sub-chunks, but a file that contains one no longer conforms until the sub-chunk is defined (spec 3.2).
Data types
| Type | Size | Meaning |
|---|---|---|
BYTE | 1 | Unsigned, 0 to 255 |
CHAR | 1 | Signed, −128 to +127 |
WORD | 2 | Unsigned, 0 to 65,535 |
SHORT | 2 | Signed, −32,768 to +32,767 |
DWORD | 4 | Unsigned, 0 to 4,294,967,295 |
FOURCC | 4 | A DWORD that holds four characters |
ZSTR | varies | A zero-terminated ASCII string |
SFModulator, SFGenerator, SFTransform | 2 | Enumerations, each two bytes long; see generators and modulators |
SFSampleLink | 2 | The sample type: 1 monoSample, 2 rightSample, 4 leftSample, 8 linkedSample, and the same with bit 15 set for a sample in ROM (0x8001, 0x8002, 0x8004, 0x8008); see sample headers |
genAmountType | 2 | A union of ranges (BYTE byLo, BYTE byHi), SHORT shAmount and WORD wAmount; see generator lists |
These are the definitions of the specification’s glossary and sections 4.4 and 4.5 (spec 2.1, 4.5).
Sizes and damage
The RIFF structure repeats the length of the file and of each chunk, so a reader can find out whether the file lost data. If it did, the file is “structurally unsound” and in general should be rejected; utilities may recover data from such files (spec 3.3). The rules of error handling say which errors reject the file and which only ignore a part of it.
The explorer shows a RIFF size that is larger than the file as a cut-short file and reads what is there, shows bytes after the RIFF chunk as extra bytes, reports an odd-sized chunk whose pad byte is missing, reports a LIST type other than INFO, sdta and pdta, and a chunk outside INFO, sdta or pdta that the specification does not define, and reports lists that are missing, repeated or out of order.
Source: SoundFont Technical Specification 2.04, sections 2.1 (data structure terms), 3 (RIFF structure), 4.1 to 4.5 (levels 0 to 3 and the type definitions) and 10.2 (unknown chunks).