From b6fb7ef023664c3276c8113f4a3622e9f09a1430 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 11 Jun 2017 18:10:39 +0200 Subject: [PATCH] wma: Simplify init_coef_vlc(). This function of wmadec_filter.c was unnecessarily convoluted. The patched version should be equivalent, and easier to understand. This also allows to get rid of ->coef_vlcs of struct private_wmadec_data, which was utterly confusing since we also have ->coef_vlc. --- wmadec_filter.c | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/wmadec_filter.c b/wmadec_filter.c index 13f19464..7b4b1a28 100644 --- a/wmadec_filter.c +++ b/wmadec_filter.c @@ -81,7 +81,6 @@ struct private_wmadec_data { struct vlc coef_vlc[2]; uint16_t *run_table[2]; uint16_t *level_table[2]; - const struct coef_vlc_table *coef_vlcs[2]; /** Frame length in samples. */ int frame_len; /** log2 of frame_len. */ @@ -159,34 +158,27 @@ static void sine_window_init(float *window, int n) window[i] = sinf((i + 0.5) * (M_PI / (2.0 * n))); } -static void init_coef_vlc(struct vlc *vlc, uint16_t **prun_table, - uint16_t **plevel_table, const struct coef_vlc_table *vlc_table) +static void init_coef_vlc(struct private_wmadec_data *pwd, int sidx, int didx) { - int n = vlc_table->n; - const uint8_t *table_bits = vlc_table->huffbits; - const uint32_t *table_codes = vlc_table->huffcodes; - const uint16_t *levels_table = vlc_table->levels; - uint16_t *run_table, *level_table; - int i, l, j, k, level; + const struct coef_vlc_table *src = coef_vlcs + sidx; + struct vlc *dst = pwd->coef_vlc + didx; + int i, l, j, k, level, n = src->n; - init_vlc(vlc, VLCBITS, n, table_bits, table_codes, 4); - - run_table = para_malloc(n * sizeof(uint16_t)); - level_table = para_malloc(n * sizeof(uint16_t)); + init_vlc(dst, VLCBITS, n, src->huffbits, src->huffcodes, 4); + pwd->run_table[didx] = para_malloc(n * sizeof(uint16_t)); + pwd->level_table[didx] = para_malloc(n * sizeof(uint16_t)); i = 2; level = 1; k = 0; while (i < n) { - l = levels_table[k++]; + l = src->levels[k++]; for (j = 0; j < l; j++) { - run_table[i] = j; - level_table[i] = level; + pwd->run_table[didx][i] = j; + pwd->level_table[didx][i] = level; i++; } level++; } - *prun_table = run_table; - *plevel_table = level_table; } /* compute the scale factor band sizes for each MDCT block size */ @@ -396,19 +388,15 @@ static int wma_init(struct private_wmadec_data *pwd) } /* choose the VLC tables for the coefficients */ - coef_vlc_table = 2; + coef_vlc_table = 4; if (ahi->sample_rate >= 32000) { if (bps1 < 0.72) coef_vlc_table = 0; else if (bps1 < 1.16) - coef_vlc_table = 1; + coef_vlc_table = 2; } - pwd->coef_vlcs[0] = &coef_vlcs[coef_vlc_table * 2]; - pwd->coef_vlcs[1] = &coef_vlcs[coef_vlc_table * 2 + 1]; - init_coef_vlc(&pwd->coef_vlc[0], &pwd->run_table[0], &pwd->level_table[0], - pwd->coef_vlcs[0]); - init_coef_vlc(&pwd->coef_vlc[1], &pwd->run_table[1], &pwd->level_table[1], - pwd->coef_vlcs[1]); + init_coef_vlc(pwd, coef_vlc_table, 0); + init_coef_vlc(pwd, coef_vlc_table + 1, 1); return 0; } -- 2.39.2