HE-AAC adds spectral band replication (SBR), which rebuilds high frequencies from low
ones, and HE-AAC v2 adds parametric stereo (PS). A stream states them in its
AudioSpecificConfig
or not at all. The data itself sits in the
fill elements of each raw data block,
as type 13 (EXT_SBR_DATA) or 14 (EXT_SBR_DATA_CRC). A core
decoder that does not know these types skips them and plays the audio at the core
rate.
SBR payload layout
| Width in bits | Name | Meaning |
|---|---|---|
| 10 | bs_sbr_crc_bits | only for type 14: a check on the rest of the payload |
| 1 | bs_header_flag | 1 means an SBR header follows |
| varies | sbr_header | if the flag is set |
| varies | sbr_data | a single-channel or channel-pair element, matching the AAC element it extends |
SBR header
| Width in bits | Name | Meaning |
|---|---|---|
| 1 | bs_amp_res | the amplitude resolution of envelope values |
| 4 | bs_start_freq | the start of the SBR frequency range |
| 4 | bs_stop_freq | the end of the SBR frequency range |
| 3 | bs_xover_band | the crossover band |
| 2 | bs_reserved | |
| 1 | bs_header_extra_1 | 1 if the next three fields follow |
| 1 | bs_header_extra_2 | 1 if the final four fields follow |
| 2 | bs_freq_scale | frequency band spacing |
| 1 | bs_alter_scale | an alternative scale |
| 2 | bs_noise_bands | noise floor bands |
| 2 | bs_limiter_bands | limiter bands |
| 2 | bs_limiter_gains | limiter gain |
| 1 | bs_interpol_freq | interpolation of frequency |
| 1 | bs_smoothing_mode | smoothing of the envelope |
SBR single channel element
| Width in bits | Name | Meaning |
|---|---|---|
| 1 | bs_data_extra | |
| 4 | bs_reserved | only if bs_data_extra is 1 |
| varies | grid, then delta flags, then invf, then envelope, then noise | |
| 1 + bands | bs_add_harmonic_flag, then bs_add_harmonic | one bit for each high-resolution band, when set |
| 1 | bs_extended_data | see extension |
SBR channel pair element
| Width in bits | Name | Meaning |
|---|---|---|
| 1 | bs_data_extra | |
| 8 | bs_reserved | only if bs_data_extra is 1 |
| 1 | bs_coupling | 1 means one grid and one set of inverse-filtering modes serve both channels |
| varies | one set per channel, or shared under coupling | grids, delta flags, invf, envelopes, noise floors, as for a single channel |
| 1 + bands each | bs_add_harmonic_flag and bs_add_harmonic | for each channel |
| 1 | bs_extended_data | see extension |
Grid
A two-bit bs_frame_class says how the frame is divided into envelopes in
time.
| Value | Name | Fields, in order |
|---|---|---|
| 0 | FIXFIX | bs_num_env (2 bits, read as 1 << n), one bs_freq_res bit for all envelopes |
| 1 | FIXVAR | trailing border (2), bs_num_rel_1 (2), relative borders (2 each), bs_pointer, one bs_freq_res per envelope |
| 2 | VARFIX | leading border (2), bs_num_rel_0 (2), relative borders (2 each), bs_pointer, one bs_freq_res per envelope |
| 3 | VARVAR | leading and trailing border (2 each), both relative counts (2 each), relative borders (2 each), bs_pointer, one bs_freq_res per envelope |
bs_pointer is 1 to 3 bits, depending on the number of envelopes (1, 2, 2, 3,
3 bits for 1 to 5 envelopes). bs_freq_res is 1 for the high-resolution
band table.
Delta, invf, envelope and noise
| Width in bits | Name | Meaning |
|---|---|---|
| 1 each | bs_df_env | per envelope: 0 delta across frequency, 1 delta across time |
| 1 each | bs_df_noise | per noise floor: same |
| 2 each | bs_invf_mode | per noise band: the inverse filtering level |
| 5, 6 or 7 | bs_env_start_value | for a frequency-delta envelope: the first value. 6 bits when bs_amp_res is set, 7 otherwise; in coupled channel 1, 5 and 6 bits |
| varies | bs_data_env | Huffman-coded differences |
| 5 | bs_noise_start_value | for a frequency-delta noise floor |
| varies | bs_data_noise | Huffman-coded differences |
Extension
| Width in bits | Name | Meaning |
|---|---|---|
| 1 | bs_extended_data | 1 means extensions follow |
| 4 | bs_extension_size | their total size in bytes |
| 8 | bs_esc_count | only if the size is 15: added to it |
| 2 | bs_extension_id | each extension’s type; 2 is parametric stereo |
Parametric stereo
| Width in bits | Name | Meaning |
|---|---|---|
| 1 | enable_ps_header | 1 if the next five fields follow |
| 1 | enable_iid | |
| 3 | iid_mode | only if enable_iid is 1: see below |
| 1 | enable_icc | |
| 3 | icc_mode | only if enable_icc is 1: see below |
| 1 | enable_ext | |
| 1 | frame_class | |
| 2 | num_env_idx | index into the envelope-count table |
| 5 each | border_position | only if frame_class is 1 |
| 1, then varies | iid_dt, then Huffman-coded IID values | for each envelope, if IID is enabled |
| 1, then varies | icc_dt, then Huffman-coded ICC values | for each envelope, if ICC is enabled |
| 4 + 8 | ps_extension_size, escape | if enable_ext is 1; the size is in bytes and 15 means 8 more bits follow, added on |
| 2 each | ps_extension_id | 0 means IPD/OPD data follows: enable_ipdopd (1 bit), then per envelope dt and Huffman-coded IPD and OPD values |
iid_mode | IID/ICC bands | IPD/OPD bands | IID steps |
|---|---|---|---|
| 0 | 10 | 5 | coarse |
| 1 | 20 | 11 | coarse |
| 2 | 34 | 17 | coarse |
| 3 | 10 | 5 | fine |
| 4 | 20 | 11 | fine |
| 5 | 34 | 17 | fine |
| 6, 7 | reserved | ||
icc_mode uses the same band counts by value; it has no steps of its
own.