Get rid of liboil
authorWim Taymans <wim.taymans@collabora.co.uk>
Fri, 14 Aug 2009 17:45:39 +0000 (19:45 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Thu, 20 Aug 2009 09:31:03 +0000 (11:31 +0200)
Get rid of the liboil dependency and reimplement the liboil functions with an
equivalent C implementation. Note that most of these functions are deprecated in
liboil and that none of them had  any optimisations. We can further specialize
our handrolled versions for some extra speedups.

configure.ac
src/daemon/main.c
src/pulsecore/resampler.c
src/pulsecore/sconv-s16le.c
src/pulsecore/sconv.c
src/tests/envelope-test.c
src/tests/mix-test.c
src/tests/remix-test.c
src/tests/resampler-test.c

index 05312d3..40455e1 100644 (file)
@@ -941,12 +941,6 @@ AC_SUBST(AVAHI_LIBS)
 AC_SUBST(HAVE_AVAHI)
 AM_CONDITIONAL([HAVE_AVAHI], [test "x$HAVE_AVAHI" = x1])
 
-### LIBOIL ####
-
-PKG_CHECK_MODULES(LIBOIL, [ liboil-0.3 >= 0.3.0 ])
-AC_SUBST(LIBOIL_CFLAGS)
-AC_SUBST(LIBOIL_LIBS)
-
 ### JACK (optional) ####
 
 AC_ARG_ENABLE([jack],
index 774b4e9..31e434d 100644 (file)
@@ -39,8 +39,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#include <liboil/liboil.h>
-
 #ifdef HAVE_SYS_MMAN_H
 #include <sys/mman.h>
 #endif
@@ -863,8 +861,6 @@ int main(int argc, char *argv[]) {
     win32_timer = pa_mainloop_get_api(mainloop)->rtclock_time_new(pa_mainloop_get_api(mainloop), pa_gettimeofday(&win32_tv), message_cb, NULL);
 #endif
 
-    oil_init();
-
     if (!conf->no_cpu_limit)
         pa_assert_se(pa_cpu_limit_init(pa_mainloop_get_api(mainloop)) == 0);
 
index 59e0a0c..a3c17f8 100644 (file)
@@ -31,9 +31,6 @@
 
 #include <speex/speex_resampler.h>
 
-#include <liboil/liboilfuncs.h>
-#include <liboil/liboil.h>
-
 #include <pulse/xmalloc.h>
 #include <pulsecore/sconv.h>
 #include <pulsecore/log.h>
@@ -1045,33 +1042,46 @@ static pa_memchunk* convert_to_work_format(pa_resampler *r, pa_memchunk *input)
     return &r->buf1;
 }
 
-static void vectoradd_s16_with_fraction(
-        int16_t *d, int dstr,
-        const int16_t *s1, int sstr1,
-        const int16_t *s2, int sstr2,
-        int n,
-        float s3, float s4) {
+static void vectoradd_f32(
+        float *d, int dstr,
+        const float *s, int sstr,
+        int n, float s4) {
 
-    int32_t i3, i4;
+    for (; n > 0; n--) {
+        *d = (float) (*d + (s4 * *s));
 
-    i3 = (int32_t) (s3 * 0x10000);
-    i4 = (int32_t) (s4 * 0x10000);
+        s = (const float*) ((const uint8_t*) s + sstr);
+        d = (float*) ((uint8_t*) d + dstr);
+    }
+}
+
+static void vectoradd_s16(
+        int16_t *d, int dstr,
+        const int16_t *s, int sstr,
+        int n) {
 
     for (; n > 0; n--) {
-        int32_t a, b;
+        *d = (int16_t) (*d + *s);
 
-        a = *s1;
-        b = *s2;
+        s = (const int16_t*) ((const uint8_t*) s + sstr);
+        d = (int16_t*) ((uint8_t*) d + dstr);
+    }
+}
 
-        a = (a * i3) / 0x10000;
-        b = (b * i4) / 0x10000;
+static void vectoradd_s16_with_fraction(
+        int16_t *d, int dstr,
+        const int16_t *s, int sstr,
+        int n, float s4) {
 
-        *d = (int16_t) (a + b);
+    int32_t i4;
 
-        s1 = (const int16_t*) ((const uint8_t*) s1 + sstr1);
-        s2 = (const int16_t*) ((const uint8_t*) s2 + sstr2);
-        d = (int16_t*) ((uint8_t*) d + dstr);
+    i4 = (int32_t) (s4 * 0x10000);
+
+    for (; n > 0; n--) {
+        *d = (int16_t) (*d + (((int32_t)*s * i4) >> 16));
 
+        s = (const int16_t*) ((const uint8_t*) s + sstr);
+        d = (int16_t*) ((uint8_t*) d + dstr);
     }
 }
 
@@ -1125,12 +1135,11 @@ static pa_memchunk *remap_channels(pa_resampler *r, pa_memchunk *input) {
                     if (r->map_table[oc][ic] <= 0.0)
                         continue;
 
-                    oil_vectoradd_f32(
-                            (float*) dst + oc, o_skip,
+                    vectoradd_f32(
                             (float*) dst + oc, o_skip,
                             (float*) src + ic, i_skip,
                             (int) n_frames,
-                            &one, &r->map_table[oc][ic]);
+                            r->map_table[oc][ic]);
                 }
             }
 
@@ -1147,23 +1156,19 @@ static pa_memchunk *remap_channels(pa_resampler *r, pa_memchunk *input) {
                         continue;
 
                     if (r->map_table[oc][ic] >= 1.0) {
-                        static const int16_t one = 1;
 
-                        oil_vectoradd_s16(
-                                (int16_t*) dst + oc, o_skip,
+                        vectoradd_s16(
                                 (int16_t*) dst + oc, o_skip,
                                 (int16_t*) src + ic, i_skip,
-                                (int) n_frames,
-                                &one, &one);
+                                (int) n_frames);
 
                     } else
 
                         vectoradd_s16_with_fraction(
                                 (int16_t*) dst + oc, o_skip,
-                                (int16_t*) dst + oc, o_skip,
                                 (int16_t*) src + ic, i_skip,
                                 (int) n_frames,
-                                1.0f, r->map_table[oc][ic]);
+                                r->map_table[oc][ic]);
                 }
             }
 
