All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sourceforge.jaad.aac.huffman.Huffman Maven / Gradle / Ivy

There is a newer version: 0.2.5
Show newest version
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);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy