net.sourceforge.jaad.aac.sbr.HFGeneration 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.sbr;
/**
* 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
*/
class HFGeneration {
private static final int[] goalSbTab = {21, 23, 32, 43, 46, 64, 85, 93, 128, 0, 0, 0};
private static class acorr_coef {
float[] r01;
float[] r02;
float[] r11;
float[] r12;
float[] r22;
float det;
public acorr_coef() {
this.r01 = new float[2];
this.r02 = new float[2];
this.r11 = new float[2];
this.r12 = new float[2];
this.r22 = new float[2];
}
}
public static void hf_generation(SBR sbr, float[][][] Xlow,
float[][][] Xhigh, int ch) {
int l, i, x;
float[][] alpha_0 = new float[64][2], alpha_1 = new float[64][2];
int offset = sbr.tHFAdj;
int first = sbr.t_E[ch][0];
int last = sbr.t_E[ch][sbr.L_E[ch]];
calc_chirp_factors(sbr, ch);
if((ch==0)&&(sbr.Reset))
patch_construction(sbr);
/* calculate the prediction coefficients */
/* actual HF generation */
for(i = 0; i0) {
float temp1_r, temp2_r, temp3_r;
float temp1_i, temp2_i, temp3_i;
calc_prediction_coef(sbr, Xlow, alpha_0, alpha_1, p);
a0_r = (alpha_0[p][0]*bw);
a1_r = (alpha_1[p][0]*bw2);
a0_i = (alpha_0[p][1]*bw);
a1_i = (alpha_1[p][1]*bw2);
temp2_r = (Xlow[first-2+offset][p][0]);
temp3_r = (Xlow[first-1+offset][p][0]);
temp2_i = (Xlow[first-2+offset][p][1]);
temp3_i = (Xlow[first-1+offset][p][1]);
for(l = first; l=16.0f)
||((alpha_1[k][0]*alpha_1[k][0])+(alpha_1[k][1]*alpha_1[k][1])>=16.0f)) {
alpha_0[k][0] = 0;
alpha_0[k][1] = 0;
alpha_1[k][0] = 0;
alpha_1[k][1] = 0;
}
}
/* FIXED POINT: bwArray = COEF */
private static float mapNewBw(int invf_mode, int invf_mode_prev) {
switch(invf_mode) {
case 1: /* LOW */
if(invf_mode_prev==0) /* NONE */
return 0.6f;
else
return 0.75f;
case 2: /* MID */
return 0.9f;
case 3: /* HIGH */
return 0.98f;
default: /* NONE */
if(invf_mode_prev==1) /* LOW */
return 0.6f;
else
return 0.0f;
}
}
/* FIXED POINT: bwArray = COEF */
private static void calc_chirp_factors(SBR sbr, int ch) {
int i;
for(i = 0; i=0.99609375f)
sbr.bwArray[ch][i] = 0.99609375f;
sbr.bwArray_prev[ch][i] = sbr.bwArray[ch][i];
sbr.bs_invf_mode_prev[ch][i] = sbr.bs_invf_mode[ch][i];
}
}
private static void patch_construction(SBR sbr) {
int i, k;
int odd, sb;
int msb = sbr.k0;
int usb = sbr.kx;
/* (uint8_t)(2.048e6/sbr.sample_rate + 0.5); */
int goalSb = goalSbTab[sbr.sample_rate.getIndex()];
sbr.noPatches = 0;
if(goalSb<(sbr.kx+sbr.M)) {
for(i = 0, k = 0; sbr.f_master[i](sbr.k0-1+msb-odd));
sbr.patchNoSubbands[sbr.noPatches] = Math.max(sb-usb, 0);
sbr.patchStartSubband[sbr.noPatches] = sbr.k0-odd
-sbr.patchNoSubbands[sbr.noPatches];
if(sbr.patchNoSubbands[sbr.noPatches]>0) {
usb = sb;
msb = sb;
sbr.noPatches++;
}
else {
msb = sbr.kx;
}
if(sbr.f_master[k]-sb<3)
k = sbr.N_master;
}
while(sb!=(sbr.kx+sbr.M));
if((sbr.patchNoSubbands[sbr.noPatches-1]<3)&&(sbr.noPatches>1)) {
sbr.noPatches--;
}
sbr.noPatches = Math.min(sbr.noPatches, 5);
}
}