A raw data block is the compressed audio itself, the same however it is carried: inside
ADTS frames, after an
ADIF header, in an
M4A sample, or in a
LATM payload. It is a run of
syntactic elements. Each starts with a 3-bit code; the code
7 ends the block, which is then padded to a byte boundary. The fields below
are for the MPEG-2 and MPEG-4 AAC object types; the error-resilient types reorder them, as
ISO/IEC 14496-3 sets out.
Element codes
| Code | Name | What it holds |
|---|---|---|
| 0 | ID_SCE | single channel element: one channel |
| 1 | ID_CPE | channel pair element: two channels, possibly sharing settings |
| 2 | ID_CCE | coupling channel element: a channel shared across others |
| 3 | ID_LFE | low-frequency effects element: laid out like an SCE |
| 4 | ID_DSE | data stream element: ancillary bytes |
| 5 | ID_PCE | program config element: the channel layout |
| 6 | ID_FIL | fill element: padding and extension payloads |
| 7 | ID_END | end of the raw data block |
Which elements a block holds follows the channel configuration. For stereo, usually a CPE; for 5.1, an SCE, a CPE, a CPE and an LFE.
Single channel and LFE elements
| Width in bits | Name | Meaning |
|---|---|---|
| 4 | element_instance_tag | identifies this element |
| varies | individual_channel_stream | the channel’s data |
Channel pair element
| Width in bits | Name | Meaning |
|---|---|---|
| 4 | element_instance_tag | identifies this element |
| 1 | common_window | 1 means both channels share one ICS info |
| varies | ics_info | only if common_window is 1 |
| 2 | ms_mask_present | only if common_window is 1: 0 no mid/side, 1 a mask, 2 all bands, 3 reserved |
| 1 each | ms_used | only if ms_mask_present is 1: one bit for each scalefactor band of each window group |
| varies | individual_channel_stream | the first channel, then the second |
When common_window is 1, an LTP stream’s second channel carries its own
LTP data after the shared ICS info.
Individual channel stream
| Width in bits | Name | Meaning |
|---|---|---|
| 8 | global_gain | the starting value for scalefactors |
| varies | ics_info | unless common_window is 1 |
| varies | section_data | which codebook each band uses |
| varies | scale_factor_data | one Huffman-coded difference per band that needs one |
| 1 | pulse_data_present | |
| varies | pulse_data | only if present; not allowed with eight short windows |
| 1 | tns_data_present | |
| varies | tns_data | only if present |
| 1 | gain_control_data_present | |
| varies | gain_control_data | only if present; SSR only |
| varies | spectral_data | Huffman-coded quantised coefficients |
ICS info
| Width in bits | Name | Meaning |
|---|---|---|
| 1 | ics_reserved_bit | 0 |
| 2 | window_sequence | see below |
| 1 | window_shape | 0 sine, 1 Kaiser-Bessel derived |
| 4 | max_sfb | for eight short windows: scalefactor bands used |
| 7 | scale_factor_grouping | for eight short windows: seven bits; each set bit joins that window to the group before it |
| 6 | max_sfb | otherwise |
| 1 | predictor_data_present | otherwise; then prediction (Main) or LTP (LTP) data |
Window sequences
| Value | Name | Windows |
|---|---|---|
| 0 | ONLY_LONG_SEQUENCE | one window of 1024 (or 960) samples |
| 1 | LONG_START_SEQUENCE | long window that leads into short ones |
| 2 | EIGHT_SHORT_SEQUENCE | eight windows of 128 (or 120) samples |
| 3 | LONG_STOP_SEQUENCE | long window that leads out of short ones |
Section data
For each window group, the bands are divided into runs (sections). Each section uses one codebook.
| Width in bits | Name | Meaning |
|---|---|---|
| 4 | sect_cb | the codebook of this section |
| 5, or 3 for short windows | sect_len_incr | the section length; repeated while all ones (31, or 7 for short windows), the increments being added together |
Codebooks
The table of spectrum and scalefactor Huffman codes is in the standard and is not reproduced here.
| Value | Dimension | Signed | Largest absolute value | Meaning |
|---|---|---|---|---|
| 0 | – | – | 0 | zero codebook: the band is silent |
| 1, 2 | 4 | signed | 1 | quadruples |
| 3, 4 | 4 | unsigned | 2 | quadruples |
| 5, 6 | 2 | signed | 4 | pairs |
| 7, 8 | 2 | unsigned | 7 | pairs |
| 9, 10 | 2 | unsigned | 12 | pairs |
| 11 | 2 | unsigned | 16, with escapes | escape codebook: larger values follow an escape sequence |
| 12 | – | – | – | reserved |
| 13 | – | – | – | noise (PNS): the band is filled with noise |
| 14 | – | – | – | intensity, out of phase |
| 15 | – | – | – | intensity, in phase |
Scalefactor bands vary by sample rate. The band counts per sampling index (0 to 12, as on the ADTS page) are:
| Windows | Bands, indices 0 to 12 |
|---|---|
| 1024 long | 41, 41, 47, 49, 49, 51, 47, 47, 43, 43, 43, 40, 40 |
| 960 long | 40, 40, 46, 49, 49, 49, 46, 46, 42, 42, 42, 40, 40 |
| 128 short | 12, 12, 12, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15 |
| 512 Low Delay | –, –, –, 36, 36, 37, 31, 31, –, –, –, –, – |
| 480 Low Delay | –, –, –, 35, 35, 37, 30, 30, –, –, –, –, – |
The band edges themselves are listed in ISO/IEC 14496-3 for every rate. For 44,100 Hz long windows they are 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 48, 56, 64, 72, 80, 88, 96, 108, 120, 132, 144, 160, 176, 196, 216, 240, 264, 292, 320, 352, 384, 416, 448, 480, 512, 544, 576, 608, 640, 672, 704, 736, 768, 800, 832, 864, 896, 928, 1024.
Pulse data
| Width in bits | Name | Meaning |
|---|---|---|
| 2 | number_pulse | the pulse count, minus one |
| 6 | pulse_start_sfb | the band of the first pulse |
| 5 | pulse_offset | for each pulse, a position offset from the last |
| 4 | pulse_amp | for each pulse, its amplitude |
TNS data
Temporal noise shaping, one set per window.
| Width in bits | Name | Meaning |
|---|---|---|
| 2, or 1 for short windows | n_filt | the number of filters |
| 1 | coef_res | if any filters: coefficient resolution, 3 or 4 bits |
| 6, or 4 for short windows | length | for each filter, its length in bands |
| 5, or 3 for short windows | order | for each filter, its order; the highest allowed is 20 in AAC Main, 12 otherwise, and 7 for short windows |
| 1 | direction | if the order is above 0: 0 upward, 1 downward |
| 1 | coef_compress | if the order is above 0: 1 drops the coefficient’s top bit |
| 2 to 4 | coef | the filter’s coefficients, each coef_res + 3 − coef_compress bits |
Main-profile prediction
| Width in bits | Name | Meaning |
|---|---|---|
| 1 | predictor_reset | 1 if the next field is present |
| 5 | predictor_reset_group_number | the group of predictors to reset, 1 to 30 |
| 1 each | prediction_used | per band, up to the rate’s limit: 33, 33, 38, 40, 40, 40, 41, 41, 37, 37, 37, 34, 34 for indices 0 to 12 |
LTP data
| Width in bits | Name | Meaning |
|---|---|---|
| 1 | ltp_data_present | present in place of predictor data in AAC LTP |
| 11 | ltp_lag | the prediction lag |
| 3 | ltp_coef | the coefficient index |
| 1 each | ltp_used | per band, up to a maximum of 40 bands |
Gain control (SSR)
| Width in bits | Name | Meaning |
|---|---|---|
| 2 | max_band | how many of the three polyphase bands carry data |
| 3 | adjust_num | for each band and window: the number of gain changes |
| 4 | alevcode | for each change: its level |
| 2 to 5 | aloccode | for each change: its position (widths below) |
| window_sequence | Windows | aloccode width in bits |
|---|---|---|
| ONLY_LONG | 1 | 5 |
| LONG_START | 2 | first window 4, second 2 |
| EIGHT_SHORT | 8 | 2 |
| LONG_STOP | 2 | first window 4, second 5 |
Coupling channel element
These fields could not be checked against a public parser and are unconfirmed.
| Width in bits | Name | Meaning |
|---|---|---|
| 4 | element_instance_tag | |
| 1 | ind_sw_cce_flag | independent switching |
| 3 | num_coupled_elements | the number of channels coupled, minus one |
| 1 | cc_target_is_cpe | for each target: 1 a CPE, 0 an SCE |
| 4 | cc_target_tag_select | for each target: its element tag |
| 1, 1 | cc_l, cc_r | for a CPE target, whether each channel is used |
| 1 | cc_domain | 0 applied before TNS, 1 after |
| 1 | gain_element_sign | |
| 2 | gain_element_scale | the gain step |
| varies | individual_channel_stream | the coupled data |
| varies | gain elements | for each coupling after the first: common_gain_element_present and Huffman-coded gains |
Data stream element
| Width in bits | Name | Meaning |
|---|---|---|
| 4 | element_instance_tag | |
| 1 | data_byte_align_flag | 1 aligns to a byte boundary before the data |
| 8 | count | bytes of data |
| 8 | esc_count | only if count is 255: added to it |
| 8 each | data_stream_byte | the ancillary data |
Program config element
| Width in bits | Name | Meaning |
|---|---|---|
| 4 | element_instance_tag | |
| 2 | object_type | the profile, as in ADTS |
| 4 | sampling_frequency_index | as in ADTS |
| 4 | num_front_channel_elements | |
| 4 | num_side_channel_elements | |
| 4 | num_back_channel_elements | |
| 2 | num_lfe_channel_elements | |
| 3 | num_assoc_data_elements | |
| 4 | num_valid_cc_elements | |
| 1 + 4 | mono_mixdown_present, mono_mixdown_element_number | the element to use for mono mixdown |
| 1 + 4 | stereo_mixdown_present, stereo_mixdown_element_number | the element to use for stereo mixdown |
| 1 + 2 + 1 | matrix_mixdown_idx_present, matrix_mixdown_idx, pseudo_surround_enable | the matrix mixdown settings |
| 1 + 4 each | front_element_is_cpe, front_element_tag_select | for each front element; side and back elements follow the same way |
| 4 each | lfe_element_tag_select | for each LFE element |
| 4 each | assoc_data_element_tag_select | for each data element |
| 1 + 4 each | cc_element_is_ind_sw, valid_cc_element_tag_select | for each coupling element |
| varies | byte alignment | padding to the next byte |
| 8 | comment_field_bytes | the comment length |
| 8 each | comment_field_data | the comment bytes |
Newer decoders read height information from the comment area when it starts with
the byte AC: a byte, then two bits per front, side and back element.
Fill element
| Width in bits | Name | Meaning |
|---|---|---|
| 4 | count | the bytes of extension data |
| 8 | esc_count | only if count is 15: the count becomes 15 + esc_count − 1 |
| varies | extension_payload | the payloads, filling the count, each beginning with a 4-bit type |
| Type | Name | Payload |
|---|---|---|
| 0 | EXT_FILL | padding |
| 1 | EXT_FILL_DATA | a 4-bit nibble of zero, then bytes of 10100101 |
| 2 | EXT_DATA_ELEMENT | a 4-bit version, then for version 0 (ANC_DATA) a length made of 8-bit parts (255 means another follows) and the bytes |
| 11 | EXT_DYNAMIC_RANGE | dynamic range control |
| 12 | EXT_SAC_DATA | spatial audio (MPEG Surround) data |
| 13 | EXT_SBR_DATA | SBR data |
| 14 | EXT_SBR_DATA_CRC | SBR data with a 10-bit check |
Dynamic range control
| Width in bits | Name | Meaning |
|---|---|---|
| 1 | pce_tag_present | |
| 4 + 4 | pce_instance_tag, drc_tag_reserved_bits | only if present |
| 1 | excluded_chns_present | |
| 7 + 1 | exclude_mask, additional_excluded_chns | only if present: seven channel flags, with a further group while the extra bit is 1 |
| 1 | drc_bands_present | |
| 4 + 4 | drc_band_incr, drc_interpolation_scheme | only if present |
| 8 each | drc_band_top | for each of drc_band_incr + 1 bands |
| 1 | prog_ref_level_present | |
| 7 + 1 | prog_ref_level, reserved bit | only if present; the programme’s reference level in steps of 0.25 dB |
| 1 + 7 each | dyn_rng_sgn, dyn_rng_ctl | for each band: sign and gain |