📄 ilbc_encoder.java
字号:
void SimpleAnalysis(
float lsf[], /* (o) lsf coefficients */
float data[]) /* (i) new data vector */
{
int k, is;
float [] temp = new float[ilbc_constants.BLOCKL_MAX];
float [] lp = new float[ilbc_constants.LPC_FILTERORDER + 1];
float [] lp2 = new float[ilbc_constants.LPC_FILTERORDER + 1];
float [] r = new float[ilbc_constants.LPC_FILTERORDER + 1];
is=ilbc_constants.LPC_LOOKBACK+ilbc_constants.BLOCKL_MAX-this.ULP_inst.blockl;
// System.out.println("copie 1");
// System.out.println("\nInformations de copie : \nbuffer source : " + data.length + " octets\n"+
// "buffer cible : " + this.lpc_buffer.length + "octets\n" +
// " offset : " + is + "octets\n" +
// "longueur de la copie : " + this.ULP_inst.blockl);
System.arraycopy(data, 0, this.lpc_buffer, is, this.ULP_inst.blockl);
// memcpy(iLBCenc_inst->lpc_buffer+is,data,iLBCenc_inst->blockl*sizeof(float));
/* No lookahead, last window is asymmetric */
for (k = 0; k < this.ULP_inst.lpc_n; k++) {
is = ilbc_constants.LPC_LOOKBACK;
if (k < (this.ULP_inst.lpc_n - 1)) {
window(temp, ilbc_constants.lpc_winTbl, this.lpc_buffer, 0,
ilbc_constants.BLOCKL_MAX);
} else {
window(temp, ilbc_constants.lpc_asymwinTbl,
this.lpc_buffer, is, ilbc_constants.BLOCKL_MAX);
}
autocorr(r, temp, ilbc_constants.BLOCKL_MAX, ilbc_constants.LPC_FILTERORDER);
window(r, r, ilbc_constants.lpc_lagwinTbl, 0, ilbc_constants.LPC_FILTERORDER + 1);
levdurb(lp, temp, r, ilbc_constants.LPC_FILTERORDER);
ilbc_common.bwexpand(lp2, 0, lp, ilbc_constants.LPC_CHIRP_SYNTDENUM,
ilbc_constants.LPC_FILTERORDER+1);
a2lsf(lsf, k * ilbc_constants.LPC_FILTERORDER, lp2);
}
is=ilbc_constants.LPC_LOOKBACK+ilbc_constants.BLOCKL_MAX-this.ULP_inst.blockl;
// System.out.println("copie 2");
System.arraycopy(this.lpc_buffer, ilbc_constants.LPC_LOOKBACK + ilbc_constants.BLOCKL_MAX - is,
this.lpc_buffer, 0, is);
// memmove(iLBCenc_inst->lpc_buffer,
// iLBCenc_inst->lpc_buffer+LPC_LOOKBACK+BLOCKL_MAX-is,
// is*sizeof(float));
}
/*----------------------------------------------------------------*
* lsf interpolator and conversion from lsf to a coefficients
* (subrutine to SimpleInterpolateLSF)
*---------------------------------------------------------------*/
void LSFinterpolate2a_enc(
float a[], /* (o) lpc coefficients */
float lsf1[],/* (i) first set of lsf coefficients */
float lsf2[],/* (i) second set of lsf coefficients */
int lsf2_idx,
float coef, /* (i) weighting coefficient to use between
lsf1 and lsf2 */
long length /* (i) length of coefficient vectors */
){
float [] lsftmp = new float[ilbc_constants.LPC_FILTERORDER];
ilbc_common.interpolate(lsftmp, lsf1, lsf2, lsf2_idx, coef, ((int)length));
ilbc_common.lsf2a(a, lsftmp);
}
/*----------------------------------------------------------------*
* lsf interpolator (subrutine to LPCencode)
*---------------------------------------------------------------*/
void SimpleInterpolateLSF(
float syntdenum[], /* (o) the synthesis filter denominator
resulting from the quantized
interpolated lsf */
float weightdenum[], /* (o) the weighting filter denominator
resulting from the unquantized
interpolated lsf */
float lsf[], /* (i) the unquantized lsf coefficients */
float lsfdeq[], /* (i) the dequantized lsf coefficients */
float lsfold[], /* (i) the unquantized lsf coefficients of
the previous signal frame */
float lsfdeqold[], /* (i) the dequantized lsf coefficients of
the previous signal frame */
int length) /* (i) should equate LPC_FILTERORDER */
{
int i, pos, lp_length;
float [] lp = new float[ilbc_constants.LPC_FILTERORDER + 1];
int lsf2, lsfdeq2;
lsf2 = length;
lsfdeq2 = length;
// lsf2 = lsf + length;
// lsfdeq2 = lsfdeq + length;
lp_length = length + 1;
if (this.ULP_inst.mode==30) {
/* sub-frame 1: Interpolation between old and first
set of lsf coefficients */
LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq, 0,
ilbc_constants.lsf_weightTbl_30ms[0], length);
System.arraycopy(lp, 0, syntdenum, 0, lp_length);
// memcpy(syntdenum,lp,lp_length*sizeof(float));
LSFinterpolate2a_enc(lp, lsfold, lsf, 0,
ilbc_constants.lsf_weightTbl_30ms[0], length);
ilbc_common.bwexpand(weightdenum, 0, lp,
ilbc_constants.LPC_CHIRP_WEIGHTDENUM,
lp_length);
/* sub-frame 2 to 6: Interpolation between first
and second set of lsf coefficients */
pos = lp_length;
for (i = 1; i < this.ULP_inst.nsub; i++) {
LSFinterpolate2a_enc(lp, lsfdeq, lsfdeq, lsfdeq2,
ilbc_constants.lsf_weightTbl_30ms[i], length);
System.arraycopy(lp, 0, syntdenum, pos, lp_length);
// memcpy(syntdenum + pos,lp,lp_length*sizeof(float));
LSFinterpolate2a_enc(lp, lsf, lsf, lsf2,
ilbc_constants.lsf_weightTbl_30ms[i], length);
ilbc_common.bwexpand(weightdenum, pos, lp,
ilbc_constants.LPC_CHIRP_WEIGHTDENUM, lp_length);
pos += lp_length;
}
}
else {
pos = 0;
for (i = 0; i < this.ULP_inst.nsub; i++) {
//System.out.println("ici ?");
LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq, 0,
ilbc_constants.lsf_weightTbl_20ms[i], length);
//System.out.println("ici !");
System.arraycopy(lp, 0, syntdenum, pos, lp_length);
for (int li = 0; li < lp_length; li++)
//System.out.println("interpolate syntdenum [" + (li+pos) +"] is worth " + syntdenum[li+pos]);
// memcpy(syntdenum+pos,lp,lp_length*sizeof(float));
LSFinterpolate2a_enc(lp, lsfold, lsf, 0,
ilbc_constants.lsf_weightTbl_20ms[i], length);
ilbc_common.bwexpand(weightdenum, pos, lp,
ilbc_constants.LPC_CHIRP_WEIGHTDENUM, lp_length);
pos += lp_length;
}
}
/* update memory */
if (this.ULP_inst.mode==30) {
System.arraycopy(lsf, lsf2, lsfold, 0, length);
// memcpy(lsfold, lsf2, length*sizeof(float));
System.arraycopy(lsfdeq, lsfdeq2, lsfdeqold, 0, length);
// memcpy(lsfdeqold, lsfdeq2, length*sizeof(float));
}
else {
System.arraycopy(lsf, 0, lsfold, 0, length);
// memcpy(lsfold, lsf, length*sizeof(float));
System.arraycopy(lsfdeq, 0, lsfdeqold, 0, length);
// memcpy(lsfdeqold, lsfdeq, length*sizeof(float));
}
}
/*----------------------------------------------------------------*
* lsf quantizer (subrutine to LPCencode)
*---------------------------------------------------------------*/
void SimplelsfQ(
float lsfdeq[], /* (o) dequantized lsf coefficients
(dimension FILTERORDER) */
int index[], /* (o) quantization index */
float lsf[], /* (i) the lsf coefficient vector to be
quantized (dimension FILTERORDER ) */
int lpc_n /* (i) number of lsf sets to quantize */
){
/* Quantize first LSF with memoryless split VQ */
SplitVQ(lsfdeq, 0, index, 0, lsf, 0, ilbc_constants.lsfCbTbl,
ilbc_constants.LSF_NSPLIT, ilbc_constants.dim_lsfCbTbl,
ilbc_constants.size_lsfCbTbl);
if (lpc_n==2) {
/* Quantize second LSF with memoryless split VQ */
SplitVQ(lsfdeq, ilbc_constants.LPC_FILTERORDER,
index, ilbc_constants.LSF_NSPLIT,
lsf, ilbc_constants.LPC_FILTERORDER,
ilbc_constants.lsfCbTbl,
ilbc_constants.LSF_NSPLIT,
ilbc_constants.dim_lsfCbTbl,
ilbc_constants.size_lsfCbTbl);
}
}
/*----------------------------------------------------------------*
* lpc encoder
*---------------------------------------------------------------*/
void LPCencode(
float syntdenum[], /* (i/o) synthesis filter coefficients
before/after encoding */
float weightdenum[], /* (i/o) weighting denumerator
coefficients before/after
encoding */
int lsf_index[], /* (o) lsf quantization index */
float data[]) /* (i) lsf coefficients to quantize */
{
float [] lsf = new float[ilbc_constants.LPC_FILTERORDER * ilbc_constants.LPC_N_MAX];
float [] lsfdeq= new float[ilbc_constants.LPC_FILTERORDER * ilbc_constants.LPC_N_MAX];
int change = 0;
SimpleAnalysis(lsf, data);
// for (int li = 0; li < ilbc_constants.LPC_FILTERORDER * ilbc_constants.LPC_N_MAX; li++)
// System.out.println("postSA n-" + li + " is worth " + lsf[li]);
// for (int li = 0; li < ilbc_constants.BLOCKL_MAX; li++)
// System.out.println("data postSA n-" + li + " is worth " + data[li]);
SimplelsfQ(lsfdeq, lsf_index, lsf, this.ULP_inst.lpc_n);
// for (int li = 0; li < ilbc_constants.LPC_FILTERORDER * ilbc_constants.LPC_N_MAX; li++)
// System.out.println("postSlsfQ n-" + li + " is worth " + lsfdeq[li]);
// for (int li = 0; li < lsf_index.length; li++)
// System.out.println("index postSlsfQ n-" + li + " is worth " + lsf_index[li]);
change = ilbc_common.LSF_check(lsfdeq, ilbc_constants.LPC_FILTERORDER, this.ULP_inst.lpc_n);
//System.out.println("check gives " + change);
SimpleInterpolateLSF(syntdenum, weightdenum,
lsf, lsfdeq, this.lsfold,
this.lsfdeqold, ilbc_constants.LPC_FILTERORDER);
// for (int li = 0; li < syntdenum.length; li++)
// System.out.println("syntdenum[" + li +"] is worth " + syntdenum[li]);
}
public void iCBSearch(
int index[], /* (o) Codebook indices */
int index_idx,
int gain_index[],/* (o) Gain quantization indices */
int gain_index_idx,
float intarget[],/* (i) Target vector for encoding */
int intarget_idx,
float mem[], /* (i) Buffer for codebook construction */
int mem_idx,
int lMem, /* (i) Length of buffer */
int lTarget, /* (i) Length of vector */
int nStages, /* (i) Number of codebook stages */
float weightDenum[], /* (i) weighting filter coefficients */
int weightDenum_idx,
float weightState[], /* (i) weighting filter state */
int block) /* (i) the sub-block number */
{
int i, j, icount, stage, best_index, range, counter;
float max_measure, gain, measure, crossDot, ftmp;
float [] gains = new float[ilbc_constants.CB_NSTAGES];
float [] target = new float[ilbc_constants.SUBL];
int base_index, sInd, eInd, base_size;
int sIndAug=0, eIndAug=0;
float [] buf = new float[ilbc_constants.CB_MEML+ilbc_constants.SUBL+2*ilbc_constants.LPC_FILTERORDER];
float [] invenergy = new float[ilbc_constants.CB_EXPAND*128];
float [] energy = new float[ilbc_constants.CB_EXPAND*128];
// float *pp, *ppi=0, *ppo=0, *ppe=0;
int pp, ppi = 0, ppo = 0, ppe = 0;
float [] ppt;
float [] cbvectors = new float[ilbc_constants.CB_MEML];
float tene, cene;
float [] cvec = new float[ilbc_constants.SUBL];
float [] aug_vec = new float[ilbc_constants.SUBL];
float [] a = new float[1];
int [] b = new int[1];
float [] c = new float[1];
for (int li = 0; li < ilbc_constants.SUBL; li++)
cvec[li] = 0.0f;
// memset(cvec,0,SUBL*sizeof(float));
/* Determine size of codebook sections */
base_size=lMem-lTarget+1;
if (lTarget == ilbc_constants.SUBL) {
base_size=lMem-lTarget+1+lTarget/2;
}
/* setup buffer for weighting */
System.arraycopy(weightState, 0, buf, 0, ilbc_constants.LPC_FILTERORDER);
// memcpy(buf,weightState,sizeof(float)*LPC_FILTERORDER);
System.arraycopy(mem, mem_idx, buf, ilbc_constants.LPC_FILTERORDER, lMem);
// memcpy(buf+LPC_FILTERORDER,mem,lMem*sizeof(float));
System.arraycopy(intarget, intarget_idx, buf, ilbc_constants.LPC_FILTERORDER+lMem, lTarget);
// memcpy(buf+LPC_FILTERORDER+lMem,intarget,lTarget*sizeof(float));
//System.out.println("beginning of mem");
// for (int li = 0; li < lMem; li++)
// System.out.println("mem[" + li + "] = " + mem[li+mem_idx]);
// System.out.println("end of mem");
// System.out.println("plages : [0-" + ilbc_constants.LPC_FILTERORDER +
// "], puis [" + ilbc_constants.LPC_FILTERORDER + "-" + (ilbc_constants.LPC_FILTERORDER + lMem) +
// "], puis [" + (ilbc_constants.LPC_FILTERORDER + lMem) +
// "-" + (ilbc_constants.LPC_FILTERORDER + lMem + lTarget) + "]");
// System.out.println("beginning of buffer");
// for (int li = 0; li < buf.length; li++)
// System.out.println("buffer[" + li + "] = " + buf[li]);
// System.out.println("end of buffer");
/* weighting */
ilbc_common.AllPoleFilter(buf, ilbc_constants.LPC_FILTERORDER, weightDenum, weightDenum_idx,
lMem+lTarget, ilbc_constants.LPC_FILTERORDER);
/* Construct the codebook and target needed */
System.arraycopy(buf, ilbc_constants.LPC_FILTERORDER + lMem, target, 0, lTarget);
// memcpy(target, buf+LPC_FILTERORDER+lMem, lTarget*sizeof(float));
tene=0.0f;
for (i=0; i<lTarget; i++) {
tene+=target[i]*target[i];
}
/* Prepare search over one more codebook section. This section
is created by filtering the original buffer with a filter. */
filteredCBvecs(cbvectors, buf, ilbc_constants.LPC_FILTERORDER, lMem);
/* The Main Loop over stages */
for (stage=0; stage<nStages; stage++) {
range = ilbc_constants.search_rangeTbl[block][stage];
/* initialize search measure */
max_measure = (float)-10000000.0f;
gain = (float)0.0f;
best_index = 0;
/* Compute cross dot product between the target
and the CB memory */
crossDot=0.0f;
pp=ilbc_constants.LPC_FILTERORDER+lMem-lTarget;
// pp=buf+ilbc_constants.LPC_FILTERORDER+lMem-lTarget;
for (j=0; j<lTarget; j++) {
crossDot += target[j]*(buf[pp]);
pp++;
}
if (stage==0) {
/* Calculate energy in the first block of
'lTarget' samples. */
ppe = 0;
ppi = ilbc_constants.LPC_FILTERORDER+lMem-lTarget-1;
ppo = ilbc_constants.LPC_FILTERORDER+lMem-1;
// ppe = energy;
// ppi = buf+ilbc_constants.LPC_FILTERORDER+lMem-lTarget-1;
// ppo = buf+ilbc_constants.LPC_FILTERORDER+lMem-1;
energy[ppe]=0.0f;
pp=ilbc_constants.LPC_FILTERORDER+lMem-lTarget;
// pp=buf+ilbc_constants.LPC_FILTERORDER+lMem-lTarget;
for (j=0; j<lTarget; j++) {
energy[ppe]+=(buf[pp])*(buf[pp]);
pp++;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -