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

📄 icbsearch.c

📁 PA1688网络电话机全部源程序
💻 C
📖 第 1 页 / 共 2 页
字号:
    
               eIndAug=0; 
               sInd=base_index-CB_RESRANGE/2; 
               eInd=sInd+CB_RESRANGE; 
                
               if (lTarget==SUBL) { 
    
                   if (sInd<0) { 
                        
                       sIndAug = 40 + sInd; 
                       eIndAug = 39; 
                       sInd=0; 
    
                   } else if ( base_index < (base_size-20) ) { 
                        
                       if (eInd > range) { 
                           sInd -= (eInd-range); 
                           eInd = range; 
                       } 
                   } else { /* base_index >= (base_size-20) */ 
                        
                       if (sInd < (base_size-20)) { 
                           sIndAug = 20; 
                           sInd = 0; 
                           eInd = 0; 
                           eIndAug = 19 + CB_RESRANGE; 
                            
                           if(eIndAug > 39) { 
                               eInd = eIndAug-39; 
                               eIndAug = 39; 
                           } 
                       } else { 
                           sIndAug = 20 + sInd - (base_size-20); 
                           eIndAug = 39; 
                           sInd = 0; 
                           eInd = CB_RESRANGE - (eIndAug-sIndAug+1); 
                       } 
                   } 
    
               } else { /* lTarget = 22 or 23 */ 
                    
                   if (sInd < 0) { 
                       eInd -= sInd; 
                       sInd = 0; 
                   } 
                    
                   if(eInd > range) { 
                       sInd -= (eInd - range); 
                       eInd = range; 
                   } 
               } 
           } 
    
           /* search of higher codebook section */ 
     
    
    
    
           /* index search range */ 
           counter = sInd; 
           sInd += base_size; 
           eInd += base_size; 
            
            
           if (stage==0) { 
               ppe = energy+base_size; 
               *ppe=0.0; 
    
               pp=cbvectors+lMem-lTarget; 
               for (j=0; j<lTarget; j++) { 
                   *ppe+=(*pp)*(*pp++); 
               } 
    
               ppi = cbvectors + lMem - 1 - lTarget; 
               ppo = cbvectors + lMem - 1; 
                
               for (j=0; j<(range-1); j++) { 
                   *(ppe+1) = *ppe + (*ppi)*(*ppi) - (*ppo)*(*ppo); 
                   ppo--; 
                   ppi--; 
                   ppe++; 
               } 
           } 
    
           /* loop over search range */ 
    
           for (icount=sInd; icount<eInd; icount++) { 
    
               /* calculate measure */ 
    
               crossDot=0.0; 
               pp=cbvectors + lMem - (counter++) - lTarget; 
    
               for (j=0;j<lTarget;j++) { 
                   crossDot += target[j]*(*pp++); 
               } 
                
               if (energy[icount]>0.0) { 
                   invenergy[icount] = (float) 1.0/(energy[icount]+EPS); 
               } else { 
                   invenergy[icount] = (float) 0.0; 
               } 
                
               if (stage==0) { 
    
                   measure=(float)-10000000.0; 
                    
                   if (crossDot > 0.0) { 
                       measure = crossDot*crossDot* 
                           invenergy[icount]; 
     
    
    
                   } 
               } 
               else { 
                   measure = crossDot*crossDot*invenergy[icount]; 
               } 
    
               /* check if measure is better */ 
               ftmp = crossDot*invenergy[icount]; 
    
               if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)){ 
                   best_index = icount; 
                   max_measure = measure; 
                   gain = ftmp; 
               } 
           } 
    
           /* Search the augmented CB inside the limited range. */ 
            
           if ((lTarget==SUBL)&&(sIndAug!=0)) { 
    
               searchAugmentedCB(sIndAug, eIndAug, stage,  
                   2*base_size-20, target, cbvectors+lMem, 
                   &max_measure, &best_index, &gain, energy, invenergy); 
    
           } 
    
           /* record best index */ 
    
           index[stage] = best_index; 
    
           /* gain quantization */ 
    
           if (stage==0){ 
                
               if (gain<0.0){ 
                   gain = 0.0; 
               } 
                
               if (gain>CB_MAXGAIN) { 
                   gain = (float)CB_MAXGAIN; 
               } 
               gain = gainquant(gain, 1.0, 32, &gain_index[stage]); 
           } 
           else { 
               if (stage==1) { 
                   gain = gainquant(gain, (float)fabs(gains[stage-1]),  
                       16, &gain_index[stage]); 
               } else { 
                   gain = gainquant(gain, (float)fabs(gains[stage-1]),  
                       8, &gain_index[stage]); 
               } 
           } 
    
     
    
    
           /* Extract the best (according to measure) codebook vector */ 
            
           if (lTarget==(STATE_LEN-iLBCenc_inst->state_short_len)) { 
                
               if (index[stage]<base_size) { 
                   pp=buf+LPC_FILTERORDER+lMem-lTarget-index[stage]; 
               } else { 
                   pp=cbvectors+lMem-lTarget- 
                       index[stage]+base_size; 
               } 
           } else { 
                
               if (index[stage]<base_size) { 
                   if (index[stage]<(base_size-20)) { 
                       pp=buf+LPC_FILTERORDER+lMem-lTarget-index[stage]; 
                   } else { 
                       createAugmentedVec(index[stage]-base_size+40, 
                               buf+LPC_FILTERORDER+lMem,aug_vec); 
                       pp=aug_vec; 
                   } 
               } else { 
                   int filterno, lag_val; 
    
                   filterno=index[stage]/base_size; 
                   lag_val=index[stage]-filterno*base_size; 
    
                    
                   if (lag_val<(base_size-20)) { 
                       pp=cbvectors+filterno*lMem-lTarget- 
                           index[stage]+filterno*base_size; 
                   } else { 
                       createAugmentedVec( 
                           index[stage]-(filterno+1)*base_size+40, 
                           cbvectors+filterno*lMem,aug_vec); 
                       pp=aug_vec; 
                   } 
               } 
           } 
    
           /* Subtract the best codebook vector, according  
              to measure, from the target vector */ 
    
           for (j=0;j<lTarget;j++) { 
               cvec[j] += gain*(*pp); 
               target[j] -= gain*(*pp++); 
           } 
    
           /* record quantized gain */ 
    
           gains[stage]=gain; 
    
       }/* end of Main Loop. for (stage=0;... */ 
    
     
    
    
       /* Gain adjustment for energy matching */ 
       cene=0.0; 
       for (i=0; i<lTarget; i++) { 
           cene+=cvec[i]*cvec[i]; 
       } 
       j=gain_index[0]; 
    
       for (i=gain_index[0]; i<32; i++) { 
           ftmp=cene*gain_sq5Tbl[i]*gain_sq5Tbl[i]; 
            
           if ((ftmp<(tene*gains[0]*gains[0])) &&  
               (gain_sq5Tbl[j]<(2.0*gains[0]))) { 
               j=i; 
           } 
       } 
       gain_index[0]=j; 
   } 
    
    

⌨️ 快捷键说明

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