The desc chunk is required and comes straight after the file header. Its
size is always 32. Its structure is Apple’s CAFAudioFormat.
Fields
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 8 | f64 | mSampleRate | frames per second; must not be 0 |
| 8 | 4 | FourCC | mFormatID | the format, below; must not be 0 |
| 12 | 4 | u32 | mFormatFlags | format-specific flags, below |
| 16 | 4 | u32 | mBytesPerPacket | bytes in a packet, or 0 if packets vary in size |
| 20 | 4 | u32 | mFramesPerPacket | frames in a packet, or 0 if it varies |
| 24 | 4 | u32 | mChannelsPerFrame | the number of channels; must not be 0 |
| 28 | 4 | u32 | mBitsPerChannel | bits per channel, or 0 for compressed formats |
A format that leaves mBytesPerPacket or mFramesPerPacket at
0 needs a packet table.
Format IDs
| ID | Constant | Audio |
|---|---|---|
lpcm | kAudioFormatLinearPCM | linear PCM, integer or float |
ima4 | kAudioFormatAppleIMA4 | Apple’s IMA 4:1 ADPCM |
aac | kAudioFormatMPEG4AAC | MPEG-4 AAC |
MAC3 | kAudioFormatMACE3 | MACE 3:1 |
MAC6 | kAudioFormatMACE6 | MACE 6:1 |
ulaw | kAudioFormatULaw | µ-law |
alaw | kAudioFormatALaw | A-law |
.mp1 | kAudioFormatMPEGLayer1 | MPEG Layer I |
.mp2 | kAudioFormatMPEGLayer2 | MPEG Layer II |
.mp3 | kAudioFormatMPEGLayer3 | MPEG Layer III |
alac | kAudioFormatAppleLossless | Apple Lossless |
These are the IDs the specification defines. The format is not limited to them: a CAF
file can hold any format Core Audio supports, and mFormatID then carries
that format’s four-character code.
Format flags
For lpcm:
| Bit | Constant | Set | Clear |
|---|---|---|---|
| 0 | kCAFLinearPCMFormatFlagIsFloat | floating point | signed integer |
| 1 | kCAFLinearPCMFormatFlagIsLittleEndian | little-endian | big-endian |
For aac , mFormatFlags is the MPEG-4 Audio Object Type, and
kMP4Audio_AAC_LC_ObjectType is 2. Formats with no flags set it to 0.
Linear PCM examples
| Audio | Flags | Bytes/packet | Frames/packet | Bits |
|---|---|---|---|---|
| 16-bit big-endian stereo, 44,100 Hz | 0 | 4 | 1 | 16 |
| 24-bit little-endian stereo, packed, 48,000 Hz | 2 | 6 | 1 | 24 |
| 24-bit little-endian stereo in 4 bytes, 48,000 Hz | 2 | 8 | 1 | 24 |
| 64-bit float little-endian, 4 channels, 96,000 Hz | 3 | 32 | 1 | 64 |
Packed and unpacked 24-bit storage must both be supported. A depth that does not fill
a byte, such as 12 bits, is stored high-aligned in its byte-sized container, and
mBitsPerChannel gives the real width.
A compressed example: IMA 4:1 stereo has 64 frames per packet and 68 bytes per packet (2 × 34).