]> code.delx.au - pulseaudio/commitdiff
rework a couple of sample type converters, to actually work
authorLennart Poettering <lennart@poettering.net>
Sat, 22 Sep 2007 00:26:18 +0000 (00:26 +0000)
committerLennart Poettering <lennart@poettering.net>
Sat, 22 Sep 2007 00:26:18 +0000 (00:26 +0000)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1883 fefdeb5f-60dc-0310-8127-8f9354f1896f

src/pulsecore/sconv-s16le.c
src/pulsecore/sconv.c

index c82708caed3ccf5bb0f03b36594ca0b12449946c..86b3729598c4e9b2a195777e4d29704009ba9930 100644 (file)
@@ -82,12 +82,7 @@ void pa_sconv_s16le_from_float32ne(unsigned n, const float *a, int16_t *b) {
         int16_t s;
         float v = *(a++);
 
-        if (v > 1)
-            v = 1;
-
-        if (v < -1)
-            v = -1;
-
+        v = CLAMP(v, -1, 1);
         s = (int16_t) (v * 0x7FFF);
         *(b++) = INT16_TO(s);
     }
@@ -104,8 +99,6 @@ void pa_sconv_s16le_to_float32re(unsigned n, const int16_t *a, float *b) {
     pa_assert(a);
     pa_assert(b);
 
-#if SWAP_WORDS == 1
-
     for (; n > 0; n--) {
         int16_t s = *(a++);
         float k = ((float) INT16_FROM(s))/0x7FFF;
@@ -113,31 +106,19 @@ void pa_sconv_s16le_to_float32re(unsigned n, const int16_t *a, float *b) {
         *j = UINT32_SWAP(*j);
         *(b++) = k;
     }
-
-#endif
 }
 
 void pa_sconv_s16le_from_float32re(unsigned n, const float *a, int16_t *b) {
     pa_assert(a);
     pa_assert(b);
 
-#if SWAP_WORDS == 1
-
     for (; n > 0; n--) {
         int16_t s;
         float v = *(a++);
         uint32_t *j = (uint32_t*) &v;
         *j = UINT32_SWAP(*j);
-
-        if (v > 1)
-            v = 1;
-
-        if (v < -1)
-            v = -1;
-
+        v = CLAMP(v, -1, 1);
         s = (int16_t) (v * 0x7FFF);
         *(b++) = INT16_TO(s);
     }
-
-#endif
 }
index 4986ba7c274e66dc155a14909d0911ad2ffed339..933192b66973e862842dd8b34f08d634bdd32869 100644 (file)
@@ -43,7 +43,7 @@
 
 /* u8 */
 static void u8_to_float32ne(unsigned n, const uint8_t *a, float *b) {
-    static const double add = -128.0/127.0, factor = 1.0/127.0;
+    static const double add = -1, factor = 1.0/128.0;
 
     pa_assert(a);
     pa_assert(b);
@@ -52,7 +52,7 @@ static void u8_to_float32ne(unsigned n, const uint8_t *a, float *b) {
 }
 
 static void u8_from_float32ne(unsigned n, const float *a, uint8_t *b) {
-    static const double add = 128.0, factor = 127.0;
+    static const double add = 128, factor = 127.0;
 
     pa_assert(a);
     pa_assert(b);
@@ -61,7 +61,7 @@ static void u8_from_float32ne(unsigned n, const float *a, uint8_t *b) {
 }
 
 static void u8_to_s16ne(unsigned n, const uint8_t *a, int16_t *b) {
-    static const int16_t add = -128, factor = 0x100;
+    static const int16_t add = -0x80, factor = 0x100;
 
     pa_assert(a);
     pa_assert(b);
@@ -75,8 +75,8 @@ static void u8_from_s16ne(unsigned n, const int16_t *a, uint8_t *b) {
 
     pa_assert(a);
     pa_assert(b);
-    
-    for (; n > 0; n--, a ++, a++)
+
+    for (; n > 0; n--, a++, b++)
         *b = (uint8_t) (*a / 0x100 + 0x80);
 }
 
@@ -121,7 +121,7 @@ static void ulaw_to_float32ne(unsigned n, const uint8_t *a, float *b) {
     pa_assert(b);
 
     for (; n > 0; n--)
-        *(b++) = st_ulaw2linear16(*(a++)) * 1.0F / 0x7FFF;
+        *(b++) = (float) st_ulaw2linear16(*(a++)) / 0x8000;
 }
 
 static void ulaw_from_float32ne(unsigned n, const float *a, uint8_t *b) {
@@ -130,14 +130,9 @@ static void ulaw_from_float32ne(unsigned n, const float *a, uint8_t *b) {
 
     for (; n > 0; n--) {
         float v = *(a++);
-
-        if (v > 1)
-            v = 1;
-
-        if (v < -1)
-            v = -1;
-
-        *(b++) = st_14linear2ulaw((int16_t) (v * 0x1FFF));
+        v = CLAMP(v, -1, 1);
+        v *= 0x1FFF;
+        *(b++) = st_14linear2ulaw((int16_t) v);
     }
 }
 
@@ -164,7 +159,7 @@ static void alaw_to_float32ne(unsigned n, const uint8_t *a, float *b) {
     pa_assert(b);
 
     for (; n > 0; n--, a++, b++)
-        *b = st_alaw2linear16(*a) * 1.0F / 0x7FFF;
+        *b = (float) st_alaw2linear16(*a) / 0x8000;
 }
 
 static void alaw_from_float32ne(unsigned n, const float *a, uint8_t *b) {
@@ -173,14 +168,9 @@ static void alaw_from_float32ne(unsigned n, const float *a, uint8_t *b) {
 
     for (; n > 0; n--, a++, b++) {
         float v = *a;
-
-        if (v > 1)
-            v = 1;
-
-        if (v < -1)
-            v = -1;
-
-        *b = st_13linear2alaw((int16_t) (v * 0xFFF));
+        v = CLAMP(v, -1, 1);
+        v *= 0xFFF;
+        *b = st_13linear2alaw((int16_t) v);
     }
 }
 
@@ -196,7 +186,7 @@ static void alaw_from_s16ne(unsigned n, const int16_t *a, uint8_t *b) {
     pa_assert(a);
     pa_assert(b);
 
-    for (; n > 0; n--)
+    for (; n > 0; n--, a++, b++)
         *b = st_13linear2alaw(*a >> 3);
 }