📄 loop.c
字号:
pTabEntry+=4096-1;
retVal += 4096;
}
if( in2 >= * pTabEntry++ )
{
pTabEntry+=2048-1;
retVal += 2048;
}
if( in2 >= * pTabEntry++ )
{
pTabEntry+=1024-1;
retVal += 1024;
}
if( in2 >= * pTabEntry++ )
{
pTabEntry+=512-1;
retVal += 512;
}
if( in2 >= * pTabEntry++ )
{
pTabEntry+=256-1;
retVal += 256;
}
if( in2 >= * pTabEntry++ )
{
pTabEntry+=128-1;
retVal += 128;
}
}
else
pTabEntry += 6;
if( in2 >= * pTabEntry++ )
{
pTabEntry+=64-1;
retVal += 64;
}
if( in2 >= * pTabEntry++ )
{
pTabEntry+=32-1;
retVal += 32;
}
if( in2 >= * pTabEntry++ )
{
pTabEntry+=16-1;
retVal += 16;
}
if( in2 >= * pTabEntry++ )
{
pTabEntry+=8-1;
retVal += 8;
}
if( in2 >= * pTabEntry++ )
{
pTabEntry+=4-1;
retVal += 4;
}
if( in2 >= * pTabEntry++ )
{
pTabEntry+=2-1;
retVal += 2;
}
if( in2 >= * pTabEntry )
{
retVal += 1;
}
return retVal;
}
/*____ quantize_tj() __________________________________________________________*/
void quantize_tj( double xr[576], int ix[576], gr_info *cod_info )
{
int i, b, l_end, s_start;
double quantizerStepSize;
double mulVal;
float x,y;
D192_3 *xr_s;
I192_3 *ix_s;
xr_s = (D192_3 *) xr;
ix_s = (I192_3 *) ix;
quantizerStepSize = (double) cod_info->quantizerStepSize;
if ( cod_info->quantizerStepSize == 0.0 )
mulVal = 1.0;
else
mulVal = 1.0 / pow ( 2.0, quantizerStepSize * 0.25 );
if ( cod_info->window_switching_flag != 0 && cod_info->block_type == 2 )
if ( cod_info->mixed_block_flag == 0 )
{
l_end = 0;
s_start = 0;
}
else
{
l_end = 18 * 2;
s_start = 6 * 2;
}
else
{
l_end = 576;
s_start = 192;
}
for ( i = 0; i < l_end; i+=2 )
{
/* ix[i] = nint( pow(fabs(xr[i]) * mulVal, 0.75) - 0.0946 ); */
x = fabs(xr[i])*mulVal;
y = fabs(xr[i+1])*mulVal;
ix[i] = bladTabValue( x );
ix[i+1] = bladTabValue( y );
}
for ( ; i < 576; i++ )
ix[i] = 0;
if ( s_start < 192 )
for ( b = 0; b < 3; b++ )
{
mulVal = 1.0 / pow( 2.0, (quantizerStepSize + 8.0 * (double) cod_info->subblock_gain[b]) * 0.25 );
for ( i = s_start; i < 192; i++ )
{
/* (*ix_s)[i][b] = nint( pow(fabs((*xr_s)[i][b]) * mulVal, 0.75) - 0.0946 ); */
(*ix_s)[i][b] = bladTabValue(fabs((*xr_s)[i][b]) * mulVal);
}
}
}
/*************************************************************************/
/* ix_max */
/*************************************************************************/
/*
Function: Calculate the maximum of ix from 0 to 575
*/
int ix_max_tj( int abs_ix[576], unsigned int begin, unsigned int end )
{
uint i;
int max = 0;
for ( i = begin; i < end; i++ )
{
if ( abs_ix[i] > max )
max = abs_ix[i];
}
return max;
}
/*************************************************************************/
/* xr_max */
/*************************************************************************/
/*
Function: Calculate the maximum of xr[576] from 0 to 575
*/
double xr_max( double xr[576] )
{
uint i;
double max = 0.0, temp;
for ( i = 0; i < 576/4; i+=4 )
if( (temp = fabs(xr[i])) > max )
max = temp;
if( (temp = fabs(xr[i+1])) > max )
max = temp;
if( (temp = fabs(xr[i+2])) > max )
max = temp;
if( (temp = fabs(xr[i+3])) > max )
max = temp;
return max;
}
/* Noiseless coding -- Huffman coding */
/*************************************************************************/
/* calc_runlen */
/*************************************************************************/
/*
Function: Calculation of rzero, count1, big_values
(Partitions ix into big values, quadruples and zeros).
*/
void calc_runlen( int ix[576], gr_info *cod_info )
{
int i;
if ( cod_info->window_switching_flag && (cod_info->block_type == 2) )
{ /* short blocks */
cod_info->count1 = 0;
cod_info->big_values = 288;
}
else
{
for ( i = 576; i > 1; i -= 2 )
if ( (ix[i-1] | ix[i-2]) != 0 )
break;
cod_info->count1 = 0 ;
for ( ; i > 3; i -= 4 )
if ( (ix[i-1] | ix[i-2] | ix[i-3] | ix[i-4]) <= 1 )
cod_info->count1++;
else
break;
cod_info->big_values = i/2;
}
}
/*************************************************************************/
/* count1_bitcount */
/*************************************************************************/
/*
Determines the number of bits to encode the quadruples.
*/
int count1_bitcount( int ix[ 576 ], gr_info *cod_info )
{
int abs_and_sign( int *x );
uint k;
int i, p, bitsum_count1;
int v, w, x, y, signbits;
int sum0 = 0, sum1 = 0;
for ( i = cod_info->big_values * 2, k = 0; k < cod_info->count1; i += 4, k++ )
{
v = ix[ i ];
w = ix[ i + 1 ];
x = ix[ i + 2 ];
y = ix[ i + 3 ];
p = v + (w << 1) + (x << 2) + (y << 3);
signbits = v + w + x + y;
sum0 += signbits;
sum1 += signbits;
sum0 += ht[ 32 ].hlen[ p ];
sum1 += ht[ 33 ].hlen[ p ];
}
if ( sum0 < sum1 )
{
bitsum_count1 = sum0;
cod_info->count1table_select = 0;
}
else
{
bitsum_count1 = sum1;
cod_info->count1table_select = 1;
}
return( bitsum_count1 );
}
int optimized_calculations_tj( int * abs_ix, gr_info *cod_info )
{
uint k;
int p, i, bitsum_count1;
int v, w, x, y, signbits;
int sum0 = 0, sum1 = 0;
if ( cod_info->window_switching_flag && (cod_info->block_type == 2) )
{ /* short blocks */
cod_info->count1 = 0;
cod_info->big_values = 288;
}
else
{
for ( i = 576; i > 1; i -= 2 )
if ( (abs_ix[i-1] | abs_ix[i-2]) != 0 )
break;
cod_info->count1 = 0 ;
for ( ; i > 3; i -= 4 )
if ( (abs_ix[i-1] | abs_ix[i-2] | abs_ix[i-3] | abs_ix[i-4]) <= 1 )
{
cod_info->count1++;
}
else
break;
cod_info->big_values = i/2;
}
/*===================*/
for ( i = cod_info->big_values * 2, k = 0; k < cod_info->count1; i += 4, k++ )
{
v = abs_ix[ i ];
w = abs_ix[ i + 1 ];
x = abs_ix[ i + 2 ];
y = abs_ix[ i + 3 ];
p = v + (w << 1) + (x << 2) + (y << 3);
signbits = v + w + x + y;
sum0 += signbits;
sum1 += signbits;
sum0 += ht[ 32 ].hlen[ p ];
sum1 += ht[ 33 ].hlen[ p ];
}
if ( sum0 < sum1 )
{
bitsum_count1 = sum0;
cod_info->count1table_select = 0;
}
else
{
bitsum_count1 = sum1;
cod_info->count1table_select = 1;
}
return( bitsum_count1 );
}
struct
{
unsigned region0_count;
unsigned region1_count;
} subdv_table[ 23 ] =
{
{0, 0}, /* 0 bands */
{0, 0}, /* 1 bands */
{0, 0}, /* 2 bands */
{0, 0}, /* 3 bands */
{0, 0}, /* 4 bands */
{0, 1}, /* 5 bands */
{1, 1}, /* 6 bands */
{1, 1}, /* 7 bands */
{1, 2}, /* 8 bands */
{2, 2}, /* 9 bands */
{2, 3}, /* 10 bands */
{2, 3}, /* 11 bands */
{3, 4}, /* 12 bands */
{3, 4}, /* 13 bands */
{3, 4}, /* 14 bands */
{4, 5}, /* 15 bands */
{4, 5}, /* 16 bands */
{4, 6}, /* 17 bands */
{5, 6}, /* 18 bands */
{5, 6}, /* 19 bands */
{5, 7}, /* 20 bands */
{6, 7}, /* 21 bands */
{6, 7}, /* 22 bands */
};
/*************************************************************************/
/* subdivide */
/*************************************************************************/
/* presumable subdivides the bigvalue region which will
use separate Huffman tables.
*/
void subdivide( gr_info *cod_info )
{
int scfb_anz = 0;
int bigvalues_region;
if ( cod_info->big_values == 0 )
{ /* no big_values region */
cod_info->region0_count = 0;
cod_info->region1_count = 0;
}
else
{
bigvalues_region = 2 * cod_info->big_values;
if ( (cod_info->window_switching_flag == 0) )
{ /* long blocks */
int thiscount, index;
/* Calculate scfb_anz */
while ( scalefac_band_long[scfb_anz] < bigvalues_region )
scfb_anz++;
/* assert( scfb_anz < 23 ); */
cod_info->region0_count = subdv_table[scfb_anz].region0_count;
thiscount = cod_info->region0_count;
index = thiscount + 1;
while ( thiscount && (scalefac_band_long[index] > bigvalues_region) )
{
thiscount -= 1;
index -= 1;
}
cod_info->region0_count = thiscount;
cod_info->region1_count = subdv_table[scfb_anz].region1_count;
index = cod_info->region0_count + cod_info->region1_count + 2;
thiscount = cod_info->region1_count;
while ( thiscount && (scalefac_band_long[index] > bigvalues_region) )
{
thiscount -= 1;
index -= 1;
}
cod_info->region1_count = thiscount;
cod_info->address1 = scalefac_band_long[cod_info->region0_count+1];
cod_info->address2 = scalefac_band_long[cod_info->region0_count
+ cod_info->region1_count + 2 ];
cod_info->address3 = bigvalues_region;
}
else
{
if ( (cod_info->block_type == 2) && (cod_info->mixed_block_flag == 0) )
{
cod_info->region0_count = 8;
cod_info->region1_count = 36;
cod_info->address1 = 36;
cod_info->address2 = bigvalues_region;
cod_info->address3 = 0;
}
else
{
cod_info->region0_count = 7;
cod_info->region1_count = 13;
cod_info->address1 = scalefac_band_long[cod_info->region0_count+1];
cod_info->address2 = bigvalues_region;
cod_info->address3 = 0;
}
}
}
}
/*************************************************************************/
/* bigv_tab_select */
/*************************************************************************/
/* Function: Select huffman code tables for bigvalues regions */
void bigv_tab_select_tj( int abs_ix[576], gr_info *cod_info )
{
/* int max; */
cod_info->table_select[0] = 0;
cod_info->table_select[1] = 0;
cod_info->table_select[2] = 0;
if ( cod_info->window_switching_flag && (cod_info->block_type == 2) )
{
/*
Within each scalefactor band, data is given for successive
time windows, beginning with window 0 and ending with window 2.
Within each window, the quantized values are then arranged in
order of increasing frequency...
*/
int sfb, window, line, start, end, max1, max2, x, y;
int *pmax;
int tMax;
max1 = max2 = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -