ilbc_common.java
来自「FMJ(freedom media for java)是java视频开发的新选择」· Java 代码 · 共 726 行 · 第 1/2 页
JAVA
726 行
int in2_idx, float coef, /* (i) interpolation weights */ int length) /* (i) length of all vectors */ { int i; float invcoef; invcoef = (float)1.0f - coef; for (i = 0; i < length; i++) { out[i] = coef * in1[i] + invcoef * in2[i + in2_idx]; // System.out.println("out["+i+"] devient " + out[i] + ", par " + // coef + " * " + in1[i] + " + " + invcoef + " * " + in2[i + in2_idx]); } } /*----------------------------------------------------------------* * lpc bandwidth expansion *---------------------------------------------------------------*/ public static void bwexpand( float out[], /* (o) the bandwidth expanded lpc coefficients */ int out_idx, float in[], /* (i) the lpc coefficients before bandwidth expansion */ float coef, /* (i) the bandwidth expansion factor */ int length) /* (i) the length of lpc coefficient vectors */ { int i; float chirp; chirp = coef; out[out_idx] = in[0]; for (i = 1; i < length; i++) { out[i + out_idx] = chirp * in[i]; chirp *= coef; } } public static void getCBvec( float cbvec[], /* (o) Constructed codebook vector */ float mem[], /* (i) Codebook buffer */ int mem_idx, int index, /* (i) Codebook index */ int lMem, /* (i) Length of codebook buffer */ int cbveclen) /* (i) Codebook vector length */ { int j, k, n, memInd, sFilt; float [] tmpbuf = new float[ilbc_constants.CB_MEML]; int base_size; int ilow, ihigh; float alfa, alfa1; /* Determine size of codebook sections */ base_size=lMem-cbveclen+1; if (cbveclen==ilbc_constants.SUBL) { base_size+=cbveclen/2; } /* No filter -> First codebook section */ if (index<lMem-cbveclen+1) { /* first non-interpolated vectors */ k=index+cbveclen; /* get vector */ System.arraycopy(mem, mem_idx + lMem - k, cbvec, 0, cbveclen); // memcpy(cbvec, mem+lMem-k, cbveclen*sizeof(float)); } else if (index < base_size) { k=2*(index-(lMem-cbveclen+1))+cbveclen; ihigh=k/2; ilow=ihigh-5; /* Copy first noninterpolated part */ System.arraycopy(mem, mem_idx + lMem - k / 2, cbvec, 0, ilow); // memcpy(cbvec, mem+lMem-k/2, ilow*sizeof(float)); /* interpolation */ alfa1=(float)0.2; alfa=0.0f; for (j=ilow; j<ihigh; j++) { cbvec[j]=((float)1.0f-alfa)*mem[mem_idx + lMem-k/2+j]+ alfa*mem[mem_idx + lMem-k+j]; alfa+=alfa1; } /* Copy second noninterpolated part */ System.arraycopy(mem, mem_idx+lMem-k+ihigh, cbvec, ihigh, (cbveclen-ihigh));// memcpy(cbvec+ihigh, mem+lMem-k+ihigh,// (cbveclen-ihigh)*sizeof(float)); } /* Higher codebook section based on filtering */ else { /* first non-interpolated vectors */ if (index-base_size<lMem-cbveclen+1) { float [] tempbuff2 = new float[ilbc_constants.CB_MEML+ilbc_constants.CB_FILTERLEN+1];// float *pos;// float *pp, *pp1; int pos, pp, pp1; for (int li = 0; li < ilbc_constants.CB_HALFFILTERLEN; li++) tempbuff2[li] = 0.0f;// memset(tempbuff2, 0,// CB_HALFFILTERLEN*sizeof(float)); System.arraycopy(mem, mem_idx, tempbuff2, ilbc_constants.CB_HALFFILTERLEN, lMem);// memcpy(&tempbuff2[CB_HALFFILTERLEN], mem,// lMem*sizeof(float)); for (int li = 0; li < ilbc_constants.CB_HALFFILTERLEN + 1; li++) tempbuff2[lMem + ilbc_constants.CB_HALFFILTERLEN + li] = 0.0f;// memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0,// (CB_HALFFILTERLEN+1)*sizeof(float)); k=index-base_size+cbveclen; sFilt=lMem-k; memInd=sFilt+1-ilbc_constants.CB_HALFFILTERLEN; /* do filtering */ // pos=cbvec; pos = 0; for (int li = 0; li < cbveclen; li++) cbvec[li] = 0;// memset(pos, 0, cbveclen*sizeof(float)); for (n=0; n<cbveclen; n++) { pp = memInd + n + ilbc_constants.CB_HALFFILTERLEN;// pp=&tempbuff2[memInd+n+CB_HALFFILTERLEN]; pp1 = ilbc_constants.CB_FILTERLEN - 1;// pp1=&cbfiltersTbl[CB_FILTERLEN-1]; for (j=0; j < ilbc_constants.CB_FILTERLEN; j++) {// (*pos)+=(*pp++)*(*pp1--); cbvec[pos] += tempbuff2[pp] * ilbc_constants.cbfiltersTbl[pp1]; pp++; pp1--; } pos++; } } /* interpolated vectors */ else { float [] tempbuff2 = new float[ilbc_constants.CB_MEML+ilbc_constants.CB_FILTERLEN+1];// float *pos;// float *pp, *pp1; int pos, pp, pp1; int i; for (int li = 0; li < ilbc_constants.CB_HALFFILTERLEN; li++) tempbuff2[li] = 0.0f;// memset(tempbuff2, 0,// CB_HALFFILTERLEN*sizeof(float)); System.arraycopy(mem, mem_idx, tempbuff2, ilbc_constants.CB_HALFFILTERLEN, lMem);// memcpy(&tempbuff2[CB_HALFFILTERLEN], mem,// lMem*sizeof(float)); for (int li = 0; li < ilbc_constants.CB_HALFFILTERLEN; li++) tempbuff2[lMem+ilbc_constants.CB_HALFFILTERLEN+li] = 0.0f;// memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0,// (CB_HALFFILTERLEN+1)*sizeof(float)); k=2*(index-base_size- (lMem-cbveclen+1))+cbveclen; sFilt=lMem-k; memInd=sFilt+1 - ilbc_constants.CB_HALFFILTERLEN; /* do filtering */ // pos=&tmpbuf[sFilt]; pos = sFilt; // memset(pos, 0, k*sizeof(float)); for (int li = 0; li < k; li++) tmpbuf[pos+li] = 0.0f; for (i=0; i<k; i++) { pp = memInd + i + ilbc_constants.CB_HALFFILTERLEN;// pp=&tempbuff2[memInd+i+CB_HALFFILTERLEN]; pp1 = ilbc_constants.CB_FILTERLEN-1;// pp1=&cbfiltersTbl[CB_FILTERLEN-1]; for (j=0; j < ilbc_constants.CB_FILTERLEN; j++) { // (*pos)+=(*pp++)*(*pp1--); tmpbuf[pos] += tempbuff2[pp] * ilbc_constants.cbfiltersTbl[pp1]; pp++; pp1--; } pos++; } ihigh = k / 2; ilow=ihigh-5; /* Copy first noninterpolated part */ System.arraycopy(tmpbuf, lMem - k / 2, cbvec, 0, ilow);// memcpy(cbvec, tmpbuf+lMem-k/2,// ilow*sizeof(float)); /* interpolation */ alfa1=(float)0.2; alfa=0.0f; for (j=ilow; j<ihigh; j++) { cbvec[j]=((float)1.0f-alfa)* tmpbuf[lMem-k/2+j]+alfa*tmpbuf[lMem-k+j]; alfa+=alfa1; } /* Copy second noninterpolated part */ System.arraycopy(tmpbuf, lMem-k+ihigh, cbvec, ihigh, cbveclen - ihigh);// memcpy(cbvec+ihigh, tmpbuf+lMem-k+ihigh,// (cbveclen-ihigh)*sizeof(float)); } } } public static float gainquant(/* (o) quantized gain value */ float in, /* (i) gain value */ float maxIn,/* (i) maximum of gain value */ int cblen, /* (i) number of quantization indices */ int index[], /* (o) quantization index */ int index_idx) { int i, tindex; float minmeasure,measure, cb[], scale; /* ensure a lower bound on the scaling factor */ scale = maxIn; if (scale < 0.1) { scale = (float)0.1; } /* select the quantization table */ if (cblen == 8) { cb = ilbc_constants.gain_sq3Tbl; } else if (cblen == 16) { cb = ilbc_constants.gain_sq4Tbl; } else { cb = ilbc_constants.gain_sq5Tbl; } /* select the best index in the quantization table */ minmeasure=10000000.0f; tindex=0; for (i=0; i<cblen; i++) { measure = (in - scale*cb[i])*(in-scale*cb[i]); if (measure<minmeasure) { tindex=i; minmeasure=measure; } } index[index_idx] = tindex; /* return the quantized value */ return scale*cb[tindex]; } /*----------------------------------------------------------------* * decoder for quantized gains in the gain-shape coding of * residual *---------------------------------------------------------------*/ public static float gaindequant( /* (o) quantized gain value */ int index, /* (i) quantization index */ float maxIn,/* (i) maximum of unquantized gain */ int cblen) /* (i) number of quantization indices */ { float scale; /* obtain correct scale factor */ scale=(float)(float)Math.abs(maxIn); if (scale < 0.1) { scale=(float)0.1; } /* select the quantization table and return the decoded value */ if (cblen==8) { return scale*ilbc_constants.gain_sq3Tbl[index]; } else if (cblen==16) { return scale*ilbc_constants.gain_sq4Tbl[index]; } else if (cblen==32) { return scale*ilbc_constants.gain_sq5Tbl[index]; } return 0.0f; } public static void iCBConstruct( float decvector[], /* (o) Decoded vector */ int decvector_idx, int index[], /* (i) Codebook indices */ int index_idx, int gain_index[],/* (i) Gain quantization indices */ int gain_index_idx, float mem[], /* (i) Buffer for codevector construction */ int mem_idx, int lMem, /* (i) Length of buffer */ int veclen, /* (i) Length of vector */ int nStages /* (i) Number of codebook stages */ ){ int j,k; float [] gain = new float[ilbc_constants.CB_NSTAGES]; float [] cbvec = new float[ilbc_constants.SUBL]; /* gain de-quantization */ gain[0] = gaindequant(gain_index[gain_index_idx + 0], 1.0f, 32); if (nStages > 1) { gain[1] = gaindequant(gain_index[gain_index_idx + 1], (float)(float)Math.abs(gain[0]), 16); } if (nStages > 2) { gain[2] = gaindequant(gain_index[gain_index_idx + 2], (float)(float)Math.abs(gain[1]), 8); } /* codebook vector construction and construction of total vector */ getCBvec(cbvec, mem, mem_idx, index[index_idx + 0], lMem, veclen); for (j=0;j<veclen;j++){ decvector[decvector_idx + j] = gain[0]*cbvec[j]; } if (nStages > 1) { for (k=1; k<nStages; k++) { getCBvec(cbvec, mem, mem_idx, index[index_idx + k], lMem, veclen); for (j=0;j<veclen;j++) { decvector[decvector_idx + j] += gain[k]*cbvec[j]; } } } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?