if (gain>1) gain=1;
if (gain>.9999) gain=.9999;
void comb_filter(spx_sig_t *exc,          /*decoded excitation*/spx_sig_t *new_exc,      /*enhanced excitation*/spx_coef_t *ak,           /*LPC filter coefs*/int p,               /*LPC order*/int nsf,             /*sub-frame size*/int pitch,           /*pitch period*/spx_word16_t *pitch_gain,   /*pitch gain (3-tap)*/float  comb_gain,    /*gain of comb filter*/CombFilterMem *mem){   int i;   spx_word16_t exc_energy=0, new_exc_energy=0;   float gain;   spx_word16_t step;   spx_word16_t fact;   spx_word16_t cgain;   /*Compute excitation amplitude prior to enhancement*/   exc_energy = compute_rms(exc, nsf);   /*for (i=0;i<nsf;i++)     exc_energy+=((float)exc[i])*exc[i];*/   /*Some gain adjustment if pitch is too high or if unvoiced*/   {      float g=0;      g = GAIN_SCALING_1*.5*(gain_3tap_to_1tap(pitch_gain)+gain_3tap_to_1tap(mem->last_pitch_gain));      if (g>1.3)         comb_gain*=1.3/g;      if (g<.5)         comb_gain*=2*g;   }   step = DIV32(COMB_STEP, nsf);   fact=0;#ifdef FIXED_POINT   cgain = comb_gain*32768;#else   cgain = comb_gain;#endif   /*Apply pitch comb-filter (filter out noise between pitch harmonics)*/   for (i=0;i<nsf;i++)   {      spx_word32_t exc1, exc2;      fact += step;            exc1 = SHL(MULT16_32_Q15(SHL(pitch_gain[0],7),exc[i-pitch+1]) +                 MULT16_32_Q15(SHL(pitch_gain[1],7),exc[i-pitch]) +                 MULT16_32_Q15(SHL(pitch_gain[2],7),exc[i-pitch-1]) , 2);      exc2 = SHL(MULT16_32_Q15(SHL(mem->last_pitch_gain[0],7),exc[i-mem->last_pitch+1]) +                 MULT16_32_Q15(SHL(mem->last_pitch_gain[1],7),exc[i-mem->last_pitch]) +                 MULT16_32_Q15(SHL(mem->last_pitch_gain[2],7),exc[i-mem->last_pitch-1]),2);      new_exc[i] = exc[i] + MULT16_32_Q15(cgain,MULT16_32_Q15(fact,exc1)  + MULT16_32_Q15(SUB16(COMB_STEP,fact), exc2));   }   mem->last_pitch_gain[0] = pitch_gain[0];   mem->last_pitch_gain[1] = pitch_gain[1];   mem->last_pitch_gain[2] = pitch_gain[2];   mem->last_pitch = pitch;   /*Amplitude after enhancement*/   new_exc_energy = compute_rms(new_exc, nsf);   /*Compute scaling factor and normalize energy*/   gain = (exc_energy)/(.1+new_exc_energy);   if (gain < .5)      gain=.5;   if (gain>1)      gain=1;   for (i=0;i<nsf;i++)   {      mem->smooth_gain = .96*mem->smooth_gain + .04*gain;      new_exc[i] *= mem->smooth_gain;   }}