summaryrefslogtreecommitdiff
path: root/songdbj/de/jarnbjo/vorbis/Floor1.java
diff options
context:
space:
mode:
Diffstat (limited to 'songdbj/de/jarnbjo/vorbis/Floor1.java')
-rw-r--r--songdbj/de/jarnbjo/vorbis/Floor1.java324
1 files changed, 324 insertions, 0 deletions
diff --git a/songdbj/de/jarnbjo/vorbis/Floor1.java b/songdbj/de/jarnbjo/vorbis/Floor1.java
new file mode 100644
index 0000000000..69a118b44e
--- /dev/null
+++ b/songdbj/de/jarnbjo/vorbis/Floor1.java
@@ -0,0 +1,324 @@
1/*
2 * $ProjectName$
3 * $ProjectRevision$
4 * -----------------------------------------------------------
5 * $Id$multip
6 * -----------------------------------------------------------
7 *
8 * $Author$
9 *
10 * Description:
11 *
12 * Copyright 2002-2003 Tor-Einar Jarnbjo
13 * -----------------------------------------------------------
14 *
15 * Change History
16 * -----------------------------------------------------------
17 * $Log$
18 * Revision 1.1 2005/07/11 15:42:36 hcl
19 * Songdb java version, source. only 1.5 compatible
20 *
21 * Revision 1.1.1.1 2004/04/04 22:09:12 shred
22 * First Import
23 *
24 * Revision 1.2 2003/03/16 01:11:12 jarnbjo
25 * no message
26 *
27 *
28 */
29
30package de.jarnbjo.vorbis;
31
32import java.io.IOException;
33import java.util.*;
34
35import de.jarnbjo.util.io.BitInputStream;
36
37
38class Floor1 extends Floor implements Cloneable {
39
40 private int[] partitionClassList;
41 private int maximumClass, multiplier, rangeBits;
42 private int[] classDimensions;
43 private int[] classSubclasses;
44 private int[] classMasterbooks;
45 private int[][] subclassBooks;
46 private int[] xList;
47 private int[] yList;
48 private int[] lowNeighbours, highNeighbours;
49 //private boolean[] step2Flags;
50
51 private static final int[] RANGES = {256, 128, 86, 64};
52
53 private Floor1() {
54 }
55
56 protected Floor1(BitInputStream source, SetupHeader header) throws VorbisFormatException, IOException {
57
58 maximumClass=-1;
59 int partitions=source.getInt(5);
60 partitionClassList=new int[partitions];
61
62 for(int i=0; i<partitionClassList.length; i++) {
63 partitionClassList[i]=source.getInt(4);
64 if(partitionClassList[i]>maximumClass) {
65 maximumClass=partitionClassList[i];
66 }
67 }
68
69
70 classDimensions=new int[maximumClass+1];
71 classSubclasses=new int[maximumClass+1];
72 classMasterbooks=new int[maximumClass+1];
73 subclassBooks=new int[maximumClass+1][];
74
75 int xListLength=2;
76
77 for(int i=0; i<=maximumClass; i++) {
78 classDimensions[i]=source.getInt(3)+1;
79 xListLength+=classDimensions[i];
80 classSubclasses[i]=source.getInt(2);
81
82 if(classDimensions[i] > header.getCodeBooks().length ||
83 classSubclasses[i] > header.getCodeBooks().length) {
84 throw new VorbisFormatException("There is a class dimension or class subclasses entry higher than the number of codebooks in the setup header.");
85 }
86 if(classSubclasses[i]!=0) {
87 classMasterbooks[i]=source.getInt(8);
88 }
89 subclassBooks[i]=new int[1<<classSubclasses[i]];
90 for(int j=0; j<subclassBooks[i].length; j++) {
91 subclassBooks[i][j]=source.getInt(8)-1;
92 }
93 }
94
95 multiplier=source.getInt(2)+1;
96 rangeBits=source.getInt(4);
97
98 //System.out.println("multiplier: "+multiplier);
99 //System.out.println("rangeBits: "+rangeBits);
100
101 //System.out.println("xListLength: "+xListLength);
102
103 int floorValues=0;
104
105 ArrayList alXList=new ArrayList();
106
107 alXList.add(new Integer(0));
108 alXList.add(new Integer(1<<rangeBits));
109
110 //System.out.println("partitions: "+partitions);
111 //System.out.println("classDimensions.length: "+classDimensions.length);
112
113 for(int i=0; i<partitions; i++) {
114 for(int j=0; j<classDimensions[partitionClassList[i]]; j++) {
115 alXList.add(new Integer(source.getInt(rangeBits)));
116 }
117 }
118
119 xList=new int[alXList.size()];
120 lowNeighbours=new int[xList.length];
121 highNeighbours=new int[xList.length];
122
123 Iterator iter=alXList.iterator();
124 for(int i=0; i<xList.length; i++) {
125 xList[i]=((Integer)iter.next()).intValue();
126 }
127
128 for(int i=0; i<xList.length; i++) {
129 lowNeighbours[i]=Util.lowNeighbour(xList, i);
130 highNeighbours[i]=Util.highNeighbour(xList, i);
131 }
132 }
133
134 protected int getType() {
135 return 1;
136 }
137
138 protected Floor decodeFloor(VorbisStream vorbis, BitInputStream source) throws VorbisFormatException, IOException {
139
140 //System.out.println("decodeFloor");
141 if(!source.getBit()) {
142 //System.out.println("null");
143 return null;
144 }
145
146 Floor1 clone=(Floor1)clone();
147
148 clone.yList=new int[xList.length];
149
150 int range=RANGES[multiplier-1];
151
152 clone.yList[0]=source.getInt(Util.ilog(range-1));
153 clone.yList[1]=source.getInt(Util.ilog(range-1));
154
155 int offset=2;
156
157 for(int i=0; i<partitionClassList.length; i++) {
158 int cls=partitionClassList[i];
159 int cdim=classDimensions[cls];
160 int cbits=classSubclasses[cls];
161 int csub=(1<<cbits)-1;
162 int cval=0;
163 if(cbits>0) {
164 cval=source.getInt(vorbis.getSetupHeader().getCodeBooks()[classMasterbooks[cls]].getHuffmanRoot());
165 //cval=vorbis.getSetupHeader().getCodeBooks()[classMasterbooks[cls]].readInt(source);
166 //System.out.println("cval: "+cval);
167 }
168 //System.out.println("0: "+cls+" "+cdim+" "+cbits+" "+csub+" "+cval);
169 for(int j=0; j<cdim; j++) {
170 //System.out.println("a: "+cls+" "+cval+" "+csub);
171 int book=subclassBooks[cls][cval&csub];
172 cval>>>=cbits;
173 if(book>=0) {
174 clone.yList[j+offset]=source.getInt(vorbis.getSetupHeader().getCodeBooks()[book].getHuffmanRoot());
175 //clone.yList[j+offset]=vorbis.getSetupHeader().getCodeBooks()[book].readInt(source);
176 //System.out.println("b: "+(j+offset)+" "+book+" "+clone.yList[j+offset]);
177 //System.out.println("");
178 }
179 else {
180 clone.yList[j+offset]=0;
181 }
182 }
183 offset+=cdim;
184 }
185
186 //System.out.println("");
187 //for(int i=0; i<clone.xList.length; i++) {
188 // System.out.println(i+" = "+clone.xList[i]);
189 //}
190
191 //System.out.println("");
192 //for(int i=0; i<clone.yList.length; i++) {
193 // System.out.println(i+" = "+clone.yList[i]);
194 //}
195
196 //System.out.println("offset: "+offset);
197 //System.out.println("yList.length: "+clone.yList.length);
198
199 //System.exit(0);
200
201 return clone;
202 }
203
204 protected void computeFloor(final float[] vector) {
205
206 int n=vector.length;
207 final int values=xList.length;
208 final boolean[] step2Flags=new boolean[values];
209
210 final int range=RANGES[multiplier-1];
211
212 for(int i=2; i<values; i++) {
213 final int lowNeighbourOffset=lowNeighbours[i];//Util.lowNeighbour(xList, i);
214 final int highNeighbourOffset=highNeighbours[i];//Util.highNeighbour(xList, i);
215 final int predicted=Util.renderPoint(
216 xList[lowNeighbourOffset], xList[highNeighbourOffset],
217 yList[lowNeighbourOffset], yList[highNeighbourOffset],
218 xList[i]);
219 final int val=yList[i];
220 final int highRoom=range-predicted;
221 final int lowRoom=predicted;
222 final int room=highRoom<lowRoom?highRoom*2:lowRoom*2;
223 if(val!=0) {
224 step2Flags[lowNeighbourOffset]=true;
225 step2Flags[highNeighbourOffset]=true;
226 step2Flags[i]=true;
227 if(val>=room) {
228 yList[i]=highRoom>lowRoom?
229 val-lowRoom+predicted:
230 -val+highRoom+predicted-1;
231 }
232 else {
233 yList[i]=(val&1)==1?
234 predicted-((val+1)>>1):
235 predicted+(val>>1);
236 }
237 }
238 else {
239 step2Flags[i]=false;
240 yList[i]=predicted;
241 }
242 }
243
244 final int[] xList2=new int[values];
245
246 System.arraycopy(xList, 0, xList2, 0, values);
247 sort(xList2, yList, step2Flags);
248
249 int hx=0, hy=0, lx=0, ly=yList[0]*multiplier;
250
251 float[] vector2=new float[vector.length];
252 float[] vector3=new float[vector.length];
253 Arrays.fill(vector2, 1.0f);
254 System.arraycopy(vector, 0, vector3, 0, vector.length);
255
256 for(int i=1; i<values; i++) {
257 if(step2Flags[i]) {
258 hy=yList[i]*multiplier;
259 hx=xList2[i];
260 Util.renderLine(lx, ly, hx, hy, vector);
261 Util.renderLine(lx, ly, hx, hy, vector2);
262 lx=hx;
263 ly=hy;
264 }
265 }
266
267 final float r=DB_STATIC_TABLE[hy];
268 for(; hx<n/2; vector[hx++]=r);
269 }
270
271 public Object clone() {
272 Floor1 clone=new Floor1();
273 clone.classDimensions=classDimensions;
274 clone.classMasterbooks=classMasterbooks;
275 clone.classSubclasses=classSubclasses;
276 clone.maximumClass=maximumClass;
277 clone.multiplier=multiplier;
278 clone.partitionClassList=partitionClassList;
279 clone.rangeBits=rangeBits;
280 clone.subclassBooks=subclassBooks;
281 clone.xList=xList;
282 clone.yList=yList;
283 clone.lowNeighbours=lowNeighbours;
284 clone.highNeighbours=highNeighbours;
285 return clone;
286 }
287
288 private final static void sort(int x[], int y[], boolean b[]) {
289 int off=0;
290 int len=x.length;
291 int lim=len+off;
292 int itmp;
293 boolean btmp;
294 // Insertion sort on smallest arrays
295 for (int i=off; i<lim; i++) {
296 for (int j=i; j>off && x[j-1]>x[j]; j--) {
297 itmp=x[j];
298 x[j]=x[j-1];
299 x[j-1]=itmp;
300 itmp=y[j];
301 y[j]=y[j-1];
302 y[j-1]=itmp;
303 btmp=b[j];
304 b[j]=b[j-1];
305 b[j-1]=btmp;
306 //swap(x, j, j-1);
307 //swap(y, j, j-1);
308 //swap(b, j, j-1);
309 }
310 }
311 }
312
313 private final static void swap(int x[], int a, int b) {
314 int t = x[a];
315 x[a] = x[b];
316 x[b] = t;
317 }
318
319 private final static void swap(boolean x[], int a, int b) {
320 boolean t = x[a];
321 x[a] = x[b];
322 x[b] = t;
323 }
324} \ No newline at end of file