/* * $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.3 2003/04/10 19:49:04 jarnbjo * no message * * Revision 1.2 2003/03/16 01:11:12 jarnbjo * no message * * */ package de.jarnbjo.vorbis; import java.io.IOException; import java.util.Arrays; import de.jarnbjo.util.io.BitInputStream; import de.jarnbjo.util.io.HuffmanNode; class CodeBook { private HuffmanNode huffmanRoot; private int dimensions, entries; private int[] entryLengths; private float[][] valueVector; protected CodeBook(BitInputStream source) throws VorbisFormatException, IOException { // check sync if(source.getInt(24)!=0x564342) { throw new VorbisFormatException("The code book sync pattern is not correct."); } dimensions=source.getInt(16); entries=source.getInt(24); entryLengths=new int[entries]; boolean ordered=source.getBit(); if(ordered) { int cl=source.getInt(5)+1; for(int i=0; ientryLengths.length) { throw new VorbisFormatException("The codebook entry length list is longer than the actual number of entry lengths."); } Arrays.fill(entryLengths, i, i+num, cl); cl++; i+=num; } } else { // !ordered boolean sparse=source.getBit(); if(sparse) { for(int i=0; i0) { if(!huffmanRoot.setNewValue(el, i)) { return false; } } } return true; } protected int getDimensions() { return dimensions; } protected int getEntries() { return entries; } protected HuffmanNode getHuffmanRoot() { return huffmanRoot; } //public float[] readVQ(ReadableBitChannel source) throws IOException { // return valueVector[readInt(source)]; //} protected int readInt(final BitInputStream source) throws IOException { return source.getInt(huffmanRoot); /* HuffmanNode node; for(node=huffmanRoot; node.value==null; node=source.getBit()?node.o1:node.o0); return node.value.intValue(); */ } protected void readVvAdd(float[][] a, BitInputStream source, int offset, int length) throws VorbisFormatException, IOException { int i,j;//k;//entry; int chptr=0; int ch=a.length; if(ch==0) { return; } int lim=(offset+length)/ch; for(i=offset/ch;i8){ for(i=0;i