gst/law/mulaw-conversion.c: Fix overflow bug in ulaw encoding.
authorWim Taymans <wim.taymans@gmail.com>
Wed, 19 May 2004 20:04:10 +0000 (20:04 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Wed, 19 May 2004 20:04:10 +0000 (20:04 +0000)
Original commit message from CVS:
* gst/law/mulaw-conversion.c: (mulaw_encode):
Fix overflow bug in ulaw encoding.

ChangeLog
gst/law/mulaw-conversion.c

index c7a1527..ed229c4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2004-05-19  Wim Taymans  <wim@fluendo.com>
+
+       * gst/law/mulaw-conversion.c: (mulaw_encode):
+       Fix overflow bug in ulaw encoding.
+
 2004-05-19  Benjamin Otte  <in7y118@public.uni-hamburg.de>
 
        * ext/mad/gstmad.c: (gst_mad_handle_event):
index a05d7bd..5cee843 100644 (file)
@@ -25,7 +25,7 @@
 
 #include <glib.h>
 
-#define ZEROTRAP                /* turn on the trap as per the MIL-STD */
+/* #define ZEROTRAP *//* turn on the trap as per the MIL-STD */
 #define BIAS 0x84               /* define the add-in bias for 16 bit samples */
 #define CLIP 32635
 
@@ -57,10 +57,14 @@ mulaw_encode (gint16 * in, guint8 * out, gint numsamples)
     sample = in[i];
       /** get the sample into sign-magnitude **/
     sign = (sample >> 8) & 0x80;        /* set aside the sign */
-    if (sign != 0)
+    if (sign != 0) {
       sample = -sample;         /* get magnitude */
-    if (sample > CLIP)
+    }
+    /* sample can be zero because we can overflow in the inversion,
+     * checking against the unsigned version solves this */
+    if (((guint16) sample) > CLIP)
       sample = CLIP;            /* clip the magnitude */
+
       /** convert from 16 bit linear to ulaw **/
     sample = sample + BIAS;
     exponent = exp_lut[(sample >> 7) & 0xFF];