diff options
author | Wim Taymans <wim.taymans@gmail.com> | 2004-05-19 20:04:10 +0000 |
---|---|---|
committer | Wim Taymans <wim.taymans@gmail.com> | 2004-05-19 20:04:10 +0000 |
commit | b7d2e0b236a00429d7f6acc69b0c9d3fcdcdaed7 (patch) | |
tree | efae2d5597dc251488efaec331b08cedce21ce61 /gst | |
parent | 625ec784c390f79a19854f8c5c72a7d4c1aef943 (diff) |
gst/law/mulaw-conversion.c: Fix overflow bug in ulaw encoding.
Original commit message from CVS:
* gst/law/mulaw-conversion.c: (mulaw_encode):
Fix overflow bug in ulaw encoding.
Diffstat (limited to 'gst')
-rw-r--r-- | gst/law/mulaw-conversion.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/gst/law/mulaw-conversion.c b/gst/law/mulaw-conversion.c index a05d7bdc..5cee8436 100644 --- a/gst/law/mulaw-conversion.c +++ b/gst/law/mulaw-conversion.c @@ -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]; |