@@ -1469,7 +1474,7 @@ static void trivial_resample(pa_resampler *r, const pa_memchunk *input, unsigned
 
         pa_assert(o_index * fz < pa_memblock_get_length(output->memblock));
 
-        oil_memcpy((uint8_t*) dst + fz * o_index,
+        memcpy((uint8_t*) dst + fz * o_index,
                    (uint8_t*) src + fz * j, (int) fz);
     }
 
index 43b8cb3..0fefdf1 100644 (file)
@@ -28,8 +28,6 @@
 #include <inttypes.h>
 #include <stdio.h>
 
-#include <liboil/liboilfuncs.h>
-
 #include <pulsecore/sconv.h>
 #include <pulsecore/macro.h>
 #include <pulsecore/log.h>
@@ -86,17 +84,13 @@ void pa_sconv_s16le_to_float32ne(unsigned n, const int16_t *a, float *b) {
     pa_assert(b);
 
 #if SWAP_WORDS == 1
-
     for (; n > 0; n--) {
         int16_t s = *(a++);
         *(b++) = ((float) INT16_FROM(s))/(float) 0x7FFF;
     }
-
 #else
-{
-    static const double add = 0, factor = 1.0/0x7FFF;
-    oil_scaleconv_f32_s16(b, a, (int) n, &add, &factor);
-}
+    for (; n > 0; n--)
+        *(b++) = ((float) (*(a++)))/(float) 0x7FFF;
 #endif
 }
 
@@ -105,17 +99,13 @@ void pa_sconv_s32le_to_float32ne(unsigned n, const int32_t *a, float *b) {
     pa_assert(b);
 
 #if SWAP_WORDS == 1
-
     for (; n > 0; n--) {
         int32_t s = *(a++);
         *(b++) = (float) (((double) INT32_FROM(s))/0x7FFFFFFF);
     }
-
 #else
-{
-    static const double add = 0, factor = 1.0/0x7FFFFFFF;
-    oil_scaleconv_f32_s32(b, a, (int) n, &add, &factor);
-}
+    for (; n > 0; n--)
+        *(b++) = (float) (((double) (*(a++)))/0x7FFFFFFF);
 #endif
 }
 
@@ -124,7 +114,6 @@ void pa_sconv_s16le_from_float32ne(unsigned n, const float *a, int16_t *b) {
     pa_assert(b);
 
 #if SWAP_WORDS == 1
-
     for (; n > 0; n--) {
         int16_t s;
         float v = *(a++);
@@ -133,12 +122,13 @@ void pa_sconv_s16le_from_float32ne(unsigned n, const float *a, int16_t *b) {
         s = (int16_t) lrintf(v * 0x7FFF);
         *(b++) = INT16_TO(s);
     }
-
 #else
-{
-    static const double add = 0, factor = 0x7FFF;
-    oil_scaleconv_s16_f32(b, a, (int) n, &add, &factor);
-}
+    for (; n > 0; n--) {
+        float v = *(a++);
+
+        v = PA_CLAMP_UNLIKELY(v, -1.0f, 1.f);
+        *(b++) = (int16_t) lrintf(v * 0x7FFF);
+    }
 #endif
 }
 
@@ -147,7 +137,6 @@ void pa_sconv_s32le_from_float32ne(unsigned n, const float *a, int32_t *b) {
     pa_assert(b);
 
 #if SWAP_WORDS == 1
-
     for (; n > 0; n--) {
         int32_t s;
         float v = *(a++);
@@ -156,12 +145,13 @@ void pa_sconv_s32le_from_float32ne(unsigned n, const float *a, int32_t *b) {
         s = (int32_t) lrint((double) v * (double) 0x7FFFFFFF);
         *(b++) = INT32_TO(s);
     }
-
 #else
-{
-    static const double add = 0, factor = 0x7FFFFFFF;
-    oil_scaleconv_s32_f32(b, a, (int) n, &add, &factor);
-}
+    for (; n > 0; n--) {
+        float v = *(a++);
+
+        v = PA_CLAMP_UNLIKELY(v, -1.0f, 1.0f);
+        *(b++) = (int32_t) lrint((double) v * (double) 0x7FFFFFFF);
+    }
 #endif
 }
 
index d89f428..937bf5d 100644 (file)
@@ -27,9 +27,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#include <liboil/liboilfuncs.h>
-#include <liboil/liboil.h>
-
 #include <pulsecore/g711.h>
 #include <pulsecore/macro.h>
 
 
 /* u8 */
 static void u8_to_float32ne(unsigned n, const uint8_t *a, float *b) {
-    static const double add = -1, factor = 1.0/128.0;
-
     pa_assert(a);
     pa_assert(b);
 
-    oil_scaleconv_f32_u8(b, a, (int) n, &add, &factor);
+    for (; n > 0; n--, a++, b++)
+        *b = (*a * 1.0/128.0) - 1.0;
 }
 
 static void u8_from_float32ne(unsigned n, const float *a, uint8_t *b) {
-    static const double add = 128, factor = 127.0;
-
     pa_assert(a);
     pa_assert(b);
 
-    oil_scaleconv_u8_f32(b, a, (int) n, &add, &factor);
+    for (; n > 0; n--, a++, b++) {
+        float v;
+        v = (*a * 127.0) + 128.0;
+       v = PA_CLAMP_UNLIKELY (v, 0.0, 255.0);
+       *b = rint (v);
+    }
 }
 
 static void u8_to_s16ne(unsigned n, const uint8_t *a, int16_t *b) {
-    static const int16_t add = -0x80, factor = 0x100;
-
     pa_assert(a);
     pa_assert(b);
 
-    oil_conv_s16_u8(b, 2, a, 1, (int) n);
-    oil_scalaradd_s16(b, 2, b, 2, &add, (int) n);
-    oil_scalarmult_s16(b, 2, b, 2, &factor, (int) n);
+    for (; n > 0; n--, a++, b++)
+        *b = (((int16_t)*a) - 128) << 8;
 }
 
 static void u8_from_s16ne(unsigned n, const int16_t *a, uint8_t *b) {
@@ -84,7 +80,7 @@ static void float32ne_to_float32ne(unsigned n, const float *a, float *b) {
     pa_assert(a);
     pa_assert(b);
 
-    oil_memcpy(b, a, (int) (sizeof(float) * n));
+    memcpy(b, a, (int) (sizeof(float) * n));
 }
 
 static void float32re_to_float32ne(unsigned n, const float *a, float *b) {
@@ -101,7 +97,7 @@ static void s16ne_to_s16ne(unsigned n, const int16_t *a, int16_t *b) {
     pa_assert(a);
     pa_assert(b);
 
-    oil_memcpy(b, a, (int) (sizeof(int16_t) * n));
+    memcpy(b, a, (int) (sizeof(int16_t) * n));
 }
 
 static void s16re_to_s16ne(unsigned n, const int16_t *a, int16_t *b) {
index 3af3044..9382040 100644 (file)
@@ -34,8 +34,6 @@
 #include <pulsecore/memblock.h>
 #include <pulsecore/sample-util.h>
 
-#include <liboil/liboil.h>
-
 const pa_envelope_def ramp_down = {
     .n_points = 2,
     .points_x = { 100*PA_USEC_PER_MSEC, 300*PA_USEC_PER_MSEC },
@@ -202,7 +200,6 @@ int main(int argc, char *argv[]) {
         .values = { PA_VOLUME_NORM, PA_VOLUME_NORM/2 }
     };
 
-    oil_init();
     pa_log_set_level(PA_LOG_DEBUG);
 
     pa_assert_se(pool = pa_mempool_new(FALSE, 0));
index f9f76da..457c4ac 100644 (file)
@@ -32,8 +32,6 @@
 #include <pulsecore/memblock.h>
 #include <pulsecore/sample-util.h>
 
-#include <liboil/liboil.h>
-
 static float swap_float(float a) {
     uint32_t *b = (uint32_t*) &a;
     *b = PA_UINT32_SWAP(*b);
@@ -211,7 +209,6 @@ int main(int argc, char *argv[]) {
     pa_sample_spec a;
     pa_cvolume v;
 
-    oil_init();
     pa_log_set_level(PA_LOG_DEBUG);
 
     pa_assert_se(pool = pa_mempool_new(FALSE, 0));
index 9d110d6..4990bf9 100644 (file)
@@ -32,8 +32,6 @@
 #include <pulsecore/memblock.h>
 #include <pulsecore/sample-util.h>
 
-#include <liboil/liboil.h>
-
 int main(int argc, char *argv[]) {
 
     static const pa_channel_map maps[] = {
@@ -55,7 +53,6 @@ int main(int argc, char *argv[]) {
     unsigned i, j;
     pa_mempool *pool;
 
-    oil_init();
     pa_log_set_level(PA_LOG_DEBUG);
 
     pa_assert_se(pool = pa_mempool_new(FALSE, 0));
index 7236265..82198b5 100644 (file)
@@ -32,8 +32,6 @@
 #include <pulsecore/memblock.h>
 #include <pulsecore/sample-util.h>
 
-#include <liboil/liboil.h>
-
 static void dump_block(const pa_sample_spec *ss, const pa_memchunk *chunk) {
     void *d;
     unsigned i;
@@ -248,7 +246,6 @@ int main(int argc, char *argv[]) {
     pa_sample_spec a, b;
     pa_cvolume v;
 
-    oil_init();
     pa_log_set_level(PA_LOG_DEBUG);
 
     pa_assert_se(pool = pa_mempool_new(FALSE, 0));