summaryrefslogtreecommitdiff
path: root/songdbj/de/jarnbjo/vorbis/Residue.java
diff options
context:
space:
mode:
Diffstat (limited to 'songdbj/de/jarnbjo/vorbis/Residue.java')
-rw-r--r--songdbj/de/jarnbjo/vorbis/Residue.java260
1 files changed, 0 insertions, 260 deletions
diff --git a/songdbj/de/jarnbjo/vorbis/Residue.java b/songdbj/de/jarnbjo/vorbis/Residue.java
deleted file mode 100644
index 78c28fa5ed..0000000000
--- a/songdbj/de/jarnbjo/vorbis/Residue.java
+++ /dev/null
@@ -1,260 +0,0 @@
1/*
2 * $ProjectName$
3 * $ProjectRevision$
4 * -----------------------------------------------------------
5 * $Id$
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.3 2003/04/04 08:33:02 jarnbjo
25 * no message
26 *
27 * Revision 1.2 2003/03/16 01:11:12 jarnbjo
28 * no message
29 *
30 *
31 */
32
33package de.jarnbjo.vorbis;
34
35import java.io.IOException;
36import java.util.HashMap;
37
38import de.jarnbjo.util.io.*;
39
40
41abstract class Residue {
42
43 protected int begin, end;
44 protected int partitionSize; // grouping
45 protected int classifications; // partitions
46 protected int classBook; // groupbook
47 protected int[] cascade; // secondstages
48 protected int[][] books;
49 protected HashMap looks=new HashMap();
50
51 protected Residue() {
52 }
53
54 protected Residue(BitInputStream source, SetupHeader header) throws VorbisFormatException, IOException {
55 begin=source.getInt(24);
56 end=source.getInt(24);
57 partitionSize=source.getInt(24)+1;
58 classifications=source.getInt(6)+1;
59 classBook=source.getInt(8);
60
61 cascade=new int[classifications];
62
63 int acc=0;
64
65 for(int i=0; i<classifications; i++) {
66 int highBits=0, lowBits=0;
67 lowBits=source.getInt(3);
68 if(source.getBit()) {
69 highBits=source.getInt(5);
70 }
71 cascade[i]=(highBits<<3)|lowBits;
72 acc+=Util.icount(cascade[i]);
73 }
74
75 books=new int[classifications][8];
76
77 for(int i=0; i<classifications; i++) {
78 for(int j=0; j<8; j++) {
79 if((cascade[i]&(1<<j))!=0) {
80 books[i][j]=source.getInt(8);
81 if(books[i][j]>header.getCodeBooks().length) {
82 throw new VorbisFormatException("Reference to invalid codebook entry in residue header.");
83 }
84 }
85 }
86 }
87 }
88
89
90 protected static Residue createInstance(BitInputStream source, SetupHeader header) throws VorbisFormatException, IOException {
91
92 int type=source.getInt(16);
93 switch(type) {
94 case 0:
95 //System.out.println("residue type 0");
96 return new Residue0(source, header);
97 case 1:
98 //System.out.println("residue type 1");
99 return new Residue2(source, header);
100 case 2:
101 //System.out.println("residue type 2");
102 return new Residue2(source, header);
103 default:
104 throw new VorbisFormatException("Residue type "+type+" is not supported.");
105 }
106 }
107
108 protected abstract int getType();
109 protected abstract void decodeResidue(VorbisStream vorbis, BitInputStream source, Mode mode, int ch, boolean[] doNotDecodeFlags, float[][] vectors) throws VorbisFormatException, IOException;
110 //public abstract double[][] getDecodedVectors();
111
112 protected int getBegin() {
113 return begin;
114 }
115
116 protected int getEnd() {
117 return end;
118 }
119
120 protected int getPartitionSize() {
121 return partitionSize;
122 }
123
124 protected int getClassifications() {
125 return classifications;
126 }
127
128 protected int getClassBook() {
129 return classBook;
130 }
131
132 protected int[] getCascade() {
133 return cascade;
134 }
135
136 protected int[][] getBooks() {
137 return books;
138 }
139
140 protected final void fill(Residue clone) {
141 clone.begin=begin;
142 clone.books=books;
143 clone.cascade=cascade;
144 clone.classBook=classBook;
145 clone.classifications=classifications;
146 clone.end=end;
147 clone.partitionSize=partitionSize;
148 }
149
150 protected Look getLook(VorbisStream source, Mode key) {
151 //return new Look(source, key);
152 Look look=(Look)looks.get(key);
153 if(look==null) {
154 look=new Look(source, key);
155 looks.put(key, look);
156 }
157 return look;
158 }
159
160
161 class Look {
162 int map;
163 int parts;
164 int stages;
165 CodeBook[] fullbooks;
166 CodeBook phrasebook;
167 int[][] partbooks;
168 int partvals;
169 int[][] decodemap;
170 int postbits;
171 int phrasebits;
172 int frames;
173
174 protected Look (VorbisStream source, Mode mode) {
175 int dim=0, acc=0, maxstage=0;
176
177 map=mode.getMapping();
178 parts=Residue.this.getClassifications();
179 fullbooks=source.getSetupHeader().getCodeBooks();
180 phrasebook=fullbooks[Residue.this.getClassBook()];
181 dim=phrasebook.getDimensions();
182
183 partbooks=new int[parts][];
184
185 for(int j=0;j<parts;j++) {
186 int stages=Util.ilog(Residue.this.getCascade()[j]);
187 if(stages!=0) {
188 if(stages>maxstage) {
189 maxstage=stages;
190 }
191 partbooks[j]=new int[stages];
192 for(int k=0; k<stages; k++){
193 if((Residue.this.getCascade()[j]&(1<<k))!=0){
194 partbooks[j][k]=Residue.this.getBooks()[j][k];
195 }
196 }
197 }
198 }
199
200 partvals=(int)Math.rint(Math.pow(parts, dim));
201 stages=maxstage;
202
203 decodemap=new int[partvals][];
204
205 for(int j=0;j<partvals;j++){
206 int val=j;
207 int mult=partvals/parts;
208 decodemap[j]=new int[dim];
209
210 for(int k=0;k<dim;k++){
211 int deco=val/mult;
212 val-=deco*mult;
213 mult/=parts;
214 decodemap[j][k]=deco;
215 }
216 }
217 }
218
219 protected int[][] getDecodeMap() {
220 return decodemap;
221 }
222
223 protected int getFrames() {
224 return frames;
225 }
226
227 protected int getMap() {
228 return map;
229 }
230
231 protected int[][] getPartBooks() {
232 return partbooks;
233 }
234
235 protected int getParts() {
236 return parts;
237 }
238
239 protected int getPartVals() {
240 return partvals;
241 }
242
243 protected int getPhraseBits() {
244 return phrasebits;
245 }
246
247 protected CodeBook getPhraseBook() {
248 return phrasebook;
249 }
250
251 protected int getPostBits() {
252 return postbits;
253 }
254
255 protected int getStages() {
256 return stages;
257 }
258 }
259
260} \ No newline at end of file