⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ilbc_encoder.java

📁 FMJ(freedom media for java)是java视频开发的新选择
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
           /* check if measure is better */           ftmp = crossDot*invenergy[0];           if ((measure>max_measure) && ((float)Math.abs(ftmp) < ilbc_constants.CB_MAXGAIN)) {               best_index = 0;               max_measure = measure;               gain = ftmp;           }           /* loop over the main first codebook section,              full search */           for (icount=1; icount<range; icount++) {               /* calculate measure */               crossDot=0.0f;               pp = ilbc_constants.LPC_FILTERORDER+lMem-lTarget-icount;//                pp = buf+LPC_FILTERORDER+lMem-lTarget-icount;               for (j=0; j<lTarget; j++) {                   crossDot += target[j]*(buf[pp]);		   pp++;               }               if (stage==0) {                   energy[ppe] = energy[icount-1] + (buf[ppi])*(buf[ppi]) -                       (buf[ppo])*(buf[ppo]);		   ppe++;                   ppo--;                   ppi--;                   if (energy[icount]>0.0f) {                       invenergy[icount] =                           (float)1.0f/(energy[icount]+ilbc_constants.EPS);                   } else {                       invenergy[icount] = (float) 0.0f;                   }                   measure=(float)-10000000.0f;                   if (crossDot > 0.0f) {                       measure = crossDot*crossDot*invenergy[icount];                   }               }               else {                   measure = crossDot*crossDot*invenergy[icount];               }               /* check if measure is better */               ftmp = crossDot*invenergy[icount];               if ((measure>max_measure) && ((float)Math.abs(ftmp) < ilbc_constants.CB_MAXGAIN)) {                   best_index = icount;                   max_measure = measure;                   gain = ftmp;               }           }           /* Loop over augmented part in the first codebook            * section, full search.            * The vectors are interpolated.            */           if (lTarget == ilbc_constants.SUBL) {               /* Search for best possible cb vector and                  compute the CB-vectors' energy. */	       a[0] = max_measure;	       b[0] = best_index;	       c[0] = gain;               searchAugmentedCB(20, 39, stage, base_size-lTarget/2,				 target, buf, ilbc_constants.LPC_FILTERORDER+lMem,				 a, b, c, energy, invenergy);	       max_measure = a[0];	       best_index = b[0];	       gain = c[0];           }           /* set search range for following codebook sections */	   //	   System.out.println("best index : " + best_index);           base_index = best_index;           /* unrestricted search */           if (ilbc_constants.CB_RESRANGE == -1) {	       //	       System.out.println("on met a 0");               sInd = 0;               eInd = range - 1;               sIndAug = 20;               eIndAug = 39;           }           /* restricted search around best index from first           codebook section */           else {               /* Initialize search indices */               sIndAug=0;               eIndAug=0;               sInd=base_index-ilbc_constants.CB_RESRANGE/2;	       //	       System.out.println("on met a " + base_index + " - " + ilbc_constants.CB_RESRANGE/2 + " = " + sInd);               eInd=sInd+ilbc_constants.CB_RESRANGE;               if (lTarget==ilbc_constants.SUBL) {                   if (sInd<0) {                       sIndAug = 40 + sInd;                       eIndAug = 39;		       //		       System.out.println("On met encore a 0");                       sInd=0;                   } else if ( base_index < (base_size-20) ) {                       if (eInd > range) {                           sInd -= (eInd-range);			   //			   System.out.println("on retire " + eInd + " - " + range + " pour arriver a " + sInd);                           eInd = range;                       }                   } else { /* base_index >= (base_size-20) */                       if (sInd < (base_size-20)) {                           sIndAug = 20;                           sInd = 0;			   //			   System.out.println("on remet encore a 0");                           eInd = 0;                           eIndAug = 19 + ilbc_constants.CB_RESRANGE;                           if(eIndAug > 39) {                               eInd = eIndAug-39;                               eIndAug = 39;                           }                       } else {                           sIndAug = 20 + sInd - (base_size-20);                           eIndAug = 39;                           sInd = 0;			   //			   System.out.println("on remetz4 a zero");                           eInd = ilbc_constants.CB_RESRANGE - (eIndAug-sIndAug+1);                       }                   }               } else { /* lTarget = 22 or 23 */                   if (sInd < 0) {                       eInd -= sInd;                       sInd = 0;		       //		       System.out.println("on remet x5 a zero");                   }                   if(eInd > range) {                       sInd -= (eInd - range);		       //		       System.out.println("on retire " + eInd + " - " + range + " pour arriver a " + sInd);                       eInd = range;                   }               }           }           /* search of higher codebook section */           /* index search range */           counter = sInd;	   //	   System.out.println("on ajoute " + base_size + " pour arriver a " + sInd);           sInd += base_size;           eInd += base_size;           if (stage==0) {	       //               ppe = energy+base_size;	       ppe = base_size;               energy[ppe]=0.0f;               pp=lMem-lTarget;	       //               pp=cbvectors+lMem-lTarget;               for (j=0; j<lTarget; j++) {                   energy[ppe] += (cbvectors[pp])*(cbvectors[pp]);		   pp++;               }               ppi = lMem - 1 - lTarget;               ppo = lMem - 1;//                ppi = cbvectors + lMem - 1 - lTarget;//                ppo = cbvectors + lMem - 1;               for (j=0; j<(range-1); j++) {                   energy[(ppe+1)] = energy[ppe] +		       (cbvectors[ppi])*(cbvectors[ppi]) -		       (cbvectors[ppo])*(cbvectors[ppo]);                   ppo--;                   ppi--;                   ppe++;               }           }           /* loop over search range */           for (icount=sInd; icount<eInd; icount++) {               /* calculate measure */               crossDot=0.0f;               pp=lMem - (counter++) - lTarget;//                pp=cbvectors + lMem - (counter++) - lTarget;//	       System.out.println("lMem : " + lMem);//	       System.out.println("counter : " + counter);//	       System.out.println("target : " + lTarget);               for (j=0;j<lTarget;j++) {                   crossDot += target[j]*(cbvectors[pp]);		   pp++;               }               if (energy[icount]>0.0f) {                   invenergy[icount] =(float)1.0f/(energy[icount]+ilbc_constants.EPS);               } else {                   invenergy[icount] =(float)0.0f;               }               if (stage==0) {                   measure=(float)-10000000.0f;                   if (crossDot > 0.0f) {                       measure = crossDot*crossDot*                           invenergy[icount];                   }               }               else {                   measure = crossDot*crossDot*invenergy[icount];               }               /* check if measure is better */               ftmp = crossDot*invenergy[icount];               if ((measure > max_measure) && ((float)Math.abs(ftmp)<ilbc_constants.CB_MAXGAIN)) {                   best_index = icount;                   max_measure = measure;                   gain = ftmp;               }           }           /* Search the augmented CB inside the limited range. */           if ((lTarget==ilbc_constants.SUBL)&&(sIndAug!=0)) {	       a[0] = max_measure;	       b[0] = best_index;	       c[0] = gain;               searchAugmentedCB(sIndAug, eIndAug, stage,				 2*base_size-20, target, cbvectors, lMem,				 a, b, c, energy, invenergy);	       max_measure = a[0];	       best_index = b[0];	       gain = c[0];           }           /* record best index */           index[index_idx+stage] = best_index;           /* gain quantization */           if (stage==0){               if (gain<0.0f){                   gain = 0.0f;               }               if (gain > ilbc_constants.CB_MAXGAIN) {                   gain = (float)ilbc_constants.CB_MAXGAIN;               }               gain = ilbc_common.gainquant(gain, 1.0f, 32, gain_index, gain_index_idx + stage);           }           else {               if (stage==1) {                   gain = ilbc_common.gainquant(gain, (float)(float)Math.abs(gains[stage-1]),                       16, gain_index, gain_index_idx + stage);               } else {                   gain = ilbc_common.gainquant(gain, (float)(float)Math.abs(gains[stage-1]),                       8, gain_index, gain_index_idx + stage);               }           }           /* Extract the best (according to measure)              codebook vector */           if (lTarget==(ilbc_constants.STATE_LEN - this.ULP_inst.state_short_len)) {               if (index[index_idx+stage]<base_size) {                   pp=ilbc_constants.LPC_FILTERORDER+lMem-lTarget-index[index_idx+stage];//                    pp=buf+ilbc_constants.LPC_FILTERORDER+lMem-lTarget-index[stage];		   ppt = buf;               } else {                   pp=lMem-lTarget-index[index_idx+stage]+base_size;//                    pp=cbvectors+lMem-lTarget-index[stage]+base_size;		   ppt = cbvectors;               }           } else {               if (index[index_idx+stage]<base_size) {                   if (index[index_idx+stage]<(base_size-20)) {                       pp=ilbc_constants.LPC_FILTERORDER+lMem-lTarget-index[index_idx+stage];		       //                        pp=buf+LPC_FILTERORDER+lMem-lTarget-index[stage];		       ppt = buf;                   } else {                       createAugmentedVec(index[index_idx+stage]-base_size+40,					  buf, ilbc_constants.LPC_FILTERORDER+lMem,aug_vec);		       //                       pp=aug_vec;		       pp = 0;		       ppt = aug_vec;                   }               } else {                   int filterno, position;                   filterno=index[index_idx+stage]/base_size;                   position=index[index_idx+stage]-filterno*base_size;                   if (position<(base_size-20)) {                       pp=filterno*lMem-lTarget-index[index_idx+stage]+filterno*base_size;//                        pp=cbvectors+filterno*lMem-lTarget-index[stage]+filterno*base_size;		       ppt = cbvectors;                   } else {                       createAugmentedVec(index[index_idx+stage]-(filterno+1)*base_size+40,					  cbvectors, filterno*lMem,aug_vec);		       //                       pp=aug_vec;		       pp = 0;		       ppt = aug_vec;                   }               }           }           /* Subtract the best codebook vector, according              to measure, from the target vector */           for (j=0;j<lTarget;j++) {               cvec[j] += gain*(ppt[pp]);               target[j] -= gain*(ppt[pp]);	       pp++;           }           /* record quantized gain */           gains[stage]=gain;       }/* end of Main Loop. for (stage=0;... */       /* Gain adjustment for energy matching */       cene=0.0f;       for (i=0; i<lTarget; i++) {           cene+=cvec[i]*cvec[i];       }       j=gain_index[gain_index_idx + 0];       for (i=gain_index[gain_index_idx + 0]; i<32; i++) {           ftmp=cene*ilbc_constants.gain_sq5Tbl[i]*ilbc_constants.gain_sq5Tbl[i];           if ((ftmp<(tene*gains[0]*gains[0])) &&               (ilbc_constants.gain_sq5Tbl[j]<(2.0f*gains[0]))) {               j=i;           }       }       gain_index[gain_index_idx + 0]=j;   }    public void index_conv_enc(int index[])          /* (i/o) Codebook indexes */    {	int k;	for (k=1; k < ilbc_constants.CB_NSTAGES; k++) {           if ((index[k]>=108)&&(index[k]<172)) {               index[k]-=64;           } else if (index[k]>=236) {               index[k]-=128;           } else {               /* ERROR */           }       }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -