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 lists (“not exhaustive”). 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. The tables below
add the codes the Xcode SDK header CoreAudioBaseTypes.h defines and the
codes afconvert -hf on macOS lists as writable to a CAF file.
More format IDs
| ID | SDK constant | Audio | Cookie |
|---|---|---|---|
ac-3 | kAudioFormatAC3 | Dolby Digital (AC-3); 1,536 frames a packet, a packet is one sync frame | none seen |
cac3 | kAudioFormat60958AC3 | AC-3 inside IEC 60958 (S/PDIF) frames | |
ec-3 | kAudioFormatEnhancedAC3 | Dolby Digital Plus (E-AC-3) | |
aach | kAudioFormatMPEG4AAC_HE | HE-AAC (AAC with SBR) | esds |
aacp | kAudioFormatMPEG4AAC_HE_V2 | HE-AAC v2 (SBR and parametric stereo) | esds |
aacl | kAudioFormatMPEG4AAC_LD | AAC-LD, low delay | esds |
aace | kAudioFormatMPEG4AAC_ELD | AAC-ELD, enhanced low delay | esds |
aacf | kAudioFormatMPEG4AAC_ELD_SBR | AAC-ELD with SBR | esds |
aacg | kAudioFormatMPEG4AAC_ELD_V2 | AAC-ELD v2 | esds |
aacs | kAudioFormatMPEG4AAC_Spatial | MPEG-4 Spatial Audio | |
usac | kAudioFormatMPEGD_USAC | MPEG-D USAC (xHE-AAC) | |
celp, hvxc, twvq | kAudioFormatMPEG4CELP … | MPEG-4 CELP, HVXC and TwinVQ | |
QDMC, QDM2 | kAudioFormatQDesign, …QDesign2 | QDesign Music 1 and 2 | |
Qclp | kAudioFormatQUALCOMM | QUALCOMM PureVoice | |
samr, sawb | kAudioFormatAMR, …AMR_WB | AMR narrowband and wideband | |
ilbc | kAudioFormatiLBC | iLBC (RFC 3951), 20 ms frames of 38 bytes or 30 ms frames of 50 bytes at 8,000 Hz | 8 bytes |
ms 00 11 | kAudioFormatDVIIntelIMA = 0x6D730011 | DVI/Intel IMA ADPCM, ACM code 17 (the same as WAVE format 0x11): each packet is a block of mBytesPerPacket bytes holding mFramesPerPacket frames | |
ms 00 31 | kAudioFormatMicrosoftGSM = 0x6D730031 | Microsoft GSM 6.10, ACM code 49 (the same as WAVE format 0x31): a 65-byte block of 320 frames | |
ms 00 02 | (not in the headers) | Microsoft ADPCM, afconvert lists it for CAF | |
ms 00 55 | (not in the headers) | MPEG Layer III, WAVE format 0x55: a packet is one MPEG audio frame (1,152 frames). FFmpeg’s CAF table (libavformat/caf.c) names it; Apple’s afconvert refuses it | |
agsm | (not in the headers) | GSM 06.10: FFmpeg’s CAF table maps it to its GSM decoder, whose frame is the classic 33 bytes (the signature nibble 0xD, then the 76 parameters) of 160 frames. Apple’s afconvert refuses it | |
flac | kAudioFormatFLAC | FLAC; each packet is one FLAC frame, mFramesPerPacket is the block size (4,608 seen) | a dfLa box |
opus | kAudioFormatOpus | Opus; each packet is one Opus packet, mFramesPerPacket 960 at 48,000 Hz (480 at 24,000 Hz); more than two channels need a chan chunk and an OpusHead cookie | an OpusHead (RFC 7845), or 28 bytes in Apple’s own layout (see Other chunks) |
apac | kAudioFormatAPAC | Apple Positional Audio Codec (spatial audio) | a dapa box |
AUDB | kAudioFormatAudible | Audible audiobook audio (AudioToolbox names it “Audible” and maps it to a WAVE format tag; its decoder in AudioCodecs is the protected AAX one) | |
aes3 | kAudioFormatAES3 | audio as AES3-2003 defines it, adopted into MXF, MPEG-2 and SDTI by SMPTE 302M-2002 and 331M-2000; no flags. AudioToolbox names it “Apple AES3 Audio”; no code in AudioToolbox or AudioCodecs reads or writes it (checked by disassembly), so no packet layout is known | |
time | kAudioFormatTimeCode | a stream of IOAudioTimeStamp structures (IOKit/audio/IOAudioTypes.h), with those structures’ flags | |
midi | kAudioFormatMIDIStream | a stream of MIDIPacketLists whose time stamps are sample offsets in the stream; mSampleRate says how time passes in it; no flags | |
apvs | kAudioFormatParameterValueStream | a “side-chain” of Float32 values an audio unit can read or write to carry dense parameter control data, at the audio’s sample rate or an integer divisor of it (the sample rate says which); no flags | |
dvi8, vorb | (not in the headers) | listed by afconvert for CAF. vorb is Vorbis: each packet is one Vorbis packet (mFramesPerPacket 0, a pair of sizes in the packet table), the cookie holds the three Vorbis headers (see Other chunks). dvi8 is named “DVI8” by AudioToolbox; no code in AudioToolbox or AudioCodecs reads or writes it (checked by disassembly), so no layout is known | for vorb: the three headers |
paac, pac3, pach, pacp, pec3, pusa, qaac, qac3, qach, qacp, qapc, qec3, qflc, qlac, qusa, zaac, zac3, zach, zacp, zec3, zlac | (not in the headers) | listed by afconvert for CAF; each is the encrypted form of an AAC, HE-AAC, HE-AAC v2, AC-3, E-AC-3, USAC (xHE-AAC), APAC, FLAC or Apple Lossless code. AudioToolbox’s kAudioFormatProperty_FormatIsEncrypted (AudioFormat.h) answers yes for all 21, and its format translator (disassembled) builds them from the plain code and an encryption flavour: the flavour penc gives the p codes (paac, pach, pacp, pac3, pec3, pusa), cbcs the q codes (those and qapc, qflc, qlac) and zenc the z codes (zaac, zach, zacp, zac3, zec3, zlac). The audio cannot be decoded without the keys | not examined (the content is encrypted) |
The explorer names every code in the tables and decodes these: linear PCM, µ-law, A-law,
AAC, HE-AAC, HE-AAC v2, AAC-LD and AAC-ELD (without low-delay SBR), USAC (its frequency-domain core),
Apple Lossless, FLAC, Opus, IMA4, IMA ADPCM and
Microsoft ADPCM in WAVE blocks, GSM 06.10 (in WAVE blocks and as agsm), AC-3 (also as cac3),
E-AC-3, MPEG Layers I to III (also as ms 00 55), iLBC (the shared
RFC 3951 decoder with its enhancer), QCELP (FFmpeg’s qcelpdec.c), QDesign 1 (FFmpeg’s qdmc.c), QDesign 2
(FFmpeg’s qdm2.c) and MACE 3:1 and 6:1 (the shared decoder written from FFmpeg’s mace.c). The other
codes are labelled as not decoded. Several of them (MPEG-4 CELP, HVXC and TwinVQ, MPEG Surround, and
the parts of USAC and AAC-ELD that are missing) do have public source code or specifications, and
are listed under “Known, not yet covered” on the overview;
only the codes with no public description there are unknown.
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 (1 Main, 3 SSR, 4 LTP, 5 SBR, 17 ER LC,
23 ER LD, 29 PS, 39 ER ELD, 42 USAC). Apple’s own encoders write 0 and leave the object
type to the magic cookie; all 1,341 AAC files on this Mac have flags 0. Formats with
no flags set it to 0.
Two formats put the bit depth of their source in the flags, the way Apple’s
kAppleLosslessFormatFlag_* constants do: for alac and
flac, 1 is 16-bit, 2 is 20-bit, 3 is 24-bit and 4 is 32-bit source data.
afconvert writes 1 for a 16-bit source and 3 for a 24-bit one.
Linear PCM has more than the two flags in the table in Apple’s Core Audio headers (packed, aligned high, non-interleaved), but a CAF file carries only the two above: the packet size and bits per channel say whether a sample is packed, and a depth smaller than the container is always high-aligned. The reader flags bits other than 0 and 1 as undefined.
How linear PCM samples sit in a packet
| Bits per channel | Bytes a sample | Layout |
|---|---|---|
| 8 | 1 | signed (CAF has no unsigned 8-bit) |
| 12, 16 | 2 | 12-bit samples are high-aligned in 16 bits (the low 4 bits are zero) |
| 18, 20, 24 | 3, or 4 when mBytesPerPacket is 4 × channels | packed in 3 bytes (LL XX MM little-endian, MM XX LL big-endian), or high-aligned in 4 bytes (00 LL XX MM little-endian, MM XX LL 00 big-endian) |
| 32 | 4 | signed integer, or IEEE float with the float flag |
| 64 | 8 | IEEE float (with the float flag) |
| 1 | 1 for 8 frames | Pulse Width Modulation (SA-CD style): 8 frames in a packet, 1 byte a channel; the explorer labels it, it has no waveform |
The explorer finds the bytes a sample from mBytesPerPacket divided by
mChannelsPerFrame, and plays integer samples of 1 to 8 bytes and float
samples of 4 and 8 bytes, both orders. The numbers of the files on this Mac:
573 are linear PCM: 16-bit little-endian integer (mono and stereo, 8,000 to 96,000
Hz), 24-bit little-endian integer in 3 bytes, and 32-bit little-endian float. None is
big-endian, 20-bit, 12-bit, 64-bit or 8-bit; those were checked on files built with
afconvert and by hand.
What the other fields hold for each compressed format
| Format | mBytesPerPacket | mFramesPerPacket | mBitsPerChannel | Packet table |
|---|---|---|---|---|
ima4 | 34 × channels | 64 | 0 | header only (0 packets); valid and remainder frames |
ulaw, alaw | channels | 1 | 8 | none |
aac and the other AAC codes | 0 | 1024 (2,048 with SBR as the top layer; 512 or 480 for LD and ELD) | 0 | sizes; priming 2,112 frames |
alac | 0 | 4,096 | 0 | sizes |
flac | 0 | 4,608 or the block size | 0 | sizes; priming 0 |
opus | 0 | 960 (48,000 Hz), 480 (24,000 Hz) | 0 | sizes; priming 312 frames at 48,000 Hz |
ilbc | 38 or 50 | 160 or 240 | 0 | CBR packet table |
.mp3, .mp2, .mp1 | 0 | 1,152 (576 for MPEG-2 Layer III, 384 for Layer I) | 0 | sizes |
ac-3 | 0 | 1,536 | 0 | sizes |
Priming and sizes in this table are what afconvert and the files on
this Mac show; none is a rule of the specification.
HE-AAC and the layered description
For HE-AAC, afconvert describes the base layer in desc (the
AAC core at half the output rate: 22,050 Hz, 1,024 frames a packet), and adds an
ldsc chunk that describes the
output layer (44,100 Hz, aach, 2,048 frames a packet). The packet table’s
valid, priming and remainder frames are in the core rate; a decoder that writes
SBR output at twice the rate doubles them, and the SBR synthesis adds 481 core frames
of delay that Apple’s decoder takes out too.
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).
Source: Apple, Core Audio Format Specification 1.0, sections Audio Description Chunk (the CAFAudioFormat structure, the mFormatID list and Tables 2-1 to 2-6) and mFormatFlags Field. Format IDs the specification does not list are marked with where they come from in the table above (the Xcode SDK header CoreAudioBaseTypes.h or the tools named there).