AC3 exponent coding

1.overview

AC-3编码的audio信号中的频率系数由浮点型数据表示,并将其归一化到0~1之间。

transform coefficient由exponent和mantissa组成。

设transform coefficient为a, 0<a<1,则可使a=m*2^(-exp), 其中m为mantissa,0<m<1, exp为exponent(注意不是-exp)。可以理解为将a用二进制小数表示,小数点与小数点后第一个1之间的0的个数便为exponent.

例如transform coefficient为-10db(0.316),二进制表示为0.0101B,那exponent为1,mantissa为101B.

exponent是5 bit,范围为0~24.当exponent大于24时,将exponent固定为24,那么对应的mantissa可以包含leading zero.可表示的频谱系数为0~-144db(以6 db为一个step)。0~-6db exponent 为0,-6db~-12db exponent为1,-12db~-18db exponent为2.....

由于每个frame的audio information都是独立的,并不共享。所以每个frame的block 0都会是一组新的exponents,exponent信息可以在同一个frame中共享,所以block 1~5可能会共用前一个block的exponent。

一个audio block中的diffrential exponent利用exponent strategy组合成group,有3中exponent strategy:D15,D25,D45.

AC-3 audio block包含两种类型的exponent信息,一种是每个channel使用的exponent strategy,一种是需要新exponent的channel的编码exponent。

 2.exponent strategy

exponent采用差分编码方式来提高压缩率,在fbw or lfe ch的第一个exponent用4bit表示,其范围是0~15,如果exponent大于15,也将exponent限制成15.接下来的differential exponent(差分值)表示,其真正的exponent为上一个exponent加上diffrential exponent。

如下图所示,横坐标为frequency bin, 纵坐标为transform coefficient的level(以DBFS为单位)

每一个diffrential exponent被限定为-2,-1,0,+1,+2这5个值,即允许相邻frequecy bin的两个exponent的差最大为+/-12db。

这5个值需要map到无符号数,每个值加2,map成0,1,2,3,4。由于采用diffrential coding,只需要3 bit来coding diffrential value,而不需要5bit来 coding每个 exponent.

mapped value以5进制组合成一个7bit的group value.使用group策略,用7 bit可以表示3个exponent,每个exponent占用7/3=2.33 bits.

exponent strategy包含3种:D15,D25,D45. 5表示group value使用5进制,1/2/4表示 使用同一个mapped value(M1/M2/M3)的diffrential exponets的个数。

coded 7 bit group value = 25 * M1 + 5 * M2 + M3.

以D45为例,group value 为44,第一个exponent为6. M1=1, M2=3, M3=4.

exp1 = exp2 = exp3 = exp4  = 6 + (1 -2) = 5

exp5 = exp6 = exp7 = exp8 = exp4+ (3-2) = 6;

exp9 = exp10 = exp11 = exp12 = exp8 + (4-2) = 8;

使用D25,每个exponent占用7/3/2=1.17 bits.

使用D45,每个exponent占用7/3/4=0.58 bits.

exponent使用D15/D25/D45 是frequecy sharing 方式来增加压缩率,除此之外,还可以使用exponent sharing cross time.许多audio signal在一个frame内(time period)是stationary的,紧邻的几个transform block具有similar spectral contents,即similar exponent value.因此可以只transmit第一个block的exponent,其他5个block reuse第一个block的exponent.如果使用D45,并且time sharing,每个exponent占用0.1bits.

 3. exponent decoding

1)从bitstream中读出exponent strategy.

coupled channel和independent channel的exponent strategy由bitstream的占有2bit的字段chexpstr[ch]来标识,coupling channel由chexpstr标识, lfe ch由lfeexpstr标识。

2)确定exponent的起止频率.

在bitstream中,紧接着exponent strategy后面的是一组chbwcod[ch](channel bandwidth codes),只有在当前audio block中有new exponent的independent channel(channel not coupling) 有chbwcod[ch], channel bandwidth code定义了end mantissa bin(bin表示频率,比如256个频谱系数,对应256个频率bin)的个数。 end mantissa bin表示的是exponent的截止频率.

independent channel & coupped channel

截至频率:endmant[ch] = ((chbwcod[ch] + 12) * 3) + 37; (ch  not coupled)

截至频率:endmant[ch] = cplstrtmant;(ch is coulped)

起始频率:strtmant[ch] = 0

lfe channel: 

起始频率:lfestrtmant = 0

截至频率:lfeendmant = 7

coupling channel:

起始频率:cplstrtmant = (cplbegf * 12) + 37      

截至频率:cplendmant = ((cplendf + 3) * 12) + 37

其中cplbegf,cplendf,cplstrtmant是coupling strategy infomation,在coupling中做介绍。

 3)解码exponent.

coded exponent包含在exps[ch][grp](independent channel & coupped channel),clpexps[grp](coupling channel),lfeexps[grp]等字段中。

exps[ch][0]和lfeexps[0]是第一个频率系数(bin #0)的exponents(The first absolute exponent),是一个4bit的值,被限制为0~15。cplabsexp是coupling channel用来的decoding diffrential exponent的absolute exponent.

计算每个channel内有多少组(不包含第一个absolute exponent)7位的bit group value的算法是

independent channel & coupled channel:

nchgrps[ch] = truncate {(endmant[ch] – 1) / 3} ;    /* for D15 mode */

= truncate {(endmant[ch] – 1 + 3) / 6} ; /* for D25 mode */

= truncate {(endmant[ch] - 1 + 9) / 12} ; /* for D45 mode */

lfe channel:

nlfegrps = 2

coupling channel:

ncplgrps = (cplendmant – cplstrtmant) / 3 ; /* for D15 mode */

= (cplendmant – cplstrtmant) / 6 ; /* for D25 mode */

= (cplendmant – cplstrtmant) / 12 ; /* for D45 mode */

 接下来group value解码出exponent:

a)通过group value转换成Mapped value:

M1 = truncate (gexp / 25)    

M2 = truncate {(gexp % 25} / 5)

M3 = (gexp % 25) % 5

其中gexp为 lfeexps, cplexps, exps

b)Mapped value转换成differentail exponents:

dexp = M - 2;

M为M1,M2,M3

c)absolute exponent 为前一个absolute exponent 加上differential exponent

exp[n] = exp[n-1] + dexp[n]

d)对于D25,D45,相邻的2/4个exp相同。

对于coupling channel

Clpexp[n]+cplstrmant=exp[n].

伪代码如下:

原文地址:https://www.cnblogs.com/fellow1988/p/8724778.html