diff options
Diffstat (limited to 'songdbj/javazoom/jl/decoder/BitReserve.java')
-rw-r--r-- | songdbj/javazoom/jl/decoder/BitReserve.java | 223 |
1 files changed, 0 insertions, 223 deletions
diff --git a/songdbj/javazoom/jl/decoder/BitReserve.java b/songdbj/javazoom/jl/decoder/BitReserve.java deleted file mode 100644 index a5d3056d61..0000000000 --- a/songdbj/javazoom/jl/decoder/BitReserve.java +++ /dev/null | |||
@@ -1,223 +0,0 @@ | |||
1 | /* | ||
2 | * 11/19/04 1.0 moved to LGPL. | ||
3 | * | ||
4 | * 12/12/99 0.0.7 Implementation stores single bits | ||
5 | * as ints for better performance. mdm@techie.com. | ||
6 | * | ||
7 | * 02/28/99 0.0 Java Conversion by E.B, javalayer@javazoom.net | ||
8 | * | ||
9 | * Adapted from the public c code by Jeff Tsay. | ||
10 | * | ||
11 | *----------------------------------------------------------------------- | ||
12 | * This program is free software; you can redistribute it and/or modify | ||
13 | * it under the terms of the GNU Library General Public License as published | ||
14 | * by the Free Software Foundation; either version 2 of the License, or | ||
15 | * (at your option) any later version. | ||
16 | * | ||
17 | * This program is distributed in the hope that it will be useful, | ||
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | * GNU Library General Public License for more details. | ||
21 | * | ||
22 | * You should have received a copy of the GNU Library General Public | ||
23 | * License along with this program; if not, write to the Free Software | ||
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
25 | *---------------------------------------------------------------------- | ||
26 | */ | ||
27 | |||
28 | package javazoom.jl.decoder; | ||
29 | |||
30 | /** | ||
31 | * Implementation of Bit Reservoir for Layer III. | ||
32 | * <p> | ||
33 | * The implementation stores single bits as a word in the buffer. If | ||
34 | * a bit is set, the corresponding word in the buffer will be non-zero. | ||
35 | * If a bit is clear, the corresponding word is zero. Although this | ||
36 | * may seem waseful, this can be a factor of two quicker than | ||
37 | * packing 8 bits to a byte and extracting. | ||
38 | * <p> | ||
39 | */ | ||
40 | |||
41 | // REVIEW: there is no range checking, so buffer underflow or overflow | ||
42 | // can silently occur. | ||
43 | final class BitReserve | ||
44 | { | ||
45 | /** | ||
46 | * Size of the internal buffer to store the reserved bits. | ||
47 | * Must be a power of 2. And x8, as each bit is stored as a single | ||
48 | * entry. | ||
49 | */ | ||
50 | private static final int BUFSIZE = 4096*8; | ||
51 | |||
52 | /** | ||
53 | * Mask that can be used to quickly implement the | ||
54 | * modulus operation on BUFSIZE. | ||
55 | */ | ||
56 | private static final int BUFSIZE_MASK = BUFSIZE-1; | ||
57 | |||
58 | private int offset, totbit, buf_byte_idx; | ||
59 | private final int[] buf = new int[BUFSIZE]; | ||
60 | private int buf_bit_idx; | ||
61 | |||
62 | BitReserve() | ||
63 | { | ||
64 | |||
65 | offset = 0; | ||
66 | totbit = 0; | ||
67 | buf_byte_idx = 0; | ||
68 | } | ||
69 | |||
70 | |||
71 | /** | ||
72 | * Return totbit Field. | ||
73 | */ | ||
74 | public int hsstell() | ||
75 | { | ||
76 | return(totbit); | ||
77 | } | ||
78 | |||
79 | /** | ||
80 | * Read a number bits from the bit stream. | ||
81 | * @param N the number of | ||
82 | */ | ||
83 | public int hgetbits(int N) | ||
84 | { | ||
85 | totbit += N; | ||
86 | |||
87 | int val = 0; | ||
88 | |||
89 | int pos = buf_byte_idx; | ||
90 | if (pos+N < BUFSIZE) | ||
91 | { | ||
92 | while (N-- > 0) | ||
93 | { | ||
94 | val <<= 1; | ||
95 | val |= ((buf[pos++]!=0) ? 1 : 0); | ||
96 | } | ||
97 | } | ||
98 | else | ||
99 | { | ||
100 | while (N-- > 0) | ||
101 | { | ||
102 | val <<= 1; | ||
103 | val |= ((buf[pos]!=0) ? 1 : 0); | ||
104 | pos = (pos+1) & BUFSIZE_MASK; | ||
105 | } | ||
106 | } | ||
107 | buf_byte_idx = pos; | ||
108 | return val; | ||
109 | } | ||
110 | |||
111 | |||
112 | |||
113 | /** | ||
114 | * Read 1 bit from the bit stream. | ||
115 | */ | ||
116 | /* | ||
117 | public int hget1bit_old() | ||
118 | { | ||
119 | int val; | ||
120 | totbit++; | ||
121 | if (buf_bit_idx == 0) | ||
122 | { | ||
123 | buf_bit_idx = 8; | ||
124 | buf_byte_idx++; | ||
125 | } | ||
126 | // BUFSIZE = 4096 = 2^12, so | ||
127 | // buf_byte_idx%BUFSIZE == buf_byte_idx & 0xfff | ||
128 | val = buf[buf_byte_idx & BUFSIZE_MASK] & putmask[buf_bit_idx]; | ||
129 | buf_bit_idx--; | ||
130 | val = val >>> buf_bit_idx; | ||
131 | return val; | ||
132 | } | ||
133 | */ | ||
134 | /** | ||
135 | * Returns next bit from reserve. | ||
136 | * @returns 0 if next bit is reset, or 1 if next bit is set. | ||
137 | */ | ||
138 | public int hget1bit() | ||
139 | { | ||
140 | totbit++; | ||
141 | int val = buf[buf_byte_idx]; | ||
142 | buf_byte_idx = (buf_byte_idx+1) & BUFSIZE_MASK; | ||
143 | return val; | ||
144 | } | ||
145 | |||
146 | /** | ||
147 | * Retrieves bits from the reserve. | ||
148 | */ | ||
149 | /* | ||
150 | public int readBits(int[] out, int len) | ||
151 | { | ||
152 | if (buf_bit_idx == 0) | ||
153 | { | ||
154 | buf_bit_idx = 8; | ||
155 | buf_byte_idx++; | ||
156 | current = buf[buf_byte_idx & BUFSIZE_MASK]; | ||
157 | } | ||
158 | |||
159 | |||
160 | |||
161 | // save total number of bits returned | ||
162 | len = buf_bit_idx; | ||
163 | buf_bit_idx = 0; | ||
164 | |||
165 | int b = current; | ||
166 | int count = len-1; | ||
167 | |||
168 | while (count >= 0) | ||
169 | { | ||
170 | out[count--] = (b & 0x1); | ||
171 | b >>>= 1; | ||
172 | } | ||
173 | |||
174 | totbit += len; | ||
175 | return len; | ||
176 | } | ||
177 | */ | ||
178 | |||
179 | /** | ||
180 | * Write 8 bits into the bit stream. | ||
181 | */ | ||
182 | public void hputbuf(int val) | ||
183 | { | ||
184 | int ofs = offset; | ||
185 | buf[ofs++] = val & 0x80; | ||
186 | buf[ofs++] = val & 0x40; | ||
187 | buf[ofs++] = val & 0x20; | ||
188 | buf[ofs++] = val & 0x10; | ||
189 | buf[ofs++] = val & 0x08; | ||
190 | buf[ofs++] = val & 0x04; | ||
191 | buf[ofs++] = val & 0x02; | ||
192 | buf[ofs++] = val & 0x01; | ||
193 | |||
194 | if (ofs==BUFSIZE) | ||
195 | offset = 0; | ||
196 | else | ||
197 | offset = ofs; | ||
198 | |||
199 | } | ||
200 | |||
201 | /** | ||
202 | * Rewind N bits in Stream. | ||
203 | */ | ||
204 | public void rewindNbits(int N) | ||
205 | { | ||
206 | totbit -= N; | ||
207 | buf_byte_idx -= N; | ||
208 | if (buf_byte_idx<0) | ||
209 | buf_byte_idx += BUFSIZE; | ||
210 | } | ||
211 | |||
212 | /** | ||
213 | * Rewind N bytes in Stream. | ||
214 | */ | ||
215 | public void rewindNbytes(int N) | ||
216 | { | ||
217 | int bits = (N << 3); | ||
218 | totbit -= bits; | ||
219 | buf_byte_idx -= bits; | ||
220 | if (buf_byte_idx<0) | ||
221 | buf_byte_idx += BUFSIZE; | ||
222 | } | ||
223 | } | ||