📄 layeriiidecoder.java
字号:
*
*/
private void i_stereo_k_values(int is_pos, int io_type, int i)
{
if (is_pos == 0) {
k[0][i] = 1.0f;
k[1][i] = 1.0f;
} else if ((is_pos & 1) != 0) {
k[0][i] = io[io_type][(is_pos + 1) >>> 1];
k[1][i] = 1.0f;
} else {
k[0][i] = 1.0f;
k[1][i] = io[io_type][is_pos >>> 1];
}
}
/**
*
*/
private void dequantize_sample(float xr[][], int ch, int gr)
{
gr_info_s gr_info = (si.ch[ch].gr[gr]);
int cb=0;
int next_cb_boundary;
int cb_begin = 0;
int cb_width = 0;
int index=0, t_index, j;
float g_gain;
float[][] xr_1d = xr;
// choose correct scalefactor band per block type, initalize boundary
if ((gr_info.window_switching_flag !=0 ) && (gr_info.block_type == 2) ) {
if (gr_info.mixed_block_flag != 0)
next_cb_boundary=sfBandIndex[sfreq].l[1]; // LONG blocks: 0,1,3
else {
cb_width = sfBandIndex[sfreq].s[1];
next_cb_boundary = (cb_width << 2) - cb_width;
cb_begin = 0;
}
} else {
next_cb_boundary=sfBandIndex[sfreq].l[1]; // LONG blocks: 0,1,3
}
// Compute overall (global) scaling.
g_gain = (float) Math.pow(2.0 , (0.25 * (gr_info.global_gain - 210.0)));
for (j=0; j<nonzero[ch]; j++)
{
// Modif E.B 02/22/99
int reste = j % SSLIMIT;
int quotien = (int) ((j-reste)/SSLIMIT);
if (is_1d[j] == 0) xr_1d[quotien][reste] = 0.0f;
else
{
int abv = is_1d[j];
if (is_1d[j] > 0) xr_1d[quotien][reste] = g_gain * t_43[abv];
else xr_1d[quotien][reste] = -g_gain * t_43[-abv];
}
}
// apply formula per block type
for (j=0; j<nonzero[ch]; j++)
{
// Modif E.B 02/22/99
int reste = j % SSLIMIT;
int quotien = (int) ((j-reste)/SSLIMIT);
if (index == next_cb_boundary) { /* Adjust critical band boundary */
if ((gr_info.window_switching_flag != 0) && (gr_info.block_type == 2)) {
if (gr_info.mixed_block_flag != 0) {
if (index == sfBandIndex[sfreq].l[8]) {
next_cb_boundary = sfBandIndex[sfreq].s[4];
next_cb_boundary = (next_cb_boundary << 2) -
next_cb_boundary;
cb = 3;
cb_width = sfBandIndex[sfreq].s[4] -
sfBandIndex[sfreq].s[3];
cb_begin = sfBandIndex[sfreq].s[3];
cb_begin = (cb_begin << 2) - cb_begin;
} else if (index < sfBandIndex[sfreq].l[8]) {
next_cb_boundary = sfBandIndex[sfreq].l[(++cb)+1];
} else {
next_cb_boundary = sfBandIndex[sfreq].s[(++cb)+1];
next_cb_boundary = (next_cb_boundary << 2) -
next_cb_boundary;
cb_begin = sfBandIndex[sfreq].s[cb];
cb_width = sfBandIndex[sfreq].s[cb+1] -
cb_begin;
cb_begin = (cb_begin << 2) - cb_begin;
}
} else {
next_cb_boundary = sfBandIndex[sfreq].s[(++cb)+1];
next_cb_boundary = (next_cb_boundary << 2) -
next_cb_boundary;
cb_begin = sfBandIndex[sfreq].s[cb];
cb_width = sfBandIndex[sfreq].s[cb+1] -
cb_begin;
cb_begin = (cb_begin << 2) - cb_begin;
}
} else { // long blocks
next_cb_boundary = sfBandIndex[sfreq].l[(++cb)+1];
}
}
// Do long/short dependent scaling operations
if ((gr_info.window_switching_flag !=0)&&
(((gr_info.block_type == 2) && (gr_info.mixed_block_flag == 0)) ||
((gr_info.block_type == 2) && (gr_info.mixed_block_flag!=0) && (j >= 36)) ))
{
t_index = (index - cb_begin) / cb_width;
/* xr[sb][ss] *= pow(2.0, ((-2.0 * gr_info.subblock_gain[t_index])
-(0.5 * (1.0 + gr_info.scalefac_scale)
* scalefac[ch].s[t_index][cb]))); */
int idx = scalefac[ch].s[t_index][cb]
<< gr_info.scalefac_scale;
idx += (gr_info.subblock_gain[t_index] << 2);
xr_1d[quotien][reste] *= two_to_negative_half_pow[idx];
} else { // LONG block types 0,1,3 & 1st 2 subbands of switched blocks
/* xr[sb][ss] *= pow(2.0, -0.5 * (1.0+gr_info.scalefac_scale)
* (scalefac[ch].l[cb]
+ gr_info.preflag * pretab[cb])); */
int idx = scalefac[ch].l[cb];
if (gr_info.preflag != 0)
idx += pretab[cb];
idx = idx << gr_info.scalefac_scale;
xr_1d[quotien][reste] *= two_to_negative_half_pow[idx];
}
index++;
}
for (j=nonzero[ch]; j<576; j++)
{
// Modif E.B 02/22/99
int reste = j % SSLIMIT;
int quotien = (int) ((j-reste)/SSLIMIT);
xr_1d[quotien][reste] = 0.0f;
}
return;
}
/**
*
*/
private void reorder(float xr[][], int ch, int gr)
{
gr_info_s gr_info = (si.ch[ch].gr[gr]);
int freq, freq3;
int index;
int sfb, sfb_start, sfb_lines;
int src_line, des_line;
float[][] xr_1d = xr;
if ((gr_info.window_switching_flag !=0) && (gr_info.block_type == 2)) {
for(index=0; index<576; index++)
out_1d[index] = 0.0f;
if (gr_info.mixed_block_flag !=0 ) {
// NO REORDER FOR LOW 2 SUBBANDS
for (index = 0; index < 36; index++)
{
// Modif E.B 02/22/99
int reste = index % SSLIMIT;
int quotien = (int) ((index-reste)/SSLIMIT);
out_1d[index] = xr_1d[quotien][reste];
}
// REORDERING FOR REST SWITCHED SHORT
for( sfb=3,sfb_start=sfBandIndex[sfreq].s[3],
sfb_lines=sfBandIndex[sfreq].s[4] - sfb_start;
sfb < 13; sfb++,sfb_start = sfBandIndex[sfreq].s[sfb],
sfb_lines = sfBandIndex[sfreq].s[sfb+1] - sfb_start )
{
int sfb_start3 = (sfb_start << 2) - sfb_start;
for(freq=0, freq3=0; freq<sfb_lines;
freq++, freq3+=3) {
src_line = sfb_start3 + freq;
des_line = sfb_start3 + freq3;
// Modif E.B 02/22/99
int reste = src_line % SSLIMIT;
int quotien = (int) ((src_line-reste)/SSLIMIT);
out_1d[des_line] = xr_1d[quotien][reste];
src_line += sfb_lines;
des_line++;
reste = src_line % SSLIMIT;
quotien = (int) ((src_line-reste)/SSLIMIT);
out_1d[des_line] = xr_1d[quotien][reste];
src_line += sfb_lines;
des_line++;
reste = src_line % SSLIMIT;
quotien = (int) ((src_line-reste)/SSLIMIT);
out_1d[des_line] = xr_1d[quotien][reste];
}
}
} else { // pure short
for(index=0;index<576;index++)
{
int j = reorder_table[sfreq][index];
int reste = j % SSLIMIT;
int quotien = (int) ((j-reste)/SSLIMIT);
out_1d[index] = xr_1d[quotien][reste];
}
}
}
else { // long blocks
for(index=0; index<576; index++)
{
// Modif E.B 02/22/99
int reste = index % SSLIMIT;
int quotien = (int) ((index-reste)/SSLIMIT);
out_1d[index] = xr_1d[quotien][reste];
}
}
}
/**
*
*/
int[] is_pos = new int[576];
float[] is_ratio = new float[576];
private void stereo(int gr)
{
int sb, ss;
if (channels == 1) { // mono , bypass xr[0][][] to lr[0][][]
for(sb=0;sb<SBLIMIT;sb++)
for(ss=0;ss<SSLIMIT;ss+=3) {
lr[0][sb][ss] = ro[0][sb][ss];
lr[0][sb][ss+1] = ro[0][sb][ss+1];
lr[0][sb][ss+2] = ro[0][sb][ss+2];
}
} else {
gr_info_s gr_info = (si.ch[0].gr[gr]);
int mode_ext = header.mode_extension();
int sfb;
int i;
int lines, temp, temp2;
boolean ms_stereo = ((header.mode() == Header.JOINT_STEREO) && ((mode_ext & 0x2)!=0));
boolean i_stereo = ((header.mode() == Header.JOINT_STEREO) && ((mode_ext & 0x1)!=0));
boolean lsf = ((header.version() == Header.MPEG2_LSF));
int io_type = (gr_info.scalefac_compress & 1);
// initialization
for (i=0; i<576; i++)
{
is_pos[i] = 7;
is_ratio[i] = 0.0f;
}
if (i_stereo) {
if ((gr_info.window_switching_flag !=0 )&& (gr_info.block_type == 2)) {
if (gr_info.mixed_block_flag != 0) {
int max_sfb = 0;
for (int j=0; j<3; j++) {
int sfbcnt;
sfbcnt = 2;
for( sfb=12; sfb >=3; sfb-- ) {
i = sfBandIndex[sfreq].s[sfb];
lines = sfBandIndex[sfreq].s[sfb+1] - i;
i = (i << 2) - i + (j+1) * lines - 1;
while (lines > 0) {
if (ro[1][i/18][i%18] != 0.0f) {
// MDM: in java, array access is very slow.
// Is quicker to compute div and mod values.
//if (ro[1][ss_div[i]][ss_mod[i]] != 0.0f) {
sfbcnt = sfb;
sfb = -10;
lines = -10;
}
lines--;
i--;
} // while (lines > 0)
} // for (sfb=12 ...
sfb = sfbcnt + 1;
if (sfb > max_sfb)
max_sfb = sfb;
while(sfb < 12) {
temp = sfBandIndex[sfreq].s[sfb];
sb = sfBandIndex[sfreq].s[sfb+1] - temp;
i = (temp << 2) - temp + j * sb;
for ( ; sb > 0; sb--) {
is_pos[i] = scalefac[1].s[j][sfb];
if (is_pos[i] != 7)
if (lsf)
i_stereo_k_values(is_pos[i], io_type, i);
else
is_ratio[i] = TAN12[is_pos[i]];
i++;
} // for (; sb>0...
sfb++;
} // while (sfb < 12)
sfb = sfBandIndex[sfreq].s[10];
sb = sfBandIndex[sfreq].s[11] - sfb;
sfb = (sfb << 2) - sfb + j * sb;
temp = sfBandIndex[sfreq].s[11];
sb = sfBandIndex[sfreq].s[12] - temp;
i = (temp << 2) - temp + j * sb;
for (; sb > 0; sb--) {
is_pos[i] = is_pos[sfb];
if (lsf) {
k[0][i] = k[0][sfb];
k[1][i] = k[1][sfb];
} else {
is_ratio[i] = is_ratio[sfb];
}
i++;
} // for (; sb > 0 ...
}
if (max_sfb <= 3) {
i = 2;
ss = 17;
sb = -1;
while (i >= 0) {
if (ro[1][i][ss] != 0.0f) {
sb = (i<<4) + (i<<1) + ss;
i = -1;
} else {
ss--;
if (ss < 0) {
i--;
ss = 17;
}
} // if (ro ...
} // while (i>=0)
i = 0;
while (sfBandIndex[sfreq].l[i] <= sb)
i++;
sfb = i;
i = sfBandIndex[sfreq].l[i];
for (; sfb<8; sfb++) {
sb = sfBandIndex[sfreq].l[sfb+1]-sfBandIndex[sfreq].l[sfb];
for (; sb>0; sb--) {
is_pos[i] = scalefac[1].l[sfb];
if (is_pos[i] != 7)
if (lsf)
i_stereo_k_values(is_pos[i], io_type, i);
else
is_ratio[i] = TAN12[is_pos[i]];
i++;
} // for (; sb>0 ...
} // for (; sfb<8 ...
} // for (j=0 ...
} else { // if (gr_info.mixed_block_flag)
for (int j=0; j<3; j++) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -