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];
58 memset(cvec,0,
SUBL*
sizeof(
float));
62 base_size=lMem-lTarget+1;
65 base_size=lMem-lTarget+1+lTarget/2;
89 for (i=0; i<lTarget; i++) {
90 tene+=target[i]*target[i];
100 for (stage=0; stage<nStages; stage++) {
106 max_measure = (float)-10000000.0;
115 for (j=0; j<lTarget; j++) {
116 crossDot += target[j]*(*pp++);
129 for (j=0; j<lTarget; j++, pp++) {
134 invenergy[0] = (float) 1.0 / (*ppe +
EPS);
136 invenergy[0] = (float) 0.0;
145 measure=(float)-10000000.0;
147 if (crossDot > 0.0) {
148 measure = crossDot*crossDot*invenergy[0];
152 measure = crossDot*crossDot*invenergy[0];
156 ftmp = crossDot*invenergy[0];
158 if ((measure>max_measure) && (fabs(ftmp)<
CB_MAXGAIN)) {
160 max_measure = measure;
167 for (icount=1; icount<range; icount++) {
174 for (j=0; j<lTarget; j++) {
175 crossDot += target[j]*(*pp++);
179 *ppe++ = energy[icount-1] + (*ppi)*(*ppi) -
184 if (energy[icount]>0.0) {
186 (float)1.0/(energy[icount]+
EPS);
188 invenergy[icount] = (float) 0.0;
195 measure=(float)-10000000.0;
197 if (crossDot > 0.0) {
198 measure = crossDot*crossDot*invenergy[icount];
202 measure = crossDot*crossDot*invenergy[icount];
206 ftmp = crossDot*invenergy[icount];
208 if ((measure>max_measure) && (fabs(ftmp)<
CB_MAXGAIN)) {
210 max_measure = measure;
226 &max_measure, &best_index, &gain, energy,
232 base_index=best_index;
266 }
else if ( base_index < (base_size-20) ) {
269 sInd -= (eInd-range);
274 if (sInd < (base_size-20)) {
285 sIndAug = 20 + sInd - (base_size-20);
288 eInd = CB_RESRANGE - (eIndAug-sIndAug+1);
305 sInd -= (eInd - range);
320 ppe = energy+base_size;
323 pp=cbvectors+lMem-lTarget;
324 for (j=0; j<lTarget; j++, pp++) {
328 ppi = cbvectors + lMem - 1 - lTarget;
329 ppo = cbvectors + lMem - 1;
331 for (j=0; j<(range-1); j++) {
332 *(ppe+1) = *ppe + (*ppi)*(*ppi) - (*ppo)*(*ppo);
341 for (icount=sInd; icount<eInd; icount++) {
346 pp=cbvectors + lMem - (counter++) - lTarget;
348 for (j=0;j<lTarget;j++) {
354 crossDot += target[j]*(*pp++);
357 if (energy[icount]>0.0) {
358 invenergy[icount] =(float)1.0/(energy[icount]+
EPS);
360 invenergy[icount] =(float)0.0;
365 measure=(float)-10000000.0;
367 if (crossDot > 0.0) {
368 measure = crossDot*crossDot*
373 measure = crossDot*crossDot*invenergy[icount];
377 ftmp = crossDot*invenergy[icount];
379 if ((measure>max_measure) && (fabs(ftmp)<
CB_MAXGAIN)) {
381 max_measure = measure;
388 if ((lTarget==
SUBL)&&(sIndAug!=0)) {
390 2*base_size-20, target, cbvectors+lMem,
391 &max_measure, &best_index, &gain, energy,
397 index[stage] = best_index;
415 gain =
gainquant(gain, 1.0, 32, &gain_index[stage]);
419 gain =
gainquant(gain, (
float)fabs(gains[stage-1]),
420 16, &gain_index[stage]);
422 gain =
gainquant(gain, (
float)fabs(gains[stage-1]),
423 8, &gain_index[stage]);
432 if (index[stage]<base_size) {
435 pp=cbvectors+lMem-lTarget-
436 index[stage]+base_size;
440 if (index[stage]<base_size) {
441 if (index[stage]<(base_size-20)) {
443 lTarget-index[stage];
450 int filterno, position;
452 filterno=index[stage]/base_size;
453 position=index[stage]-filterno*base_size;
461 if (position<(base_size-20)) {
462 pp=cbvectors+filterno*lMem-lTarget-
463 index[stage]+filterno*base_size;
466 index[stage]-(filterno+1)*base_size+40,
467 cbvectors+filterno*lMem,aug_vec);
476 for (j=0;j<lTarget;j++) {
477 cvec[j] += gain*(*pp);
478 target[j] -= gain*(*pp++);
489 for (i=0; i<lTarget; i++) {
490 cene+=cvec[i]*cvec[i];
494 for (i=gain_index[0]; i<32; i++) {
497 if ((ftmp<(tene*gains[0]*gains[0])) &&
498 (gain_sq5Tbl[j]<(2.0*gains[0]))) {
int search_rangeTbl[5][CB_NSTAGES]
void AllPoleFilter(float *InOut, float *Coef, int lengthInOut, int orderCoef)
void createAugmentedVec(int index, float *buffer, float *cbVec)
void filteredCBvecs(float *cbvectors, float *mem, int lMem)
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)
float gainquant(float in, float maxIn, int cblen, int *index)