📄 layeriiidecoder.java
字号:
290,251,271,291,252,272,292,253,273,293,254,274,294,255,275,295,
256,276,296,257,277,297,258,278,298,259,279,299,300,326,352,301,
327,353,302,328,354,303,329,355,304,330,356,305,331,357,306,332,
358,307,333,359,308,334,360,309,335,361,310,336,362,311,337,363,
312,338,364,313,339,365,314,340,366,315,341,367,316,342,368,317,
343,369,318,344,370,319,345,371,320,346,372,321,347,373,322,348,
374,323,349,375,324,350,376,325,351,377,378,444,510,379,445,511,
380,446,512,381,447,513,382,448,514,383,449,515,384,450,516,385,
451,517,386,452,518,387,453,519,388,454,520,389,455,521,390,456,
522,391,457,523,392,458,524,393,459,525,394,460,526,395,461,527,
396,462,528,397,463,529,398,464,530,399,465,531,400,466,532,401,
467,533,402,468,534,403,469,535,404,470,536,405,471,537,406,472,
538,407,473,539,408,474,540,409,475,541,410,476,542,411,477,543,
412,478,544,413,479,545,414,480,546,415,481,547,416,482,548,417,
483,549,418,484,550,419,485,551,420,486,552,421,487,553,422,488,
554,423,489,555,424,490,556,425,491,557,426,492,558,427,493,559,
428,494,560,429,495,561,430,496,562,431,497,563,432,498,564,433,
499,565,434,500,566,435,501,567,436,502,568,437,503,569,438,504,
570,439,505,571,440,506,572,441,507,573,442,508,574,443,509,575},
{0,4,8,1,5,9,2,6,10,3,7,11,12,16,20,13,
17,21,14,18,22,15,19,23,24,28,32,25,29,33,26,30,
34,27,31,35,36,40,44,37,41,45,38,42,46,39,43,47,
48,54,60,49,55,61,50,56,62,51,57,63,52,58,64,53,
59,65,66,74,82,67,75,83,68,76,84,69,77,85,70,78,
86,71,79,87,72,80,88,73,81,89,90,102,114,91,103,115,
92,104,116,93,105,117,94,106,118,95,107,119,96,108,120,97,
109,121,98,110,122,99,111,123,100,112,124,101,113,125,126,142,
158,127,143,159,128,144,160,129,145,161,130,146,162,131,147,163,
132,148,164,133,149,165,134,150,166,135,151,167,136,152,168,137,
153,169,138,154,170,139,155,171,140,156,172,141,157,173,174,194,
214,175,195,215,176,196,216,177,197,217,178,198,218,179,199,219,
180,200,220,181,201,221,182,202,222,183,203,223,184,204,224,185,
205,225,186,206,226,187,207,227,188,208,228,189,209,229,190,210,
230,191,211,231,192,212,232,193,213,233,234,260,286,235,261,287,
236,262,288,237,263,289,238,264,290,239,265,291,240,266,292,241,
267,293,242,268,294,243,269,295,244,270,296,245,271,297,246,272,
298,247,273,299,248,274,300,249,275,301,250,276,302,251,277,303,
252,278,304,253,279,305,254,280,306,255,281,307,256,282,308,257,
283,309,258,284,310,259,285,311,312,346,380,313,347,381,314,348,
382,315,349,383,316,350,384,317,351,385,318,352,386,319,353,387,
320,354,388,321,355,389,322,356,390,323,357,391,324,358,392,325,
359,393,326,360,394,327,361,395,328,362,396,329,363,397,330,364,
398,331,365,399,332,366,400,333,367,401,334,368,402,335,369,403,
336,370,404,337,371,405,338,372,406,339,373,407,340,374,408,341,
375,409,342,376,410,343,377,411,344,378,412,345,379,413,414,456,
498,415,457,499,416,458,500,417,459,501,418,460,502,419,461,503,
420,462,504,421,463,505,422,464,506,423,465,507,424,466,508,425,
467,509,426,468,510,427,469,511,428,470,512,429,471,513,430,472,
514,431,473,515,432,474,516,433,475,517,434,476,518,435,477,519,
436,478,520,437,479,521,438,480,522,439,481,523,440,482,524,441,
483,525,442,484,526,443,485,527,444,486,528,445,487,529,446,488,
530,447,489,531,448,490,532,449,491,533,450,492,534,451,493,535,
452,494,536,453,495,537,454,496,538,455,497,539,540,552,564,541,
553,565,542,554,566,543,555,567,544,556,568,545,557,569,546,558,
570,547,559,571,548,560,572,549,561,573,550,562,574,551,563,575}
};
private final static int SSLIMIT = 18;
private final static int SBLIMIT = 32;
final static int slen0[] ={0,0,0,0,3,1,1,1,2,2,2,3,3,3,4,4};
final static int slen1[] ={0,1,2,3,0,1,2,3,1,2,3,1,2,3,2,3};
private final static HuffmanTables.Huffman huff = new HuffmanTables.Huffman();
private final static int[] is_pos = new int[576];
private final static float[] is_ratio = new float[576];
private final static float[] tsOutCopy = new float[18];
private final static float[] rawout = new float[36];
private static final int[] is_1d = new int[SBLIMIT * SSLIMIT + 4];
private static final float[][][] ro = new float[2][SBLIMIT][SSLIMIT];
private static final float[][][] lr = new float[2][SBLIMIT][SSLIMIT];
private static final float[] out_1d = new float[SBLIMIT * SSLIMIT];
private static final float[][] prevblck = new float[2][SBLIMIT * SSLIMIT];
private static final float[][] k = new float[2][SBLIMIT * SSLIMIT];
private static int nonzero0,nonzero1;
private static BitStream stream;
private static Header header;
private static SynthesisFilter filter1,filter2;
private static SampleBuffer buffer;
private static int which_channels;
private static BitReserve br;
private static SideInfo si;
public static int[] scalefac0L= new int[23];
public static int[][] scalefac0S= new int[3][13];
public static int[] scalefac1L= new int[23];
public static int[][] scalefac1S= new int[3][13];
private static int max_gr;
private static int frame_start;
private static int part2_start;
private static int channels;
private static int first_channel;
private static int last_channel;
private static int sfreq;
private final static float[] samples1 = new float[32];
private final static float[] samples2 = new float[32];
private static int[] sfBandIndexL;
private static int[] sfBandIndexS;
private static HuffmanTables h;
public LayerIIIDecoder(BitStream stream0,Header header0,SynthesisFilter filtera,SynthesisFilter filterb,SampleBuffer buffer0,int which_ch0) {
stream = stream0;
header = header0;
filter1 = filtera;
filter2 = filterb;
buffer = buffer0;
which_channels = which_ch0;
frame_start = 0;
channels = (header.mode() == Header.SINGLE_CHANNEL) ? 1 : 2;
max_gr = (header.version() == Header.MPEG1) ? 2 : 1;
sfreq = header.sample_frequency() + ((header.version() == Header.MPEG1) ? 3 : 0);
switch(sfreq){
case 0:
sfBandIndexL = new int[]{0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576};
sfBandIndexS = new int[]{0,4,8,12,18,24,32,42,56,74,100,132,174,192};
break;
case 1:
sfBandIndexL = new int[]{0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,330,394,464,540,576};
sfBandIndexS = new int[]{0,4,8,12,18,26,36,48,62,80,104,136,180,192};
break;
case 2:
sfBandIndexL = new int[]{0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576};
sfBandIndexS = new int[]{0,4,8,12,18,26,36,48,62,80,104,134,174,192};
break;
case 3:
sfBandIndexL = new int[]{0,4,8,12,16,20,24,30,36,44,52,62,74,90,110,134,162,196,238,288,342,418,576};
sfBandIndexS = new int[]{0,4,8,12,16,22,30,40,52,66,84,106,136,192};
break;
case 4:
sfBandIndexL = new int[]{0,4,8,12,16,20,24,30,36,42,50,60,72,88,106,128,156,190,230,276,330,384,576};
sfBandIndexS = new int[]{0,4,8,12,16,22,28,38,50,64,80,100,126,192};
break;
case 5:
sfBandIndexL = new int[]{0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576};
sfBandIndexS = new int[]{0,4,8,12,16,22,30,42,58,78,104,138,180,192};
break;
}
if (channels == 2) {
switch (which_channels) {
case OutputChannels.LEFT_CHANNEL:
case OutputChannels.DOWNMIX_CHANNELS:
first_channel = last_channel = 0;
break;
case OutputChannels.RIGHT_CHANNEL:
first_channel = last_channel = 1;
break;
case OutputChannels.BOTH_CHANNELS:
default:
first_channel = 0;
last_channel = 1;
break;
}
}
else {
first_channel = last_channel = 0;
}
for (int ch = 0; ch < 2; ch++) {
for (int j = 0; j < 576; j++) {
prevblck[ch][j] = 0.0f;
}
}
nonzero0 = nonzero1 = 576;
br = new BitReserve();
si = new SideInfo();
h = new HuffmanTables();
}
public final void decodeFrame() {
int compteur = 0;
int nSlots = header.slots();
get_side_info();
for (int i = 0; i < nSlots; i++) {
br.hputbuf(stream.readbits(8));
}
int main_data_end = BitReserve.totbit >>> 3;
int flush_main = (BitReserve.totbit & 7);
if (flush_main != 0) {
br.hgetbits(8 - flush_main);
main_data_end++;
}
// E.B Fix.
int bytes_to_discard = frame_start - main_data_end - si.main_data_begin;
frame_start += nSlots;
if(bytes_to_discard < 0)
return;
// End of E.B Fix.
if (main_data_end > 4096) {
frame_start -= 4096;
br.rewindNbytes(4096);
}
while(bytes_to_discard-->0)
br.hgetbits(8);
//System.out.println("max gr : " + max_gr);
for (int gr = 0; gr < max_gr; gr++) {
for (int ch = 0; ch < channels; ch++) {
part2_start = BitReserve.totbit;
get_scale_factors(ch,gr);
huffman_decode(ch,gr);
dequantize_sample(ro[ch],ch,gr);
}
stereo(gr);
for (int ch = first_channel; ch <= last_channel; ch++) {
reorder(lr[ch],ch,gr);
antialias(ch,gr);
hybrid(ch,gr);
for(int sb18 = 18; sb18 < 576; sb18 += 36){
for(int ss=1; ss < SSLIMIT; ss += 2){
out_1d[sb18 + ss] *= -1;
}
}
if ((ch == 0) || (which_channels == OutputChannels.RIGHT_CHANNEL)) {
for(int ss=0; ss < SSLIMIT; ss++){
for(int sb18 = 0,sb = 0; sb18 < 576; sb18 += 18){
samples1[sb++] = out_1d[sb18 + ss];
}
filter1.calculateSamples(samples1,buffer);
}
}
else {
for(int ss=0; ss < SSLIMIT; ss++){
for(int sb18 = 0,sb = 0; sb18 < 576; sb18 += 18){
samples2[sb++] = out_1d[sb18 + ss];
}
compteur++;
//System.out.println("compute : " + SSLIMIT);
filter2.calculateSamples(samples2,buffer);
}
}
}
}
}
public void invMDCT(final float[] in,final float[] out,final int block_type) {
if (block_type == 2) {
for(int i=0; i<36; i++)
out[i] = 0;
int six_i = 0;
for (int i = 0; i < 3; i++) {
// 12 point IMDCT
// Begin 12 point IDCT
// Input aliasing for 12 pt IDCT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -