44    {
   45       int i, j, icount, stage, best_index, range, counter;
   46       float max_measure, gain, measure, crossDot, ftmp;
   49       int base_index, sInd, eInd, base_size;
   50       int sIndAug=0, eIndAug=0;
   53       float *pp, *ppi=0, *ppo=0, *ppe=0;
   55       float tene, cene, cvec[
SUBL];
 
   57 
   58       memset(cvec,0,
SUBL*
sizeof(
float));
 
   59 
   60       
   61 
   62       base_size=lMem-lTarget+1;
   63 
   65           base_size=lMem-lTarget+1+lTarget/2;
   66       }
   67 
   68       
   69 
   73 
   74       
   75 
   78 
   79       
   80 
   82 
   83       tene=0.0;
   84 
   85 
   86 
   87 
   88 
   89       for (i=0; i<lTarget; i++) {
   90           tene+=target[i]*target[i];
   91       }
   92 
   93       
   94
   95 
   97 
   98       
   99 
  100       for (stage=0; stage<nStages; stage++) {
  101 
  103 
  104           
  105 
  106           max_measure = (float)-10000000.0;
  107           gain = (float)0.0;
  108           best_index = 0;
  109 
  110           
  111
  112 
  113           crossDot=0.0;
  115           for (j=0; j<lTarget; j++) {
  116               crossDot += target[j]*(*pp++);
  117           }
  118 
  119           if (stage==0) {
  120 
  121               
  122
  123               ppe = energy;
  126 
  127               *ppe=0.0;
  129               for (j=0; j<lTarget; j++, pp++) {
  130                   *ppe+=(*pp)*(*pp);
  131               }
  132 
  133               if (*ppe>0.0) {
  134                   invenergy[0] = (float) 1.0 / (*ppe + 
EPS);
 
  135               } else {
  136                   invenergy[0] = (float) 0.0;
  137 
  138 
  139 
  140 
  141 
  142               }
  143               ppe++;
  144 
  145               measure=(float)-10000000.0;
  146 
  147               if (crossDot > 0.0) {
  148                      measure = crossDot*crossDot*invenergy[0];
  149               }
  150           }
  151           else {
  152               measure = crossDot*crossDot*invenergy[0];
  153           }
  154 
  155           
  156           ftmp = crossDot*invenergy[0];
  157 
  158           if ((measure>max_measure) && (fabs(ftmp)<
CB_MAXGAIN)) {
 
  159               best_index = 0;
  160               max_measure = measure;
  161               gain = ftmp;
  162           }
  163 
  164           
  165
  166 
  167           for (icount=1; icount<range; icount++) {
  168 
  169               
  170 
  171               crossDot=0.0;
  173 
  174               for (j=0; j<lTarget; j++) {
  175                   crossDot += target[j]*(*pp++);
  176               }
  177 
  178               if (stage==0) {
  179                   *ppe++ = energy[icount-1] + (*ppi)*(*ppi) -
  180                       (*ppo)*(*ppo);
  181                   ppo--;
  182                   ppi--;
  183 
  184                   if (energy[icount]>0.0) {
  185                       invenergy[icount] =
  186                           (float)1.0/(energy[icount]+
EPS);
 
  187                   } else {
  188                       invenergy[icount] = (float) 0.0;
  189                   }
  190 
  191 
  192 
  193 
  194 
  195                   measure=(float)-10000000.0;
  196 
  197                   if (crossDot > 0.0) {
  198                       measure = crossDot*crossDot*invenergy[icount];
  199                   }
  200               }
  201               else {
  202                   measure = crossDot*crossDot*invenergy[icount];
  203               }
  204 
  205               
  206               ftmp = crossDot*invenergy[icount];
  207 
  208               if ((measure>max_measure) && (fabs(ftmp)<
CB_MAXGAIN)) {
 
  209                   best_index = icount;
  210                   max_measure = measure;
  211                   gain = ftmp;
  212               }
  213           }
  214 
  215           
  216
  217
  218
  219 
  221 
  222               
  223
  226                   &max_measure, &best_index, &gain, energy,
  227                   invenergy);
  228           }
  229 
  230           
  231 
  232           base_index=best_index;
  233 
  234           
  235 
  237               sInd=0;
  238               eInd=range-1;
  239               sIndAug=20;
  240               eIndAug=39;
  241           }
  242 
  243 
  244 
  245 
  246 
  247 
  248           
  249
  250 
  251           else {
  252               
  253               sIndAug=0;
  254               eIndAug=0;
  257 
  259 
  260                   if (sInd<0) {
  261 
  262                       sIndAug = 40 + sInd;
  263                       eIndAug = 39;
  264                       sInd=0;
  265 
  266                   } else if ( base_index < (base_size-20) ) {
  267 
  268                       if (eInd > range) {
  269                           sInd -= (eInd-range);
  270                           eInd = range;
  271                       }
  272                   } else { 
  273 
  274                       if (sInd < (base_size-20)) {
  275                           sIndAug = 20;
  276                           sInd = 0;
  277                           eInd = 0;
  279 
  280                           if(eIndAug > 39) {
  281                               eInd = eIndAug-39;
  282                               eIndAug = 39;
  283                           }
  284                       } else {
  285                           sIndAug = 20 + sInd - (base_size-20);
  286                           eIndAug = 39;
  287                           sInd = 0;
  289                       }
  290                   }
  291 
  292               } else { 
  293 
  294                   if (sInd < 0) {
  295                       eInd -= sInd;
  296 
  297 
  298 
  299 
  300 
  301                       sInd = 0;
  302                   }
  303 
  304                   if(eInd > range) {
  305                       sInd -= (eInd - range);
  306                       eInd = range;
  307                   }
  308               }
  309           }
  310 
  311           
  312 
  313           
  314           counter = sInd;
  315           sInd += base_size;
  316           eInd += base_size;
  317 
  318 
  319           if (stage==0) {
  320               ppe = energy+base_size;
  321               *ppe=0.0;
  322 
  323               pp=cbvectors+lMem-lTarget;
  324               for (j=0; j<lTarget; j++, pp++) {
  325                   *ppe+=(*pp)*(*pp);
  326               }
  327 
  328               ppi = cbvectors + lMem - 1 - lTarget;
  329               ppo = cbvectors + lMem - 1;
  330 
  331               for (j=0; j<(range-1); j++) {
  332                   *(ppe+1) = *ppe + (*ppi)*(*ppi) - (*ppo)*(*ppo);
  333                   ppo--;
  334                   ppi--;
  335                   ppe++;
  336               }
  337           }
  338 
  339           
  340 
  341           for (icount=sInd; icount<eInd; icount++) {
  342 
  343               
  344 
  345               crossDot=0.0;
  346               pp=cbvectors + lMem - (counter++) - lTarget;
  347 
  348               for (j=0;j<lTarget;j++) {
  349 
  350 
  351 
  352 
  353 
  354                   crossDot += target[j]*(*pp++);
  355               }
  356 
  357               if (energy[icount]>0.0) {
  358                   invenergy[icount] =(float)1.0/(energy[icount]+
EPS);
 
  359               } else {
  360                   invenergy[icount] =(float)0.0;
  361               }
  362 
  363               if (stage==0) {
  364 
  365                   measure=(float)-10000000.0;
  366 
  367                   if (crossDot > 0.0) {
  368                       measure = crossDot*crossDot*
  369                           invenergy[icount];
  370                   }
  371               }
  372               else {
  373                   measure = crossDot*crossDot*invenergy[icount];
  374               }
  375 
  376               
  377               ftmp = crossDot*invenergy[icount];
  378 
  379               if ((measure>max_measure) && (fabs(ftmp)<
CB_MAXGAIN)) {
 
  380                   best_index = icount;
  381                   max_measure = measure;
  382                   gain = ftmp;
  383               }
  384           }
  385 
  386           
  387 
  388           if ((lTarget==
SUBL)&&(sIndAug!=0)) {
 
  390                   2*base_size-20, target, cbvectors+lMem,
  391                   &max_measure, &best_index, &gain, energy,
  392                   invenergy);
  393           }
  394 
  395           
  396 
  397           index[stage] = best_index;
  398 
  399           
  400 
  401           if (stage==0){
  402 
  403 
  404 
  405 
  406 
  407 
  408               if (gain<0.0){
  409                   gain = 0.0;
  410               }
  411 
  414               }
  415               gain = 
