src/audio/SDL_audiocvt.c
changeset 2042 3908e1f808e1
parent 2014 7abe37467fa5
child 2049 5f6550e5184f
--- a/src/audio/SDL_audiocvt.c	Sun Sep 24 00:55:19 2006 +0000
+++ b/src/audio/SDL_audiocvt.c	Sun Sep 24 15:56:36 2006 +0000
@@ -45,11 +45,7 @@
             dst = cvt->buf;
             for (i = cvt->len_cvt / 2; i; --i) {
                 sample = src[0] + src[1];
-                if (sample > 255) {
-                    *dst = 255;
-                } else {
-                    *dst = (Uint8) sample;
-                }
+                *dst = (Uint8) (sample / 2);
                 src += 2;
                 dst += 1;
             }
@@ -64,13 +60,7 @@
             dst = (Sint8 *) cvt->buf;
             for (i = cvt->len_cvt / 2; i; --i) {
                 sample = src[0] + src[1];
-                if (sample > 127) {
-                    *dst = 127;
-                } else if (sample < -128) {
-                    *dst = -128;
-                } else {
-                    *dst = (Sint8) sample;
-                }
+                *dst = (Sint8) (sample / 2);
                 src += 2;
                 dst += 1;
             }
@@ -87,14 +77,10 @@
                 for (i = cvt->len_cvt / 4; i; --i) {
                     sample = (Uint16) ((src[0] << 8) | src[1]) +
                         (Uint16) ((src[2] << 8) | src[3]);
-                    if (sample > 65535) {
-                        dst[0] = 0xFF;
-                        dst[1] = 0xFF;
-                    } else {
-                        dst[1] = (sample & 0xFF);
-                        sample >>= 8;
-                        dst[0] = (sample & 0xFF);
-                    }
+                    sample /= 2;
+                    dst[1] = (sample & 0xFF);
+                    sample >>= 8;
+                    dst[0] = (sample & 0xFF);
                     src += 4;
                     dst += 2;
                 }
@@ -102,14 +88,10 @@
                 for (i = cvt->len_cvt / 4; i; --i) {
                     sample = (Uint16) ((src[1] << 8) | src[0]) +
                         (Uint16) ((src[3] << 8) | src[2]);
-                    if (sample > 65535) {
-                        dst[0] = 0xFF;
-                        dst[1] = 0xFF;
-                    } else {
-                        dst[0] = (sample & 0xFF);
-                        sample >>= 8;
-                        dst[1] = (sample & 0xFF);
-                    }
+                    sample /= 2;
+                    dst[0] = (sample & 0xFF);
+                    sample >>= 8;
+                    dst[1] = (sample & 0xFF);
                     src += 4;
                     dst += 2;
                 }
@@ -127,17 +109,10 @@
                 for (i = cvt->len_cvt / 4; i; --i) {
                     sample = (Sint16) ((src[0] << 8) | src[1]) +
                         (Sint16) ((src[2] << 8) | src[3]);
-                    if (sample > 32767) {
-                        dst[0] = 0x7F;
-                        dst[1] = 0xFF;
-                    } else if (sample < -32768) {
-                        dst[0] = 0x80;
-                        dst[1] = 0x00;
-                    } else {
-                        dst[1] = (sample & 0xFF);
-                        sample >>= 8;
-                        dst[0] = (sample & 0xFF);
-                    }
+                    sample /= 2;
+                    dst[1] = (sample & 0xFF);
+                    sample >>= 8;
+                    dst[0] = (sample & 0xFF);
                     src += 4;
                     dst += 2;
                 }
@@ -145,17 +120,10 @@
                 for (i = cvt->len_cvt / 4; i; --i) {
                     sample = (Sint16) ((src[1] << 8) | src[0]) +
                         (Sint16) ((src[3] << 8) | src[2]);
-                    if (sample > 32767) {
-                        dst[1] = 0x7F;
-                        dst[0] = 0xFF;
-                    } else if (sample < -32768) {
-                        dst[1] = 0x80;
-                        dst[0] = 0x00;
-                    } else {
-                        dst[0] = (sample & 0xFF);
-                        sample >>= 8;
-                        dst[1] = (sample & 0xFF);
-                    }
+                    sample /= 2;
+                    dst[0] = (sample & 0xFF);
+                    sample >>= 8;
+                    dst[1] = (sample & 0xFF);
                     src += 4;
                     dst += 2;
                 }