net.sourceforge.jaad.aac.gain.GainControl 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.gain;
import static java.lang.System.arraycopy;
import org.jcodec.platform.Platform;
import net.sourceforge.jaad.aac.AACException;
import net.sourceforge.jaad.aac.syntax.IBitStream;
import net.sourceforge.jaad.aac.syntax.ICSInfo.WindowSequence;
/**
* 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
*/
public class GainControl implements GCConstants {
private final int frameLen, lbLong, lbShort;
private final IMDCT imdct;
private final IPQF ipqf;
private final float[] buffer1, _function;
private final float[][] buffer2, overlap;
private int maxBand;
private int[][][] level, levelPrev;
private int[][][] location, locationPrev;
public GainControl(int frameLen) {
this.frameLen = frameLen;
lbLong = frameLen/BANDS;
lbShort = lbLong/8;
imdct = new IMDCT(frameLen);
ipqf = new IPQF();
levelPrev = new int[0][][];
locationPrev = new int[0][][];
buffer1 = new float[frameLen/2];
buffer2 = new float[BANDS][lbLong];
_function = new float[lbLong*2];
overlap = new float[BANDS][lbLong*2];
}
public void decode(IBitStream _in, WindowSequence winSeq) throws AACException {
maxBand = _in.readBits(2)+1;
int wdLen, locBits, locBits2 = 0;
switch(winSeq) {
case ONLY_LONG_SEQUENCE:
wdLen = 1;
locBits = 5;
locBits2 = 5;
break;
case EIGHT_SHORT_SEQUENCE:
wdLen = 8;
locBits = 2;
locBits2 = 2;
break;
case LONG_START_SEQUENCE:
wdLen = 2;
locBits = 4;
locBits2 = 2;
break;
case LONG_STOP_SEQUENCE:
wdLen = 2;
locBits = 4;
locBits2 = 5;
break;
default:
return;
}
level = new int[maxBand][wdLen][];
location = new int[maxBand][wdLen][];
int wd, k, len, bits;
for(int bd = 1; bd=loc[m[i]])&&(i<=loc[m[i]]+7)) fmd[i] = interpolateGain(lev[m[i]], lev[m[i]+1], i-loc[m[i]]);
else fmd[i] = lev[m[i]+1];
}
return secLevel;
}
/**
* transformes the exponent value of the gain to the id of the gain change
* point
*/
private int getGainChangePointID(int lngain) {
for(int i = 0; i