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 |
When bs_header_extra_1 is 0 the defaults are bs_freq_scale
2, bs_alter_scale 1 and bs_noise_bands 2; when
bs_header_extra_2 is 0, bs_limiter_bands 2,
bs_limiter_gains 2, bs_interpol_freq 1 and
bs_smoothing_mode 1. A header whose start, stop, crossover, scale or
noise-band values differ from the last one makes the decoder rebuild its frequency
tables.
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; the first channel then carries the level and the second the balance between them, in steps of two |
| 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. Borders are in time slots of two QMF samples: a frame has 16, and a
trailing border may reach 19, into the next frame. Relative borders count 2, 4, 6 or
8 slots. A FIXFIX frame with one envelope always uses the 1.5 dB
amplitude steps, whatever bs_amp_res says. With more than one envelope
there are two noise floors, split at a border that bs_pointer chooses.
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, then one reserved bit; other values are skipped to the end of the extension |
The number of envelopes comes from num_env_idx: 0, 1, 2 or 4 when
frame_class is 0 (evenly spaced), and 1, 2, 3 or 4 when it is 1 (at the
given border positions). When the last envelope ends before the frame does, the
decoder repeats its values in one more envelope that reaches the end.
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. Its values 0 to 2 select
the first mixing method, a rotation, and 3 to 5 the second; ICC has eight steps,
from fully coherent (1) to opposite phase (−1). 3GPP’s Enhanced aacPlus decoder
(TS 26.401) needs only the baseline form of the tool, which works in 20 bands and
leaves IPD/OPD out.
Decoding
The core AAC decoder runs at half the output rate. Its 1024 samples a frame go
through a 32-band complex QMF analysis bank, in 32 time slots. SBR builds its
frequency tables from the header, copies low bands upwards in up to five patches,
whitens them with second-order inverse filtering chosen by bs_invf_mode,
scales them to the transmitted envelope with a limiter, adds noise from a fixed table
of 512 complex values and sine tones where bs_add_harmonic asks, and
sends all 64 bands through a QMF synthesis bank at the full rate. The QMF prototype
filter has 640 coefficients, symmetric about the middle except for two
(c[384] and c[512]), whose signs are flipped.
Parametric stereo splits the lowest QMF bands further with hybrid filters (to 71 or 91 bands for the 20- and 34-band modes), makes a decorrelated copy of the mono signal with all-pass filters, and mixes the two into left and right with a 2 × 2 matrix per parameter band, interpolated across each envelope.
The site’s file explorer plays HE-AAC and HE-AAC v2 in .aac,
.latm and .loas files and inside WAV files, and in the first
three shows each SBR header, grid, envelope, noise floor and PS field of every frame. The
decoder is explorer/formats/shared/audio/aac.js with
aac-sbr.js. On the streams tested its output matches FFmpeg’s to within
float rounding (129 to 136 dB). SBR in 960-sample frames is not decoded.