]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Merge branch 'refs/heads/t/wma_improvements'
authorAndre Noll <maan@tuebingen.mpg.de>
Fri, 21 Apr 2017 15:07:00 +0000 (17:07 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Fri, 21 Apr 2017 15:09:17 +0000 (17:09 +0200)
A couple of simple patches which simplify the WMA code and improve
readability.

Cooking for three weeks.

* refs/heads/t/wma_improvements:
  wmadec: Use read_u32_be().
  wma_afh.c: Remove condition which is always true.
  imdct.c: Replace pointless macro PASS.
  wma_common.c: Remove pointless assignment.
  wma_afh.c: Use DIV_ROUND_UP().

NEWS.md
bitstream.c
bitstream.h
imdct.c
wma_afh.c
wma_common.c
wmadec_filter.c

diff --git a/NEWS.md b/NEWS.md
index ae0c14b5d57c72e046e13d7fd0c129adf6fe46fb..df1a80e352c19edd24dba2683aff1f5c4fd4db5d 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -25,6 +25,7 @@ NEWS
 - The DESTDIR make variable is honored to prepend a path to the
   installation directory. This feature is orthogonal to the --prefix
   option to configure.
+- Minor WMA cleanups.
 
 Downloads:
 [tarball](./releases/paraslash-git.tar.bz2),
index 638d19a3579b02053bd281e29e7f39d2bf54495c..9cd1273cfd578cf89492012b41cf236ecd32a38d 100644 (file)
@@ -19,6 +19,7 @@
 #include "error.h"
 #include "string.h"
 #include "wma.h"
+#include "portable_io.h"
 #include "bitstream.h"
 
 static inline uint32_t get_data(const void *table, int i, int size)
index 5875b0d090e6e8007d34766ee090950c819188dd..a6349861a55092fcdc1f957d7570621fd51e6834 100644 (file)
@@ -36,8 +36,8 @@ struct vlc {
 static inline uint32_t show_bits(struct getbit_context *gbc, int num)
 {
        int idx = gbc->index;
-       const uint8_t *p = gbc->buffer + (idx >> 3);
-       uint32_t x = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
+       const char *p = (const char *)gbc->buffer + (idx >> 3);
+       uint32_t x = read_u32_be(p);
        return (x << (idx & 7)) >> (32 - num);
 }
 
diff --git a/imdct.c b/imdct.c
index d2a0681898b6497f2742e842d3b9ef1ed104621a..5791353b5a2d0c806f58229fd6861f3561b7e0c6 100644 (file)
--- a/imdct.c
+++ b/imdct.c
@@ -141,28 +141,26 @@ __a_const static int split_radix_permutation(int i, int n)
 }
 
 /* z[0...8n - 1], w[1...2n - 1] */
-#define PASS(name)\
-static void name(struct fft_complex *z, const fftsample_t *wre, unsigned int n)\
-{\
-       fftsample_t t1, t2, t3, t4, t5, t6;\
-       int o1 = 2 * n;\
-       int o2 = 4 * n;\
-       int o3 = 6 * n;\
-       const fftsample_t *wim = wre + o1;\
-       n--;\
-\
-       TRANSFORM_ZERO(z[0], z[o1], z[o2], z[o3]);\
-       TRANSFORM(z[1], z[o1 + 1], z[o2 + 1], z[o3 + 1], wre[1], wim[-1]);\
-       do {\
-               z += 2;\
-               wre += 2;\
-               wim -= 2;\
-               TRANSFORM(z[0], z[o1], z[o2], z[o3], wre[0], wim[0]);\
-               TRANSFORM(z[1], z[o1 + 1], z[o2 + 1], z[o3 + 1], wre[1], wim[-1]);\
-       } while (--n);\
+static void pass(struct fft_complex *z, const fftsample_t *wre, unsigned int n)
+{
+       fftsample_t t1, t2, t3, t4, t5, t6;
+       int o1 = 2 * n;
+       int o2 = 4 * n;
+       int o3 = 6 * n;
+       const fftsample_t *wim = wre + o1;
+
+       n--;
+       TRANSFORM_ZERO(z[0], z[o1], z[o2], z[o3]);
+       TRANSFORM(z[1], z[o1 + 1], z[o2 + 1], z[o3 + 1], wre[1], wim[-1]);
+       do {
+               z += 2;
+               wre += 2;
+               wim -= 2;
+               TRANSFORM(z[0], z[o1], z[o2], z[o3], wre[0], wim[0]);
+               TRANSFORM(z[1], z[o1 + 1], z[o2 + 1], z[o3 + 1], wre[1], wim[-1]);
+       } while (--n);
 }
 
-PASS(pass)
 #undef BUTTERFLIES
 #define BUTTERFLIES BUTTERFLIES_BIG
 
index 4c9d87e047af8d1d5873096db54ab4a9d17ab966..0d543195151922a27e4f5d7a72749e26f0ad34cc 100644 (file)
--- a/wma_afh.c
+++ b/wma_afh.c
@@ -38,8 +38,7 @@ static int count_frames(const char *buf, int buf_size, uint32_t packet_size,
                sfc++;
        }
        PARA_INFO_LOG("%d frames, %d superframes\n", fc, sfc);
-       if (num_superframes)
-               *num_superframes = sfc;
+       *num_superframes = sfc;
        return fc;
 }
 
@@ -68,7 +67,7 @@ static int put_utf8(uint32_t val, char *result)
                *out++ = in;
                return 1;
        }
-       bytes = (wma_log2(in) + 4) / 5;
+       bytes = DIV_ROUND_UP(wma_log2(in), 5);
        shift = (bytes - 1) * 6;
        *out++ = (256 - (256 >> bytes)) | (in >> shift);
        while (shift >= 6) {
index 6d57c00be2d2627624f5642a74948723bc2726fb..fcaf3ce4574de8297a7bffa4c53bf09658ea6982 100644 (file)
@@ -178,7 +178,5 @@ __a_const int wma_log2(unsigned int v)
                v >>= 8;
                n += 8;
        }
-       n += log2_tab[v];
-
-       return n;
+       return n + log2_tab[v];
 }
index 4c7c047a482e2b3f256cfb8c12dcd6b4de3a7500..692ea0f3dde1d25996a874aff00e1a6a1f7b043d 100644 (file)
@@ -29,6 +29,7 @@
 #include "sched.h"
 #include "buffer_tree.h"
 #include "filter.h"
+#include "portable_io.h"
 #include "bitstream.h"
 #include "imdct.h"
 #include "wma.h"