📄 layer3.c
字号:
};
int numbits;
int num0 = slen[0][gr_info->scalefac_compress];
int num1 = slen[1][gr_info->scalefac_compress];
if (gr_info->block_type == 2)
{
int i=18;
numbits = (num0 + num1) * 18;
if (gr_info->mixed_block_flag) {
// for (i=8;i;i--)
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
i = 9;
numbits -= num0; /* num0 * 17 + num1 * 18 */
}
for (;i;i--)
*scf++ = getbits_fast(num0);
// for (i = 18; i; i--)
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = 0; *scf++ = 0; *scf++ = 0; /* short[13][0..2] = 0 */
}
else
{
int i;
int scfsi = gr_info->scfsi;
if(scfsi < 0) { /* scfsi < 0 => granule == 0 */
// for(i=11;i;i--)
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
// for(i=10;i;i--)
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
numbits = (num0 + num1) * 10 + num0;
}
else {
numbits = 0;
if(!(scfsi & 0x8)) {
// for (i=6;i;i--)
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
numbits += num0 * 6;
}
else {
*scf++ = 0; *scf++ = 0; *scf++ = 0; /* set to ZERO necessary? */
*scf++ = 0; *scf++ = 0; *scf++ = 0;
}
if(!(scfsi & 0x4)) {
// for (i=5;i;i--)
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(num0);
numbits += num0 * 5;
}
else {
*scf++ = 0; *scf++ = 0; *scf++ = 0; /* set to ZERO necessary? */
*scf++ = 0; *scf++ = 0;
}
if(!(scfsi & 0x2)) {
// for(i=5;i;i--)
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
numbits += num1 * 5;
}
else {
*scf++ = 0; *scf++ = 0; *scf++ = 0; /* set to ZERO necessary? */
*scf++ = 0; *scf++ = 0;
}
if(!(scfsi & 0x1)) {
// for (i=5;i;i--)
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(num1);
numbits += num1 * 5;
}
else {
*scf++ = 0; *scf++ = 0; *scf++ = 0; /* set to ZERO necessary? */
*scf++ = 0; *scf++ = 0;
}
}
*scf++ = 0; /* no l[21] in original sources */
}
return numbits;
}
#endif
#if (defined MPEG2||defined MPEG25)
static int III_get_scale_factors_2(int *scf,struct gr_info_s *gr_info,int i_stereo)
{
unsigned char *pnt;
int i,j;
unsigned int slen;
int n = 0;
int numbits = 0;
static unsigned char stab[3][6][4] = {
{ { 6, 5, 5,5 } , { 6, 5, 7,3 } , { 11,10,0,0} ,
{ 7, 7, 7,0 } , { 6, 6, 6,3 } , { 8, 8,5,0} } ,
{ { 9, 9, 9,9 } , { 9, 9,12,6 } , { 18,18,0,0} ,
{12,12,12,0 } , {12, 9, 9,6 } , { 15,12,9,0} } ,
{ { 6, 9, 9,9 } , { 6, 9,12,6 } , { 15,18,0,0} ,
{ 6,15,12,0 } , { 6,12, 9,6 } , { 6,18,9,0} } };
if(i_stereo) /* i_stereo AND second channel -> do_layer3() checks this */
slen = i_slen2[gr_info->scalefac_compress>>1];
else
slen = n_slen2[gr_info->scalefac_compress];
gr_info->preflag = (slen>>15) & 0x1;
n = 0;
if( gr_info->block_type == 2 ) {
n++;
if(gr_info->mixed_block_flag)
n++;
}
pnt = stab[n][(slen>>12)&0x7];
for(i=0;i<4;i++) {
int num = slen & 0x7;
slen >>= 3;
if(num) {
for(j=0;j<(int)(pnt[i]);j++)
*scf++ = getbits_fast(num);
numbits += pnt[i] * num;
}
else {
for(j=0;j<(int)(pnt[i]);j++)
*scf++ = 0;
}
}
n = (n << 1) + 1;
for(i=0;i<n;i++)
*scf++ = 0;
return numbits;
}
#endif
// x: 21bit xr, v: gainpow2index(24bit), return 24bit
/*real deq_pow(int x, int v)
{
int p, r, l;
real pow43;
real deq;
if (x < 130) {
pow43 = ispow[x]; // 21bit
l = 0;
}else if (x < 1025) {
p = x >> 3;
r = x & 7;
pow43 = (ispow[p]>>3) * (8-r) + (ispow[p+1]>>3) * r; // 21bit
l = 4;
} else {
p = x >> 6;
r = x & 63;
pow43 = (ispow[p]>>6) * (64-r) + (ispow[p+1]>>6) * r; // 21bit
l = 8;
}
p = -v;
r = p & 3;
p = p >> 2;
deq = (pow43>>13) * (gainpow2[r]>>10); // 21-9 + 24-14 = 22
deq = deq >> (-2-l-p); // left shift l + p and shift (24-22)
return deq;
}
*/
extern int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
struct gr_info_s *gr_info,int sfreq,int part2bits);
#if 0
#define deq_pow(x,v) \
{ \
int p, r, l; \
if ((x)<130 ) { deq = ispow[(x)]; l = 0; } \
else if ((x)<1025) { p = (x)>>3; r = (x)&7 ; deq = (ispow[p]>>3)*(8 -r)+(ispow[p+1]>>3)*r; l = 4; } \
else { p = (x)>>6; r = (x)&63; deq = (ispow[p]>>6)*(64-r)+(ispow[p+1]>>6)*r; l = 8; } \
p = -(v); r = p&3; p = p>>2; \
deq = (deq>>13)*(gainpow2[r]>>10); deq = deq>>(-2-l-p); \
}
static int pretab1[22] = {0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,3,3,3,2,0};
static int pretab2[22] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
struct gr_info_s *gr_info,int sfreq,int part2bits)
{
int shift = 1 + gr_info->scalefac_scale;
real *xrpnt = (real *) xr;
int l[3],l3,*count;
int part2remain = gr_info->part2_3_length - part2bits;
int *me;
real deq;
{
int bv = gr_info->big_values;
int region1 = gr_info->region1start;
int region2 = gr_info->region2start;
l3 = ((576>>1)-bv)>>1;
/*
* we may lose the 'odd' bit here !!
* check this later again
*/
if(bv <= region1) {
l[0] = bv; l[1] = 0; l[2] = 0;
}
else {
l[0] = region1;
if(bv <= region2) {
l[1] = bv - l[0]; l[2] = 0;
}
else {
l[1] = region2 - l[0]; l[2] = bv - region2;
}
}
}
if(gr_info->block_type == 2) {
/*
* decoding with short or mixed mode BandIndex table
*/
int i,max[4];
int step=0,lwin=0,cb=0;
register int v = 0;
register int *m,mc;
count = max;
if(gr_info->mixed_block_flag) {
/*max[3] = -1;
max[0] = max[1] = max[2] = 2;*/
*count = 2; count++;
*count = 2; count++;
*count = 2; count++;
*count = -1;
m = map[sfreq][0];
me = mapend[sfreq][0];
}
else {
/*max[0] = max[1] = max[2] = max[3] = -1;*/
*count = -1; count++;
*count = -1; count++;
*count = -1; count++;
*count = -1;
/* max[3] not really needed in this case */
m = map[sfreq][1];
me = mapend[sfreq][1];
}
mc = 0;
for(i=0;i<2;i++) {
int lp = l[i];
struct newhuff *h = ht+gr_info->table_select[i];
for(;lp;lp--,mc--) {
register int x,y;
if( (!mc) ) {
mc = *m++;
xrpnt = ((real *) xr) + (*m++);
lwin = *m++;
cb = *m++;
if(lwin == 3) {
v = gr_info->pow2gain + ((*scf++) << shift);
step = 1;
}
else {
v = gr_info->full_gain[lwin] + ((*scf++) << shift);
step = 3;
}
}
{
register short *val = h->table;
while((y=*val++)<0) {
GET1BIT();
if (rval)
val -= y;
part2remain--;
}
x = y >> 4;
y &= 0xf;
}
if(x == 15) {
max[lwin] = cb;
part2remain -= h->linbits+1;
x += getbits(h->linbits);
deq_pow(x, v); // ispow[x] * v;
GET1BIT();
if(rval)
*xrpnt = -deq;
else
*xrpnt = deq;
}
else if(x) {
max[lwin] = cb;
deq_pow(x, v); // ispow[x] * v;
GET1BIT();
if(rval)
*xrpnt = -deq;
else
*xrpnt = deq;
part2remain--;
}
else
*xrpnt = 0;
xrpnt += step;
if(y == 15) {
max[lwin] = cb;
part2remain -= h->linbits+1;
y += getbits(h->linbits);
deq_pow(y, v); // ispow[y] * v;
GET1BIT();
if(rval)
*xrpnt = -deq;
else
*xrpnt = deq;
}
else if(y) {
max[lwin] = cb;
deq_pow(y, v); // ispow[y] * v;
GET1BIT();
if(rval)
*xrpnt = -deq;
else
*xrpnt = deq;
part2remain--;
}
else
*xrpnt = 0;
xrpnt += step;
}
}
for(;l3 && (part2remain > 0);l3--) {
struct newhuff *h = htc+gr_info->count1table_select;
register short *val = h->table;
register short a;
while((a=*val++)<0) {
part2remain--;
if(part2remain < 0) {
part2remain++;
a = 0;
break;
}
GET1BIT();
if (rval)
val -= a;
}
for(i=0;i<4;i++) {
if(!(i & 1)) {
if(!mc) {
mc = *m++;
xrpnt = ((real *) xr) + (*m++);
lwin = *m++;
cb = *m++;
if(lwin == 3) {
v = gr_info->pow2gain + ((*scf++) << shift);
step = 1;
}
else {
v = gr_info->full_gain[lwin] + ((*scf++) << shift);
step = 3;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -