首页 > 技术文章 > AAC 码流信息分析

fellow1988 2017-09-21 23:34 原文

AAC在对PCM数据进行编码时,使用window取出1024或128个数据进行MDCT转换到频域。

Window的相关信息记录在ics_info中:

关于ics_info中各个字段的含义如下

 window sequence的类别如Table 44,long_sequence/start_sequence/stop_sequence包含1个window,short_sequence包含8个short window。

在一个window中包含的scalefactor band 依赖于fs.

对于48k来说long_window/long_start_window/long_stop_window中包含49个scalfactor band.window中的 频谱系数个数为1024.

而short window中包含14个scalefactor band,short window中的频谱系数个数为128.

Table 45为long_window的scalefactor band信息。

Scalefactor:Factor by which a set of values is scaled before quantization.
Scalefactor band:A set of spectral coefficients which are scaled by one scalefactor.

The basic method to adjust the quantization noise in the frequency domain is the noise shaping using scalefactors. For this purpose the spectrum is divided in several groups of spectral coefficients called scalefactor bands which share one scalefactor (see subclause 8.3.4). A scalefactor represents a gain value which is used to change the amplitude of all spectral coefficients in that scalefactor band. This mechanism is used to change the allocation of the quantization noise in the spectral domain generated by the non uniform
quantizer.

The width of the scalefactor bands is built in imitation of the critical bands of the human auditory system. For that reason the number of scalefactor bands in a spectrum and their width depend on the transform length and the sampling frequency.

The spectral coefficients are divided into scalefactor bands that contain a multiple of 4 quantized spectral coefficients. Each scalefactor band has a scalefactor.

 num_swb_long_window:long window中scalefactor band的个数。

swb:window中scalefactor band的index.

swb_offset_long_window:long window中,scalefactor band中最小频谱系数的index。比如第0个scalefactor band包含4个频谱系数,最小频谱系数的index为0,那第一个scalefactor band的最小频谱系数的index为4.

window信息相关的字段含义如下:

对于long_sequence而言,window group为1,window group中只包含一个window.

对于short_sequence而言,可能包含多个window group,但所有window group中包含的window总数为8,window group信息和每个window group包含的window个数信息由scale factor_grouping算出。

 下面是short window grouping的example.

包含4个window group, group划分由grouping_bits决定,当bit为1时,当前window在同一个window group中,window_group_length 加1,如果bit为0,当前window是在一个新的window group中,num_window_groups 加1,window_group_length等于1.

 

 

 为进一步提高压缩率,AAC将一个window group中的所有的scalefactor band划分为几个section,每个section使用同一个huffman codebook.

Note that the length of a section is given in scalefactor bands rather than scalefactor window bands

section的划分使得原本码流的层次结构[g][win][sfb][coeff]变成[g][sect][sfb][coeff]

section划分信息包含在section_data()中:

sect_cb[g][i]: group g的第i个huffman table.

sect_len:section中包含的scalefactor个数。

sect_len_incr:用于计算sect_len的字段,short window为3 bit, long_window为5bit。当sect_len_incr==sect_esc_val时,sect_len加sect_esc_val.

sect_start/sect_end:表示当前section的起始和结束的scalfactor的index。sect_start和sect_end之间的scalefactor使用同一个huffman table.

num_sec[g]:group中section的个数。

scalefactor是在频域调节量化后带来的noise最基本的方法。为了这个目的,频谱被分为几个scalefactor band,每一个scalefactor band使用一个scalefactor.

scalefactor 是scalefactor band中频谱系数的gain value。

scalefactor的信息在scale_factor_data()中获取。

hcod_sf为scalefactor的codeword.

dpcm_sf为差分后的scalefactor.

 

scalefactor是采用差分方式进行编码的,即第一个scalefactor减去global_gain后编码,其后的scalefactor减去前一个scalefactor后编码。

scalefactor解码过程如下:

在码流信息中获取到scalfactor的codeword后,查找huffman codebook,获取到codeword的index,差分后的scalefactor为index-index_offset. index_offset固定为-60.

 

频谱系数信息包含在spectral_data()中:

hcod为编码4/2元组频谱系数的codeword。

在码流中读出频谱系数的codeword后,查huffman codebook,获取到codeword对应的index, 通过index可以计算出量化后的频谱系数(w,x,y,z),最大的量化频谱系数为8192

huffman解码出来的量化的频谱系数,需要进行反量化:

反量化的过程如下:

反量化的频谱系数为通过scalefactor进行scale后的频谱系数,在解码时,需要rescale还原真正的频谱系数x_rescale。

gain和scalefactor之间的关系为:

 

推荐阅读