-/*\r
- * 11/19/04 1.0 moved to LGPL.\r
- * \r
- * 12/12/99 0.0.7 Implementation stores single bits \r
- * as ints for better performance. mdm@techie.com.\r
- *\r
- * 02/28/99 0.0 Java Conversion by E.B, javalayer@javazoom.net\r
- *\r
- * Adapted from the public c code by Jeff Tsay.\r
- *\r
- *-----------------------------------------------------------------------\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Library General Public License as published\r
- * by the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU Library General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Library General Public\r
- * License along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
- *----------------------------------------------------------------------\r
- */\r
-\r
-/**\r
- * Implementation of Bit Reservoir for Layer III.\r
- * <p>\r
- * The implementation stores single bits as a word in the buffer. If a bit is\r
- * set, the corresponding word in the buffer will be non-zero. If a bit is\r
- * clear, the corresponding word is zero. Although this may seem waseful, this\r
- * can be a factor of two quicker than packing 8 bits to a byte and extracting.\r
- * <p>\r
- */\r
-\r
-// REVIEW: there is no range checking, so buffer underflow or overflow\r
-// can silently occur.\r
-@LATTICE("BUF<OFF,BUF<BIT,BIT*,OFF*")\r
-@METHODDEFAULT("OUT<THIS,THIS<IN,IN*,OUT*,THISLOC=THIS,RETURNLOC=OUT")\r
-final class BitReserve {\r
- /**\r
- * Size of the internal buffer to store the reserved bits. Must be a power of\r
- * 2. And x8, as each bit is stored as a single entry.\r
- */\r
- private static final int BUFSIZE = 4096 * 8;\r
-\r
- /**\r
- * Mask that can be used to quickly implement the modulus operation on\r
- * BUFSIZE.\r
- */\r
- private static final int BUFSIZE_MASK = BUFSIZE - 1;\r
-\r
- @LOC("BIT")\r
- private int offset;\r
-\r
- @LOC("BIT")\r
- public int totbit;\r
-\r
- @LOC("BIT")\r
- public int buf_byte_idx;\r
-\r
- @LOC("BIT")\r
- private final int[] buf;\r
-\r
- BitReserve() {\r
- offset = 0;\r
- totbit = 0;\r
- buf_byte_idx = 0;\r
- buf = new int[BUFSIZE];\r
- }\r
-\r
- /**\r
- * Return totbit Field.\r
- */\r
- @RETURNLOC("THIS,BitReserve.BIT")\r
- public int hsstell() {\r
- return (totbit);\r
- }\r
-\r
- /**\r
- * Read a number bits from the bit stream.\r
- * \r
- * @param N\r
- * the number of\r
- */\r
- @PCLOC("THIS,BitReserve.BIT")\r
- public int hgetbits(@LOC("THIS,BitReserve.BIT") int N) {\r
-\r
- totbit += N;\r
-\r
- @LOC("OUT") int val = 0;\r
-\r
- @LOC("THIS,BitReserve.BIT") int pos = buf_byte_idx;\r
- if (pos + N < BUFSIZE) {\r
- TERMINATE: while (N-- > 0) {\r
- val <<= 1;\r
- val |= ((buf[pos++] != 0) ? 1 : 0);\r
- }\r
- } else {\r
- TERMINATE: while (N-- > 0) {\r
- val <<= 1;\r
- val |= ((buf[pos] != 0) ? 1 : 0);\r
- pos = (pos + 1) & BUFSIZE_MASK;\r
- }\r
- }\r
-\r
- buf_byte_idx = pos;\r
-\r
- return val;\r
-\r
- }\r
-\r
- /**\r
- * Returns next bit from reserve.\r
- * \r
- * @returns 0 if next bit is reset, or 1 if next bit is set.\r
- */\r
- @RETURNLOC("THIS,BitReserve.BIT")\r
- public int hget1bit() {\r
- totbit++;\r
- @LOC("THIS,BitReserve.BIT") int val = buf[buf_byte_idx];\r
- buf_byte_idx = (buf_byte_idx + 1) & BUFSIZE_MASK;\r
- return val;\r
- }\r
-\r
- /**\r
- * Write 8 bits into the bit stream.\r
- */\r
- @LATTICE("OUT<THIS,THIS<IN,THISLOC=THIS,GLOBALLOC=IN")\r
- public void hputbuf(@LOC("IN") int val) {\r
- @LOC("THIS,BitReserve.OFF") int ofs = offset;\r
- buf[ofs++] = val & 0x80;\r
- buf[ofs++] = val & 0x40;\r
- buf[ofs++] = val & 0x20;\r
- buf[ofs++] = val & 0x10;\r
- buf[ofs++] = val & 0x08;\r
- buf[ofs++] = val & 0x04;\r
- buf[ofs++] = val & 0x02;\r
- buf[ofs++] = val & 0x01;\r
-\r
- if (ofs == BUFSIZE)\r
- offset = 0;\r
- else\r
- offset = ofs;\r
-\r
- }\r
-\r
- /**\r
- * Rewind N bits in Stream.\r
- */\r
- public void rewindNbits(@LOC("THIS,BitReserve.BIT") int N) {\r
- totbit -= N;\r
- buf_byte_idx -= N;\r
- if (buf_byte_idx < 0)\r
- buf_byte_idx += BUFSIZE;\r
- }\r
-\r
- /**\r
- * Rewind N bytes in Stream.\r
- */\r
- @LATTICE("THIS<BIT,BIT<N,THISLOC=THIS,GLOBALLOC=N")\r
- public void rewindNbytes(@LOC("N") int N) {\r
- @LOC("BIT") int bits = (N << 3);\r
- totbit -= bits;\r
- buf_byte_idx -= bits;\r
- if (buf_byte_idx < 0)\r
- buf_byte_idx += BUFSIZE;\r
- }\r
-}\r
+/*
+ * 11/19/04 1.0 moved to LGPL.
+ *
+ * 12/12/99 0.0.7 Implementation stores single bits
+ * as ints for better performance. mdm@techie.com.
+ *
+ * 02/28/99 0.0 Java Conversion by E.B, javalayer@javazoom.net
+ *
+ * Adapted from the public c code by Jeff Tsay.
+ *
+ *-----------------------------------------------------------------------
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *----------------------------------------------------------------------
+ */
+
+/**
+ * Implementation of Bit Reservoir for Layer III.
+ * <p>
+ * The implementation stores single bits as a word in the buffer. If a bit is
+ * set, the corresponding word in the buffer will be non-zero. If a bit is
+ * clear, the corresponding word is zero. Although this may seem waseful, this
+ * can be a factor of two quicker than packing 8 bits to a byte and extracting.
+ * <p>
+ */
+
+// REVIEW: there is no range checking, so buffer underflow or overflow
+// can silently occur.
+@LATTICE("BUF<OFF,BUF<BIT,BIT*,OFF*")
+@METHODDEFAULT("OUT<THIS,THIS<IN,IN*,OUT*,THISLOC=THIS,RETURNLOC=OUT")
+final class BitReserve {
+ /**
+ * Size of the internal buffer to store the reserved bits. Must be a power of
+ * 2. And x8, as each bit is stored as a single entry.
+ */
+ private static final int BUFSIZE = 4096 * 8;
+
+ /**
+ * Mask that can be used to quickly implement the modulus operation on
+ * BUFSIZE.
+ */
+ private static final int BUFSIZE_MASK = BUFSIZE - 1;
+
+ @LOC("BIT")
+ private int offset;
+
+ @LOC("BIT")
+ public int totbit;
+
+ @LOC("BIT")
+ public int buf_byte_idx;
+
+ @LOC("BIT")
+ private final int[] buf;
+
+ BitReserve() {
+ offset = 0;
+ totbit = 0;
+ buf_byte_idx = 0;
+ buf = new int[BUFSIZE];
+ }
+
+ /**
+ * Return totbit Field.
+ */
+ @RETURNLOC("THIS,BitReserve.BIT")
+ public int hsstell() {
+ return (totbit);
+ }
+
+ /**
+ * Read a number bits from the bit stream.
+ *
+ * @param N
+ * the number of
+ */
+ @PCLOC("THIS,BitReserve.BIT")
+ public int hgetbits(@LOC("THIS,BitReserve.BIT") int N) {
+
+ totbit += N;
+
+ @LOC("OUT") int val = 0;
+
+ @LOC("THIS,BitReserve.BIT") int pos = buf_byte_idx;
+ if (pos + N < BUFSIZE) {
+ TERMINATE: while (N-- > 0) {
+ val <<= 1;
+ val |= ((buf[pos++] != 0) ? 1 : 0);
+ }
+ } else {
+ TERMINATE: while (N-- > 0) {
+ val <<= 1;
+ val |= ((buf[pos] != 0) ? 1 : 0);
+ pos = (pos + 1) & BUFSIZE_MASK;
+ }
+ }
+
+ buf_byte_idx = pos;
+
+ return val;
+
+ }
+
+ /**
+ * Returns next bit from reserve.
+ *
+ * @returns 0 if next bit is reset, or 1 if next bit is set.
+ */
+ @RETURNLOC("THIS,BitReserve.BIT")
+ public int hget1bit() {
+ totbit++;
+ @LOC("THIS,BitReserve.BIT") int val = buf[buf_byte_idx];
+ buf_byte_idx = (buf_byte_idx + 1) & BUFSIZE_MASK;
+ return val;
+ }
+
+ /**
+ * Write 8 bits into the bit stream.
+ */
+ @LATTICE("OUT<THIS,THIS<IN,THISLOC=THIS,GLOBALLOC=IN")
+ public void hputbuf(@LOC("IN") int val) {
+ @LOC("THIS,BitReserve.OFF") int ofs = offset;
+ buf[ofs++] = val & 0x80;
+ buf[ofs++] = val & 0x40;
+ buf[ofs++] = val & 0x20;
+ buf[ofs++] = val & 0x10;
+ buf[ofs++] = val & 0x08;
+ buf[ofs++] = val & 0x04;
+ buf[ofs++] = val & 0x02;
+ buf[ofs++] = val & 0x01;
+
+ if (ofs == BUFSIZE)
+ offset = 0;
+ else
+ offset = ofs;
+
+ }
+
+ /**
+ * Rewind N bits in Stream.
+ */
+ public void rewindNbits(@LOC("THIS,BitReserve.BIT") int N) {
+ totbit -= N;
+ buf_byte_idx -= N;
+ if (buf_byte_idx < 0)
+ buf_byte_idx += BUFSIZE;
+ }
+
+ /**
+ * Rewind N bytes in Stream.
+ */
+ @LATTICE("THIS<BIT,BIT<N,THISLOC=THIS,GLOBALLOC=N")
+ public void rewindNbytes(@LOC("N") int N) {
+ @LOC("BIT") int bits = (N << 3);
+ totbit -= bits;
+ buf_byte_idx -= bits;
+ if (buf_byte_idx < 0)
+ buf_byte_idx += BUFSIZE;
+ }
+}