The SSND chunk holds the audio. There is at most one, and it is required
unless the file has no sample frames. What the bytes mean depends on the
compression type.
Fields
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 4 | u32 | offset | where the audio starts in soundData; most software writes 0 |
| 4 | 4 | u32 | blockSize | the size of the alignment blocks; 0 means the data need not be block-aligned |
| 8 | … | bytes | soundData | the audio |
A reader should find the audio at offset from the start of
soundData. FFmpeg, for one, adds offset and skips the block
size.
Uncompressed audio
With NONE or twos, sample points are two’s-complement
numbers, most significant byte first. A sample of fewer bits than the bytes it uses is
left-justified, with the spare low bits zero:
sampleSize | Bytes |
|---|---|
| 1 to 8 | 1 |
| 9 to 16 | 2 |
| 17 to 24 | 3 |
| 25 to 32 | 4 |
With sowt, the same samples are stored little-endian: 16-bit values are
byte-swapped, which is why many tools treat it as a form of PCM.
Floats (fl32, fl64) are big-endian IEEE numbers.
alaw and ulaw are single bytes; see
µ-law and A-law.
Channels
Frames are stored in time order and channels are interleaved within each frame, in the same way as in plain AIFF.
Compressed audio
A codec’s data is stored in that codec’s own layout. The common chunk still gives the
audio’s channels, frames and sample rate, with sampleSize the depth before
compression. The specification left the layout of each codec to its definers, and the
AIFF-C chunks do not describe them. What numSampleFrames counts is the unit of the coding:
sample frames for linear PCM, floats and companded sound, but frames of the compressed data for the
Apple codecs (the draft’s example of 107,460 MACE 3:1 frames has 214,920 bytes of sound) and packets for
ima4 (34 bytes a channel, 64 sample frames) and GSM (33 bytes a channel, 160 sample frames). Files made by afconvert and FFmpeg
(IMA4, MACE) store exactly that count.
MACE and Apple IMA4 are described on the compression types page.
Apple IMA4 packets
A 34-byte packet a channel holds 64 samples. Its first two bytes, big-endian, are the top 9 bits of the 16-bit predictor and, in
the low 7 bits, the step index (0 to 88). Then 32 bytes of 4-bit codes, the low nibble of each byte first. A code applies the usual
IMA step: diff = step >> 3, plus step for bit 2, step >> 1 for bit 1,
step >> 2 for bit 0, subtracted when bit 3 is set; the step index moves by −1 −1 −1 −1 2 4 6 8 on the three low
bits. Packets of the channels alternate packet by packet. A packet whose header repeats the running step index and whose predictor
is within 0x7F of the running one keeps the running predictor, as Apple’s decoder does. Apple publishes no layout; this is read from
FFmpeg’s decoder and equals both FFmpeg and afconvert on mono and stereo files.
XA ADPCM in an APCM chunk
Some files (FFmpeg reads them) have an APCM chunk instead of SSND: two u32 fields, then 128-byte sound groups.
In a group, bytes 0–3 repeat bytes 4–7; bytes 4–11 are one parameter byte for each of the eight 28-sample units (high nibble the
filter 0–4, low nibble the range, shift = 12 − range); bytes 16–127 are 28 words of 4 bytes, the unit pair p (0–3) taking byte
16 + p + 4 × j for sample j, the even unit its low nibble and the odd unit its high nibble. Each sample is
nibble << shift plus (s1 × f0 + s2 × f1 + 32) >> 6 with (f0, f1) = (0,0), (60,0), (115,−52), (98,−55),
(122,−60), clamped to 16 bits. Mono plays the eight units in turn (224 samples a group); stereo gives the even units to the left and the
odd to the right (112 samples a channel).
Source: Apple, AIFF-C draft, section 5.0 Sound Data Chunk (pages 10 and 11: offset, blockSize, sample points, left justification) and Appendix A example 2 (page 30: 107,460 MACE frames in an SSND of 214,928 bytes). The IMA4, GSM and XA paragraphs describe other software’s readers (FFmpeg and afconvert, as stated there), not the specification.