From: Andre Noll Date: Fri, 21 Apr 2017 15:07:00 +0000 (+0200) Subject: Merge branch 'refs/heads/t/wma_improvements' X-Git-Tag: v0.6.0~8 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=674f20dd3fc5339a1e7a9f25c5e4a987aaf13d3c;hp=40b1bbc50682effec5cf18b0923cfab24e154245 Merge branch 'refs/heads/t/wma_improvements' 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(). --- diff --git a/NEWS.md b/NEWS.md index ae0c14b5..df1a80e3 100644 --- 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), diff --git a/bitstream.c b/bitstream.c index 638d19a3..9cd1273c 100644 --- a/bitstream.c +++ b/bitstream.c @@ -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) diff --git a/bitstream.h b/bitstream.h index 5875b0d0..a6349861 100644 --- a/bitstream.h +++ b/bitstream.h @@ -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 d2a06818..5791353b 100644 --- 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 diff --git a/wma_afh.c b/wma_afh.c index 4c9d87e0..0d543195 100644 --- 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) { diff --git a/wma_common.c b/wma_common.c index 6d57c00b..fcaf3ce4 100644 --- a/wma_common.c +++ b/wma_common.c @@ -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]; } diff --git a/wmadec_filter.c b/wmadec_filter.c index 4c7c047a..692ea0f3 100644 --- a/wmadec_filter.c +++ b/wmadec_filter.c @@ -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"