gainquant(gain, 1.0, 32, &gain_index[stage]);
 
  416           }
  417           else {
  418               if (stage==1) {
  419                   gain = 
gainquant(gain, (
float)fabs(gains[stage-1]),
 
  420                       16, &gain_index[stage]);
  421               } else {
  422                   gain = 
gainquant(gain, (
float)fabs(gains[stage-1]),
 
  423                       8, &gain_index[stage]);
  424               }
  425           }
  426 
  427           
  428
  429 
  431 
  432               if (index[stage]<base_size) {
  434               } else {
  435                   pp=cbvectors+lMem-lTarget-
  436                       index[stage]+base_size;
  437               }
  438           } else {
  439 
  440               if (index[stage]<base_size) {
  441                   if (index[stage]<(base_size-20)) {
  443                           lTarget-index[stage];
  444                   } else {
  447                       pp=aug_vec;
  448                   }
  449               } else {
  450                   int filterno, position;
  451 
  452                   filterno=index[stage]/base_size;
  453                   position=index[stage]-filterno*base_size;
  454 
  455 
  456 
  457 
  458 
  459 
  460 
  461                   if (position<(base_size-20)) {
  462                       pp=cbvectors+filterno*lMem-lTarget-
  463                           index[stage]+filterno*base_size;
  464                   } else {
  466                           index[stage]-(filterno+1)*base_size+40,
  467                           cbvectors+filterno*lMem,aug_vec);
  468                       pp=aug_vec;
  469                   }
  470               }
  471           }
  472 
  473           
  474
  475 
  476           for (j=0;j<lTarget;j++) {
  477               cvec[j] += gain*(*pp);
  478               target[j] -= gain*(*pp++);
  479           }
  480 
  481           
  482 
  483           gains[stage]=gain;
  484 
  485       }
  486 
  487       
  488       cene=0.0;
  489       for (i=0; i<lTarget; i++) {
  490           cene+=cvec[i]*cvec[i];
  491       }
  492       j=gain_index[0];
  493 
  494       for (i=gain_index[0]; i<32; i++) {
  496 
  497           if ((ftmp<(tene*gains[0]*gains[0])) &&
  499               j=i;
  500           }
  501       }
  502       gain_index[0]=j;
  503   }
int search_rangeTbl[5][CB_NSTAGES]
void createAugmentedVec(int index, float *buffer, float *cbVec)
void searchAugmentedCB(int low, int high, int stage, int startIndex, float *target, float *buffer, float *max_measure, int *best_index, float *gain, float *energy, float *invenergy)
void filteredCBvecs(float *cbvectors, float *mem, int lMem)
void AllPoleFilter(float *InOut, float *Coef, int lengthInOut, int orderCoef)
float gainquant(float in, float maxIn, int cblen, int *index)