Merge branch 'refs/heads/t/wmadec'
authorAndre Noll <maan@tuebingen.mpg.de>
Thu, 5 May 2016 13:37:51 +0000 (15:37 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Thu, 5 May 2016 13:39:13 +0000 (15:39 +0200)
This topic branch was cooking in next for two months.

* refs/heads/t/wmadec:
  wmadec: Simplify wma_lsp_to_curve_init().
  wmadec: Make pwd->reset_block_lengths a boolean.
  bitstream.h: Remove some superflous parentheses.
  wmadec: Simplify get_vlc().

NEWS.md
bitstream.c
bitstream.h
wmadec_filter.c

diff --git a/NEWS.md b/NEWS.md
index d81525520be138ebeaad63e9cdb5359014e60fcb..6ea6ecfe9414f53b4768e46778b0552a1dd65fdd 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -19,6 +19,7 @@ not mentioned here have accumulated and are also part of the release.
 - New option --priority for para_server and para_audiod.
 - New mood methods: image_id and lyrics_id.
 - The manual and this NEWS file have been converted to markdown.
+- Cleanup of the wma decoder and bitstream code.
 
 Download: [tarball](./releases/paraslash-git.tar.bz2)
 
index 1593b99ee5bda9fe6f7e47b6ab63c445a10ad529..638d19a3579b02053bd281e29e7f39d2bf54495c 100644 (file)
@@ -166,29 +166,26 @@ void free_vlc(struct vlc *vlc)
  * \param gbc The getbit context structure.
  * \param table The vlc tables to use.
  * \param bits The number of bits which will be read at once.
- * \param max_depth The number of times \a bits bits must be read to completely
- * read the longest vlc code = (max_vlc_length + bits - 1) / bits.
  *
  * The \a bits parameter must be identical to the \a nb_bits value supplied to
  * \ref init_vlc().
  *
  * \return The vlc code.
  */
-int get_vlc(struct getbit_context *gbc, VLC_TYPE(*table)[2], int bits,
-               int max_depth)
+int get_vlc(struct getbit_context *gbc, VLC_TYPE(*table)[2], int bits)
 {
        int n, idx, nb_bits, code;
 
        idx = show_bits(gbc, bits);
        code = table[idx][0];
        n = table[idx][1];
-       if (max_depth > 1 && n < 0) {
+       if (n < 0) {
                skip_bits(gbc, bits);
                nb_bits = -n;
                idx = show_bits(gbc, nb_bits) + code;
                code = table[idx][0];
                n = table[idx][1];
-               if (max_depth > 2 && n < 0) {
+               if (n < 0) {
                        skip_bits(gbc, nb_bits);
                        nb_bits = -n;
                        idx = show_bits(gbc, nb_bits) + code;
index 5890d08c89d4033f7fefb9a19be525860a701d77..5875b0d090e6e8007d34766ee090950c819188dd 100644 (file)
@@ -37,7 +37,7 @@ 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]);
+       uint32_t x = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
        return (x << (idx & 7)) >> (32 - num);
 }
 
@@ -62,7 +62,7 @@ static inline unsigned int get_bits(struct getbit_context *gbc, int n)
 static inline unsigned int get_bit(struct getbit_context *gbc)
 {
        int idx = gbc->index++;
-       uint8_t tmp = gbc->buffer[idx >> 3], mask = (1 << (7 - (idx & 7)));
+       uint8_t tmp = gbc->buffer[idx >> 3], mask = 1 << (7 - (idx & 7));
        return !!(tmp & mask);
 }
 
@@ -88,5 +88,4 @@ static inline void init_get_bits(struct getbit_context *gbc,
 void init_vlc(struct vlc *vlc, int nb_bits, int nb_codes, const void *bits,
                const void *codes, int codes_size);
 void free_vlc(struct vlc *vlc);
-int get_vlc(struct getbit_context *gbc, VLC_TYPE(*table)[2], int bits,
-               int max_depth);
+int get_vlc(struct getbit_context *gbc, VLC_TYPE(*table)[2], int bits);
index 6b7251ee06338d1c1b50b4cd5eb674a6958ee0c0..be638ced7ad5e9d991ff109f7eaf5c68d4b800c3 100644 (file)
@@ -88,8 +88,8 @@ struct private_wmadec_data {
        int frame_len_bits;
        /** Number of block sizes, one if !ahi->use_variable_block_len. */
        int nb_block_sizes;
-       /* block info */
-       int reset_block_lengths;
+       /* Whether to update block lengths from getbit context. */
+       bool reset_block_lengths;
        /** log2 of current block length. */
        int block_len_bits;
        /** log2 of next block length. */
@@ -131,13 +131,8 @@ struct private_wmadec_data {
 };
 
 #define EXPVLCBITS 8
-#define EXPMAX DIV_ROUND_UP(19, EXPVLCBITS)
-
 #define HGAINVLCBITS 9
-#define HGAINMAX DIV_ROUND_UP(13, HGAINVLCBITS)
-
 #define VLCBITS 9
-#define VLCMAX DIV_ROUND_UP(22, VLCBITS)
 
 /** \cond sine_winows */
 
@@ -396,7 +391,7 @@ static int wma_init(struct private_wmadec_data *pwd)
                pwd->windows[i] = sine_windows[pwd->frame_len_bits - i - 7];
        }
 
-       pwd->reset_block_lengths = 1;
+       pwd->reset_block_lengths = true;
 
        if (pwd->use_noise_coding) {
                /* init the noise generator */
@@ -434,13 +429,13 @@ static int wma_init(struct private_wmadec_data *pwd)
        return 0;
 }
 
-static void wma_lsp_to_curve_init(struct private_wmadec_data *pwd, int frame_len)
+static void wma_lsp_to_curve_init(struct private_wmadec_data *pwd)
 {
        float wdel, a, b;
        int i, e, m;
 
-       wdel = M_PI / frame_len;
-       for (i = 0; i < frame_len; i++)
+       wdel = M_PI / pwd->frame_len;
+       for (i = 0; i < pwd->frame_len; i++)
                pwd->lsp_cos_table[i] = 2.0f * cos(wdel * i);
 
        /* tables for x^-0.25 computation */
@@ -496,7 +491,7 @@ static int wma_decode_init(char *initial_buf, int len, struct private_wmadec_dat
                        wma_scale_huffbits, wma_scale_huffcodes, 4);
        } else {
                PARA_INFO_LOG("using curve\n");
-               wma_lsp_to_curve_init(pwd, pwd->frame_len);
+               wma_lsp_to_curve_init(pwd);
        }
        *result = pwd;
        return pwd->ahi.header_len;
@@ -586,7 +581,7 @@ static int decode_exp_vlc(struct private_wmadec_data *pwd, int ch)
        last_exp = 36;
 
        while (q < q_end) {
-               code = get_vlc(&pwd->gb, pwd->exp_vlc.table, EXPVLCBITS, EXPMAX);
+               code = get_vlc(&pwd->gb, pwd->exp_vlc.table, EXPVLCBITS);
                if (code < 0)
                        return code;
                /* NOTE: this offset is the same as MPEG4 AAC ! */
@@ -714,8 +709,7 @@ static int compute_high_band_values(struct private_wmadec_data *pwd,
                                val = get_bits(&pwd->gb, 7) - 19;
                        else {
                                int code = get_vlc(&pwd->gb,
-                                       pwd->hgain_vlc.table, HGAINVLCBITS,
-                                       HGAINMAX);
+                                       pwd->hgain_vlc.table, HGAINVLCBITS);
                                if (code < 0)
                                        return code;
                                val += code - 18;
@@ -840,7 +834,7 @@ static int wma_decode_block(struct private_wmadec_data *pwd)
                n = wma_log2(pwd->nb_block_sizes - 1) + 1;
 
                if (pwd->reset_block_lengths) {
-                       pwd->reset_block_lengths = 0;
+                       pwd->reset_block_lengths = false;
                        v = get_bits(&pwd->gb, n);
                        if (v >= pwd->nb_block_sizes)
                                return -E_WMA_BLOCK_SIZE;
@@ -946,8 +940,7 @@ static int wma_decode_block(struct private_wmadec_data *pwd)
                eptr = ptr + nb_coefs[ch];
                memset(ptr, 0, pwd->block_len * sizeof(int16_t));
                for (;;) {
-                       code = get_vlc(&pwd->gb, coef_vlc->table,
-                               VLCBITS, VLCMAX);
+                       code = get_vlc(&pwd->gb, coef_vlc->table, VLCBITS);
                        if (code < 0)
                                return code;
                        if (code == 1) /* EOB */
@@ -1136,7 +1129,7 @@ static int wma_decode_superframe(struct private_wmadec_data *pwd, void *data,
                if (len > 0)
                        skip_bits(&pwd->gb, len);
 
-               pwd->reset_block_lengths = 1;
+               pwd->reset_block_lengths = true;
                for (i = 0; i < nb_frames; i++) {
                        ret = wma_decode_frame(pwd, samples);
                        if (ret < 0)