A CAF file is an 8-byte file header followed by chunks. Every field is big-endian, except the audio samples, whose byte order the format flags give. Floats are IEEE 754. The C-like structures in Apple’s specification are notation only: CAF data is not padded.
File header
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 4 | FourCC | mFileType | caff |
| 4 | 2 | u16 | mFileVersion | 1 for this specification |
| 6 | 2 | u16 | mFileFlags | 0 for version 1 |
Chunk header
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 4 | FourCC | mChunkType | the chunk type, below |
| 4 | 8 | s64 | mChunkSize | the size of the data section in bytes, without this header |
Types made only of lower-case letters, spaces and full stops are reserved by Apple. An
application’s own type must contain a character outside a–z,
space and full stop.
Chunk types
| Type | Chunk | Required | Page |
|---|---|---|---|
desc | audio description | always, straight after the file header | Audio description |
data | audio data | always, exactly one | Audio data |
pakt | packet table | when packets vary in size or frame count | Packet table |
chan | channel layout | over two channels, when order matters | Channel layout |
kuki | magic cookie | when the format needs one | Other chunks |
strg | strings | no | Other chunks |
mark | markers | no | Markers and regions |
regn | regions | no | Markers and regions |
inst | instrument | no | Other chunks |
midi | MIDI | no | Other chunks |
info | information | no | Other chunks |
edct | edit comments | no | Other chunks |
ovvw | overview | no | Other chunks |
peak | peak | no | Other chunks |
umid | unique material identifier | no, at most one | Other chunks |
uuid | user-defined | no | Other chunks |
free | free space | no | Other chunks |
Chunk types the specification does not define, seen in files on a Mac:
ldsc (the format list that Apple’s CAFFile.h defines, written for HE-AAC),
iXML (named in CAFFile.h: XML metadata) and ID3
(Amadeus Pro’s ID3v2 tag), described under
Other chunks, and
CLST (Amadeus Pro’s marker colours) and ResU (a tempo analysis as zlib-compressed JSON), both
described there too. The type of a chunk of Apple’s own lower-case family
that is not in the table is shown as “reserved by Apple but not defined”.
Order of chunks
- The file header is first and
descfollows it immediately. - The
datachunk may appear anywhere afterdescif its size is known. With a size of −1, it must be the last chunk in the file. - The specification sets no other order, and
paktmay come before or afterdata. strg,mark,regn,infoandedctmay have a size larger than their contents, to leave room to grow. The explorer shows the extra bytes as reserved space, not as a problem.- Only the
datachunk may have a size of −1, and then it ends the file. Another chunk of size −1, a negative size or a size that runs past the end of the file is marked, and the chunk is read as far as the file goes. - CAF has no padding: a chunk of odd size is followed at once by the next chunk. Amadeus Pro adds a zero byte after an odd-sized chunk (as AIFF does); the explorer finds it and labels it.
- The 64-bit sizes are signed: a chunk of 240 bytes or more is possible, and the explorer reads them with exact integers up to 253.
- Version and flags: the explorer accepts any version and any flags, as the specification asks for flags, and marks a version other than 1 and flags other than 0.
Example
The start of a stereo file of 16-bit big-endian PCM at 44,100 Hz:
| Offset | Bytes | Meaning |
|---|---|---|
| 0 | 63 61 66 66 | caff |
| 4 | 00 01 | version 1 |
| 6 | 00 00 | flags 0 |
| 8 | 64 65 73 63 | desc |
| 12 | 00 00 00 00 00 00 00 20 | chunk size 32 |
| 20 | 40 E5 88 80 00 00 00 00 | sample rate 44100.0 |
| 28 | 6C 70 63 6D | format lpcm |
| 32 | 00 00 00 00 | flags 0: integer, big-endian |
| 36 | 00 00 00 04 | 4 bytes per packet |
| 40 | 00 00 00 01 | 1 frame per packet |
| 44 | 00 00 00 02 | 2 channels |
| 48 | 00 00 00 10 | 16 bits per channel |
| 52 | 64 61 74 61 | data |
| 56 | FF FF FF FF FF FF FF FF | size −1: unknown |
| 64 | 00 00 00 00 | edit count 0 |
| 68 | … | samples |
Source: Apple, Core Audio Format Specification 1.0 (2005, 2011), sections CAF File Header and Chunk Headers, and the chunk header tables 2-1, 2-7, 2-8 and 2-13 to 2-20; the 8-byte example is built from the field values of Table 2-2 (checked by test-caf-spec.mjs).