From: yeom Date: Thu, 28 Jul 2011 09:02:08 +0000 (+0000) Subject: changes. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=93b568d529dfe9b9758052e295d8d36198fdf558;p=IRC.git changes. --- diff --git a/Robust/src/Tests/ssJava/mp3decoder/HuffData.java b/Robust/src/Tests/ssJava/mp3decoder/HuffData.java new file mode 100644 index 00000000..6cc74cf0 --- /dev/null +++ b/Robust/src/Tests/ssJava/mp3decoder/HuffData.java @@ -0,0 +1,18 @@ +// need to have this class for liner type system +public class HuffData { + + public int x; + public int y; + public int w; + public int v; + public BitReserve br; + + public HuffData(int x, int y, int w, int v, BitReserve br) { + this.x = x; + this.y = y; + this.w = w; + this.v = v; + this.br = br; + } + +} diff --git a/Robust/src/Tests/ssJava/mp3decoder/LayerIIIDecoder.java b/Robust/src/Tests/ssJava/mp3decoder/LayerIIIDecoder.java index 48b0d1b2..b96aa019 100644 --- a/Robust/src/Tests/ssJava/mp3decoder/LayerIIIDecoder.java +++ b/Robust/src/Tests/ssJava/mp3decoder/LayerIIIDecoder.java @@ -46,8 +46,8 @@ // 9th added for get_LSF_scale_factors // 10th added for get_scale_factors // llth added for decode -// @LATTICE("NZ*,SI sfBandIndex[sfreq].l.length - 1) + if (buf1 > sfBandIndex[sfreq].l.length - 1) { buf1 = sfBandIndex[sfreq].l.length - 1; + } region1Start = sfBandIndex[sfreq].l[buf]; region2Start = sfBandIndex[sfreq].l[buf1]; /* MI */ } index = 0; + @LOC("I") int h; // Read bigvalues area for (@LOC("I") int i = 0; i < (si.ch[ch].gr[gr].big_values << 1); i += 2) { - if (i < region1Start) - h = huffcodetab.ht[si.ch[ch].gr[gr].table_select[0]]; - else if (i < region2Start) - h = huffcodetab.ht[si.ch[ch].gr[gr].table_select[1]]; - else - h = huffcodetab.ht[si.ch[ch].gr[gr].table_select[2]]; + if (i < region1Start) { + // huffcodetab.huffman_decoder(h, x, y, v, w, br); + h = si.ch[ch].gr[gr].table_select[0]; + } else if (i < region2Start) { + h = si.ch[ch].gr[gr].table_select[1]; + // h = huffcodetab.ht[si.ch[ch].gr[gr].table_select[1]]; + } else { + h = si.ch[ch].gr[gr].table_select[2]; + // h = huffcodetab.ht[si.ch[ch].gr[gr].table_select[2]]; + } + + @LOC("I") HuffData huffData = huffcodetab.huffman_decoder(h, new HuffData(x, y, v, w, br)); + x = huffData.x; + y = huffData.y; + v = huffData.v; + w = huffData.w; + br = huffData.br; - huffcodetab.huffman_decoder(h, x, y, v, w, br); // if (index >= is_1d.length) // System.out.println("i0="+i+"/"+(si.ch[ch].gr[gr].big_values<<1)+" Index="+index+" is_1d="+is_1d.length); - is_1d[index++] = x[0]; - is_1d[index++] = y[0]; + is_1d[index++] = x; + is_1d[index++] = y; - CheckSumHuff = CheckSumHuff + x[0] + y[0]; + CheckSumHuff = CheckSumHuff + x + y; // System.out.println("x = "+x[0]+" y = "+y[0]); } // Read count1 area - h = huffcodetab.ht[si.ch[ch].gr[gr].count1table_select + 32]; + // h = huffcodetab.ht[si.ch[ch].gr[gr].count1table_select + 32]; num_bits = br.hsstell(); while ((num_bits < part2_3_end) && (index < 576)) { - huffcodetab.huffman_decoder(h, x, y, v, w, br); - - is_1d[index++] = v[0]; - is_1d[index++] = w[0]; - is_1d[index++] = x[0]; - is_1d[index++] = y[0]; - CheckSumHuff = CheckSumHuff + v[0] + w[0] + x[0] + y[0]; + // huffcodetab.huffman_decoder(h, x, y, v, w, br); + @LOC("I") HuffData huffData2 = + huffcodetab.huffman_decoder(si.ch[ch].gr[gr].count1table_select + 32, new HuffData(x, y, + v, w, br)); + x = huffData2.x; + y = huffData2.y; + v = huffData2.v; + w = huffData2.w; + br = huffData2.br; + + is_1d[index++] = v; + is_1d[index++] = w; + is_1d[index++] = x; + is_1d[index++] = y; + CheckSumHuff = CheckSumHuff + v + w + x + y; // System.out.println("v = "+v[0]+" w = "+w[0]); // System.out.println("x = "+x[0]+" y = "+y[0]); num_bits = br.hsstell(); @@ -2094,35 +2126,35 @@ final class LayerIIIDecoder implements FrameDecoder { } } - @LATTICE("N>> 4; - y[0] = h.val[point][1] & 0xf; - error = 0; - break; - } - - // hget1bit() is called thousands of times, and so needs to be - // ultra fast. - /* - if (bitIndex==bitsAvailable) - { - bitsAvailable = br.readBits(bits, 32); - bitIndex = 0; - } - */ - //if (bits[bitIndex++]!=0) - if (br.hget1bit()!=0) - { - while (h.val[point][1] >= MXOFF) point += h.val[point][1]; - point += h.val[point][1]; - } - else - { - while (h.val[point][0] >= MXOFF) point += h.val[point][0]; - point += h.val[point][0]; - } - level >>>= 1; - // MDM: ht[0] is always 0; - } while ((level !=0 ) || (point < 0 /*ht[0].treelen*/) ); - - // put back any bits not consumed - /* - int unread = (bitsAvailable-bitIndex); - if (unread>0) - br.rewindNbits(unread); - */ - /* Process sign encodings for quadruples tables. */ - // System.out.println(h.tablename); - if (h.tablename0 == '3' && (h.tablename1 == '2' || h.tablename1 == '3')) - { - v[0] = (y[0]>>3) & 1; - w[0] = (y[0]>>2) & 1; - x[0] = (y[0]>>1) & 1; - y[0] = y[0] & 1; - - /* v, w, x and y are reversed in the bitstream. - switch them around to make test bistream work. */ - - if (v[0]!=0) - if (br.hget1bit() != 0) v[0] = -v[0]; - if (w[0]!=0) - if (br.hget1bit() != 0) w[0] = -w[0]; - if (x[0]!=0) - if (br.hget1bit() != 0) x[0] = -x[0]; - if (y[0]!=0) - if (br.hget1bit() != 0) y[0] = -y[0]; - } - else - { - // Process sign and escape encodings for dual tables. - // x and y are reversed in the test bitstream. - // Reverse x and y here to make test bitstream work. - - if (h.linbits != 0) - if ((h.xlen-1) == x[0]) - x[0] += br.hgetbits(h.linbits); - if (x[0] != 0) - if (br.hget1bit() != 0) x[0] = -x[0]; - if (h.linbits != 0) - if ((h.ylen-1) == y[0]) - y[0] += br.hgetbits(h.linbits); - if (y[0] != 0) - if (br.hget1bit() != 0) y[0] = -y[0]; - } - return error; + // public static int huffman_decoder(/* @LOC("IN") huffcodetab h, */@LOC("IN") + // int idx, + // @LOC("X") int[] x, @LOC("Y") int[] y, @LOC("V") int[] v, @LOC("W") int[] w, + // @LOC("IN") BitReserve br) { + public static HuffData huffman_decoder(@LOC("IN") int idx, @LOC("IN") HuffData data) { + // array of all huffcodtable headers + // 0..31 Huffman code table 0..31 + // 32,33 count1-tables + + @LOC("IN") int dmask = 1 << ((4 * 8) - 1); + @LOC("IN") int hs = 4 * 8; + @LOC("VAR") int level; + @LOC("VAR") int point = 0; + @LOC("OUT") int error = 1; + level = dmask; + + if (ht[idx].val == null){ +// return 2; + return data; + } + + /* table 0 needs no bits */ + if (ht[idx].treelen == 0) { + data.y = 0; + data.x = 0; +// return 0; + return data; + } + + /* Lookup in Huffman table. */ + + /* + * int bitsAvailable = 0; int bitIndex = 0; + * + * int bits[] = bitbuf; + */ + do { + if (ht[idx].val[point][0] == 0) { /* end of tree */ + data.x = ht[idx].val[point][1] >>> 4; + data.y = ht[idx].val[point][1] & 0xf; + error = 0; + break; + } + + // hget1bit() is called thousands of times, and so needs to be + // ultra fast. + /* + * if (bitIndex==bitsAvailable) { bitsAvailable = br.readBits(bits, 32); + * bitIndex = 0; } + */ + // if (bits[bitIndex++]!=0) + if (data.br.hget1bit() != 0) { + while (ht[idx].val[point][1] >= MXOFF) + point += ht[idx].val[point][1]; + point += ht[idx].val[point][1]; + } else { + while (ht[idx].val[point][0] >= MXOFF) + point += ht[idx].val[point][0]; + point += ht[idx].val[point][0]; + } + level >>>= 1; + // MDM: ht[0] is always 0; + } while ((level != 0) || (point < 0 /* ht[0].treelen */)); + + // put back any bits not consumed + /* + * int unread = (bitsAvailable-bitIndex); if (unread>0) + * br.rewindNbits(unread); + */ + /* Process sign encodings for quadruples tables. */ + // System.out.println(h.tablename); + if (ht[idx].tablename0 == '3' && (ht[idx].tablename1 == '2' || ht[idx].tablename1 == '3')) { + data.v = (data.y >> 3) & 1; + data.w = (data.y >> 2) & 1; + data.x = (data.y >> 1) & 1; + data.y = data.y & 1; + + /* + * v, w, x and y are reversed in the bitstream. switch them around to make + * test bistream work. + */ + + if (data.v != 0) + if (data.br.hget1bit() != 0) + data.v = -data.v; + if (data.w != 0) + if (data.br.hget1bit() != 0) + data.w = -data.w; + if (data.x != 0) + if (data.br.hget1bit() != 0) + data.x = -data.x; + if (data.y != 0) + if (data.br.hget1bit() != 0) + data.y = -data.y; + } else { + // Process sign and escape encodings for dual tables. + // x and y are reversed in the test bitstream. + // Reverse x and y here to make test bitstream work. + + if (ht[idx].linbits != 0) + if ((ht[idx].xlen - 1) == data.x) + data.x += data.br.hgetbits(ht[idx].linbits); + if (data.x != 0) + if (data.br.hget1bit() != 0) + data.x = -data.x; + if (ht[idx].linbits != 0) + if ((ht[idx].ylen - 1) == data.y) + data.y += data.br.hgetbits(ht[idx].linbits); + if (data.y != 0) + if (data.br.hget1bit() != 0) + data.y = -data.y; + } + + return data; +// return error; } - public static void inithuff() - { - - if (ht!=null) - return; - + public static void inithuff() { + + if (ht != null) + return; + ht = new huffcodetab[HTN]; - ht[0] = new huffcodetab("0 ",0,0,0,0,-1,null,null,ValTab0,0); - ht[1] = new huffcodetab("1 ",2,2,0,0,-1,null,null,ValTab1,7); - ht[2] = new huffcodetab("2 ",3,3,0,0,-1,null,null,ValTab2,17); - ht[3] = new huffcodetab("3 ",3,3,0,0,-1,null,null,ValTab3,17); - ht[4] = new huffcodetab("4 ",0,0,0,0,-1,null,null,ValTab4,0); - ht[5] = new huffcodetab("5 ",4,4,0,0,-1,null,null,ValTab5,31); - ht[6] = new huffcodetab("6 ",4,4,0,0,-1,null,null,ValTab6,31); - ht[7] = new huffcodetab("7 ",6,6,0,0,-1,null,null,ValTab7,71); - ht[8] = new huffcodetab("8 ",6,6,0,0,-1,null,null,ValTab8,71); - ht[9] = new huffcodetab("9 ",6,6,0,0,-1,null,null,ValTab9,71); - ht[10] = new huffcodetab("10 ",8,8,0,0,-1,null,null,ValTab10,127); - ht[11] = new huffcodetab("11 ",8,8,0,0,-1,null,null,ValTab11,127); - ht[12] = new huffcodetab("12 ",8,8,0,0,-1,null,null,ValTab12,127); - ht[13] = new huffcodetab("13 ",16,16,0,0,-1,null,null,ValTab13,511); - ht[14] = new huffcodetab("14 ",0,0,0,0,-1,null,null,ValTab14,0); - ht[15] = new huffcodetab("15 ",16,16,0,0,-1,null,null,ValTab15,511); - ht[16] = new huffcodetab("16 ",16,16,1,1,-1,null,null,ValTab16,511); - ht[17] = new huffcodetab("17 ",16,16,2,3,16,null,null,ValTab16,511); - ht[18] = new huffcodetab("18 ",16,16,3,7,16,null,null,ValTab16,511); - ht[19] = new huffcodetab("19 ",16,16,4,15,16,null,null,ValTab16,511); - ht[20] = new huffcodetab("20 ",16,16,6,63,16,null,null,ValTab16,511); - ht[21] = new huffcodetab("21 ",16,16,8,255,16,null,null,ValTab16,511); - ht[22] = new huffcodetab("22 ",16,16,10,1023,16,null,null,ValTab16,511); - ht[23] = new huffcodetab("23 ",16,16,13,8191,16,null,null,ValTab16,511); - ht[24] = new huffcodetab("24 ",16,16,4,15,-1,null,null,ValTab24,512); - ht[25] = new huffcodetab("25 ",16,16,5,31,24,null,null,ValTab24,512); - ht[26] = new huffcodetab("26 ",16,16,6,63,24,null,null,ValTab24,512); - ht[27] = new huffcodetab("27 ",16,16,7,127,24,null,null,ValTab24,512); - ht[28] = new huffcodetab("28 ",16,16,8,255,24,null,null,ValTab24,512); - ht[29] = new huffcodetab("29 ",16,16,9,511,24,null,null,ValTab24,512); - ht[30] = new huffcodetab("30 ",16,16,11,2047,24,null,null,ValTab24,512); - ht[31] = new huffcodetab("31 ",16,16,13,8191,24,null,null,ValTab24,512); - ht[32] = new huffcodetab("32 ",1,16,0,0,-1,null,null,ValTab32,31); - ht[33] = new huffcodetab("33 ",1,16,0,0,-1,null,null,ValTab33,31); + ht[0] = new huffcodetab("0 ", 0, 0, 0, 0, -1, null, null, ValTab0, 0); + ht[1] = new huffcodetab("1 ", 2, 2, 0, 0, -1, null, null, ValTab1, 7); + ht[2] = new huffcodetab("2 ", 3, 3, 0, 0, -1, null, null, ValTab2, 17); + ht[3] = new huffcodetab("3 ", 3, 3, 0, 0, -1, null, null, ValTab3, 17); + ht[4] = new huffcodetab("4 ", 0, 0, 0, 0, -1, null, null, ValTab4, 0); + ht[5] = new huffcodetab("5 ", 4, 4, 0, 0, -1, null, null, ValTab5, 31); + ht[6] = new huffcodetab("6 ", 4, 4, 0, 0, -1, null, null, ValTab6, 31); + ht[7] = new huffcodetab("7 ", 6, 6, 0, 0, -1, null, null, ValTab7, 71); + ht[8] = new huffcodetab("8 ", 6, 6, 0, 0, -1, null, null, ValTab8, 71); + ht[9] = new huffcodetab("9 ", 6, 6, 0, 0, -1, null, null, ValTab9, 71); + ht[10] = new huffcodetab("10 ", 8, 8, 0, 0, -1, null, null, ValTab10, 127); + ht[11] = new huffcodetab("11 ", 8, 8, 0, 0, -1, null, null, ValTab11, 127); + ht[12] = new huffcodetab("12 ", 8, 8, 0, 0, -1, null, null, ValTab12, 127); + ht[13] = new huffcodetab("13 ", 16, 16, 0, 0, -1, null, null, ValTab13, 511); + ht[14] = new huffcodetab("14 ", 0, 0, 0, 0, -1, null, null, ValTab14, 0); + ht[15] = new huffcodetab("15 ", 16, 16, 0, 0, -1, null, null, ValTab15, 511); + ht[16] = new huffcodetab("16 ", 16, 16, 1, 1, -1, null, null, ValTab16, 511); + ht[17] = new huffcodetab("17 ", 16, 16, 2, 3, 16, null, null, ValTab16, 511); + ht[18] = new huffcodetab("18 ", 16, 16, 3, 7, 16, null, null, ValTab16, 511); + ht[19] = new huffcodetab("19 ", 16, 16, 4, 15, 16, null, null, ValTab16, 511); + ht[20] = new huffcodetab("20 ", 16, 16, 6, 63, 16, null, null, ValTab16, 511); + ht[21] = new huffcodetab("21 ", 16, 16, 8, 255, 16, null, null, ValTab16, 511); + ht[22] = new huffcodetab("22 ", 16, 16, 10, 1023, 16, null, null, ValTab16, 511); + ht[23] = new huffcodetab("23 ", 16, 16, 13, 8191, 16, null, null, ValTab16, 511); + ht[24] = new huffcodetab("24 ", 16, 16, 4, 15, -1, null, null, ValTab24, 512); + ht[25] = new huffcodetab("25 ", 16, 16, 5, 31, 24, null, null, ValTab24, 512); + ht[26] = new huffcodetab("26 ", 16, 16, 6, 63, 24, null, null, ValTab24, 512); + ht[27] = new huffcodetab("27 ", 16, 16, 7, 127, 24, null, null, ValTab24, 512); + ht[28] = new huffcodetab("28 ", 16, 16, 8, 255, 24, null, null, ValTab24, 512); + ht[29] = new huffcodetab("29 ", 16, 16, 9, 511, 24, null, null, ValTab24, 512); + ht[30] = new huffcodetab("30 ", 16, 16, 11, 2047, 24, null, null, ValTab24, 512); + ht[31] = new huffcodetab("31 ", 16, 16, 13, 8191, 24, null, null, ValTab24, 512); + ht[32] = new huffcodetab("32 ", 1, 16, 0, 0, -1, null, null, ValTab32, 31); + ht[33] = new huffcodetab("33 ", 1, 16, 0, 0, -1, null, null, ValTab33, 31); } }