Audio is stored in one data chunk, as the
audio description says. A format
whose packets vary also needs a packet table.
Audio data chunk
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 4 | u32 | mEditCount | 0 at first; increased every time the audio is modified |
| 4 | … | bytes | mData | the audio, in the format from desc |
A chunk size of −1 means the size is not known, as when recording. The chunk must then be the last in the file, so its data runs to the end of the file. Apple recommends setting the true size as soon as it is known, and setting it when opening such a file to read.
Other chunks can name an edit count (peak, ovvw), and a
mismatch means they no longer describe the audio. The packet table must always match
the audio.
Audio is stored frame by frame, one sample per channel, with samples in the byte order set by the format flags.
Packet table chunk
Required when mBytesPerPacket or mFramesPerPacket is 0, and
there must be exactly one. It is otherwise optional, for priming, remainder or
valid-frame information. Its data begins with this header.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 8 | s64 | mNumberPackets | the number of packets |
| 8 | 8 | s64 | mNumberValidFrames | the number of frames that actually play |
| 16 | 4 | s32 | mPrimingFrames | frames at the start that are encoder delay |
| 20 | 4 | s32 | mRemainderFrames | frames at the end that are padding |
| 24 | … | varints | table | an entry per packet, below |
What each entry holds depends on which of the two desc fields are 0:
mBytesPerPacket | mFramesPerPacket | Entry | Example |
|---|---|---|---|
| 0 | not 0 | the packet’s size in bytes | |
| not 0 | 0 | the packet’s frame count | |
| 0 | 0 | a pair: size in bytes, then frame count | Ogg Vorbis |
Variable-length integers
Each byte holds 7 bits of the number. The high bit is set when another byte follows. The most significant group of 7 bits comes first, as Apple’s examples show.
| Value | Bytes |
|---|---|
| 128 | 81 00 |
| 130 | 81 02 |
| 257 | 82 01 |
| 16,383 | FF 7F |
| 16,384 | 81 80 00 |