net.sourceforge.jaad.aac.huffman.Huffman Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jcodec Show documentation
Show all versions of jcodec Show documentation
Pure Java implementation of video/audio codecs and formats
package net.sourceforge.jaad.aac.huffman;
import net.sourceforge.jaad.aac.AACException;
import net.sourceforge.jaad.aac.syntax.IBitStream;
/**
* This class is part of JAAD ( jaadec.sourceforge.net ) that is distributed
* under the Public Domain license. Code changes provided by the JCodec project
* are distributed under FreeBSD license.
*
* @author in-somnia
*/
//TODO: implement decodeSpectralDataER
public class Huffman implements Codebooks {
private static final boolean[] UNSIGNED = {false, false, true, true, false, false, true, true, true, true, true};
private static final int QUAD_LEN = 4, PAIR_LEN = 2;
private Huffman() {
}
private static int findOffset(IBitStream _in, int[][] table) throws AACException {
int off = 0;
int len = table[off][0];
int cw = _in.readBits(len);
int j;
while(cw!=table[off][1]) {
off++;
j = table[off][0]-len;
len = table[off][0];
cw <<= j;
cw |= _in.readBits(j);
}
return off;
}
private static void signValues(IBitStream _in, int[] data, int off, int len) throws AACException {
for(int i = off; i15) {
signValues(_in, data, off, cb<5 ? QUAD_LEN : PAIR_LEN); //virtual codebooks are always unsigned
if(Math.abs(data[off])==16) data[off] = getEscape(_in, data[off]);
if(Math.abs(data[off+1])==16) data[off+1] = getEscape(_in, data[off+1]);
}
else throw new AACException("Huffman: unknown spectral codebook: "+cb);
}
}