
sound.jarnbjo.vorbis.CodeBook Maven / Gradle / Ivy
/*
* $ProjectName$
* $ProjectRevision$
* -----------------------------------------------------------
* $Id: CodeBook.java,v 1.3 2003/04/10 19:49:04 jarnbjo Exp $
* -----------------------------------------------------------
*
* $Author: jarnbjo $
*
* Description:
*
* Copyright 2002-2003 Tor-Einar Jarnbjo
* -----------------------------------------------------------
*
* Change History
* -----------------------------------------------------------
* $Log: CodeBook.java,v $
* 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 sound.jarnbjo.vorbis;
import java.io.IOException;
import java.util.Arrays;
import sound.jarnbjo.util.io.BitInputStream;
import sound.jarnbjo.util.io.HuffmanNode;
public 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
© 2015 - 2025 Weber Informatics LLC | Privacy Policy