[xiph-commits] r11393 - trunk/speex/libspeex

jm at svn.xiph.org jm at svn.xiph.org
Wed May 10 06:04:29 PDT 2006


Author: jm
Date: 2006-05-10 06:04:27 -0700 (Wed, 10 May 2006)
New Revision: 11393

Modified:
   trunk/speex/libspeex/mdf.c
Log:
Check for overflow (and saturate) in preemphasis.


Modified: trunk/speex/libspeex/mdf.c
===================================================================
--- trunk/speex/libspeex/mdf.c	2006-05-10 07:19:23 UTC (rev 11392)
+++ trunk/speex/libspeex/mdf.c	2006-05-10 13:04:27 UTC (rev 11393)
@@ -463,13 +463,40 @@
    for (i=0;i<st->frame_size;i++)
    {
       spx_word16_t tmp;
+      spx_word32_t tmp32;
       st->x[i] = st->x[i+st->frame_size];
-      st->x[i+st->frame_size] = SUB16(echo[i], MULT16_16_P15(st->preemph, st->memX));
+      tmp32 = SUB32(EXTEND32(echo[i]), EXTEND32(MULT16_16_P15(st->preemph, st->memX)));
+#ifdef FIXED_POINT
+      if (tmp32 > 32767)
+      {
+         tmp32 = 32767;
+         saturated = 1;
+      }      
+      if (tmp32 < -32767)
+      {
+         tmp32 = -32767;
+         saturated = 1;
+      }      
+#endif
+      st->x[i+st->frame_size] = EXTRACT16(tmp32);
       st->memX = echo[i];
       
       tmp = st->d[i];
       st->d[i] = st->d[i+st->frame_size];
-      st->d[i+st->frame_size] = SUB16(tmp, MULT16_16_P15(st->preemph, st->memD));
+      tmp32 = SUB32(EXTEND32(tmp), EXTEND32(MULT16_16_P15(st->preemph, st->memD)));
+#ifdef FIXED_POINT
+      if (tmp32 > 32767)
+      {
+         tmp32 = 32767;
+         saturated = 1;
+      }      
+      if (tmp32 < -32767)
+      {
+         tmp32 = -32767;
+         saturated = 1;
+      }
+#endif
+      st->d[i+st->frame_size] = tmp32;
       st->memD = tmp;
    }
 



More information about the commits mailing list