summaryrefslogtreecommitdiff
path: root/songdbj/de/jarnbjo/vorbis/Residue2.java
blob: 666d2cd017fd5f6ae069794a9aaf770ecb00f77e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
 * $ProjectName$
 * $ProjectRevision$
 * -----------------------------------------------------------
 * $Id$
 * -----------------------------------------------------------
 *
 * $Author$
 *
 * Description:
 *
 * Copyright 2002-2003 Tor-Einar Jarnbjo
 * -----------------------------------------------------------
 *
 * Change History
 * -----------------------------------------------------------
 * $Log$
 * Revision 1.1  2005/07/11 15:42:36  hcl
 * Songdb java version, source. only 1.5 compatible
 *
 * Revision 1.2  2004/09/21 06:39:06  shred
 * Importe reorganisiert, damit Eclipse Ruhe gibt. ;-)
 *
 * Revision 1.1.1.1  2004/04/04 22:09:12  shred
 * First Import
 *
 * Revision 1.2  2003/03/16 01:11:12  jarnbjo
 * no message
 *
 *
 */

package de.jarnbjo.vorbis;

import java.io.IOException;

import de.jarnbjo.util.io.BitInputStream;

class Residue2 extends Residue {

   private double[][] decodedVectors;

   private Residue2() {
   }

   protected Residue2(BitInputStream source, SetupHeader header) throws VorbisFormatException, IOException {
      super(source, header);
   }

   protected int getType() {
      return 2;
   }

   protected void decodeResidue(VorbisStream vorbis, BitInputStream source, Mode mode, int ch, boolean[] doNotDecodeFlags, float[][] vectors) throws VorbisFormatException, IOException {

      Look look=getLook(vorbis, mode);

      CodeBook codeBook=vorbis.getSetupHeader().getCodeBooks()[getClassBook()];

      int classvalsPerCodeword=codeBook.getDimensions();
      int nToRead=getEnd()-getBegin();
      int partitionsToRead=nToRead/getPartitionSize(); // partvals

      int samplesPerPartition=getPartitionSize();
      int partitionsPerWord=look.getPhraseBook().getDimensions();

      int partWords=(partitionsToRead+partitionsPerWord-1)/partitionsPerWord;

      int realCh=0;
      for(int i=0; i<doNotDecodeFlags.length; i++) {
         if(!doNotDecodeFlags[i]) {
            realCh++;
         }
      }

      float[][] realVectors=new float[realCh][];

      realCh=0;
      for(int i=0; i<doNotDecodeFlags.length; i++) {
         if(!doNotDecodeFlags[i]) {
            realVectors[realCh++]=vectors[i];
         }
      }

      int[][] partword=new int[partWords][];
      for(int s=0;s<look.getStages();s++){
         for(int i=0,l=0;i<partitionsToRead;l++){
            if(s==0){
	            //int temp=look.getPhraseBook().readInt(source);
	            int temp=source.getInt(look.getPhraseBook().getHuffmanRoot());
	            if(temp==-1){
	               throw new VorbisFormatException("");
	            }
	            partword[l]=look.getDecodeMap()[temp];
	            if(partword[l]==null){
	               throw new VorbisFormatException("");
	            }
	         }

            for(int k=0;k<partitionsPerWord && i<partitionsToRead;k++,i++){
               int offset=begin+i*samplesPerPartition;
	            if((cascade[partword[l][k]]&(1<<s))!=0){
                  CodeBook stagebook=vorbis.getSetupHeader().getCodeBooks()[look.getPartBooks()[partword[l][k]][s]];
	               if(stagebook!=null){
                     stagebook.readVvAdd(realVectors, source, offset, samplesPerPartition);
                  }
	            }
	         }
         }
      }
   }


   public Object clone() {
      Residue2 clone=new Residue2();
      fill(clone);
      return clone;
   }

   protected double[][] getDecodedVectors() {
      return decodedVectors;
   }
}