Fixed-point-ized a critical divide in the comb filter
authorjm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Wed, 9 Feb 2005 02:56:18 +0000 (02:56 +0000)
committerjm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Wed, 9 Feb 2005 02:56:18 +0000 (02:56 +0000)
git-svn-id: http://svn.xiph.org/trunk/speex@8878 0101bb08-14d6-0310-b084-bc0e0c8e3800

libspeex/filters.c

index ac5f68a..d533504 100644 (file)
@@ -478,7 +478,7 @@ CombFilterMem *mem
 {
    int i;
    spx_word16_t exc_energy=0, new_exc_energy=0;
-   float gain;
+   spx_word16_t gain;
    spx_word16_t step;
    spx_word16_t fact;
 
@@ -524,22 +524,25 @@ CombFilterMem *mem
    /*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 (exc_energy > new_exc_energy)
+      exc_energy = new_exc_energy;
+   
+   gain = DIV32_16(SHL(exc_energy,15),1+new_exc_energy);
+
+#ifdef FIXED_POINT
+   if (gain < 16384)
+      gain = 16384;
+#else
    if (gain < .5)
       gain=.5;
-   if (gain>.9999)
-      gain=.9999;
+#endif
 
 #ifdef FIXED_POINT
+   for (i=0;i<nsf;i++)
    {
-      spx_word16_t gg = gain*32768;
-      for (i=0;i<nsf;i++)
-   {
-      mem->smooth_gain = MULT16_16_Q15(31457,mem->smooth_gain) + MULT16_16_Q15(1311,gg);
+      mem->smooth_gain = MULT16_16_Q15(31457,mem->smooth_gain) + MULT16_16_Q15(1311,gain);
       new_exc[i] = MULT16_32_Q15(mem->smooth_gain, new_exc[i]);
    }
-   }
 #else
    for (i=0;i<nsf;i++)
    {