]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - wmadec_filter.c
Kill pwd->coefs_start.
[paraslash.git] / wmadec_filter.c
index eea2750b82d9a4040c5f63ae6da01db65a50ecd8..802cb8256fa30f66698f765c4cdab004cd3abb8f 100644 (file)
 struct private_wmadec_data {
        struct asf_header_info ahi;
        struct getbit_context gb;
+       /** Whether to use the bit reservoir. */
        int use_bit_reservoir;
+       /** Whether to use variable block length. */
        int use_variable_block_len;
-       int use_exp_vlc;        ///< exponent coding: 0 = lsp, 1 = vlc + delta
-       int use_noise_coding;   ///< true if perceptual noise is added
+       /** Whether to use exponent coding. */
+       int use_exp_vlc;
+       /** Whether perceptual noise is added. */
+       int use_noise_coding;
        int byte_offset_bits;
        struct vlc exp_vlc;
        int exponent_sizes[BLOCK_NB_SIZES];
        uint16_t exponent_bands[BLOCK_NB_SIZES][25];
-       int high_band_start[BLOCK_NB_SIZES];    ///< index of first coef in high band
-       int coefs_start;        ///< first coded coef
+       /** The index of the first coef in high band. */
+       int high_band_start[BLOCK_NB_SIZES];
        int coefs_end[BLOCK_NB_SIZES];  ///< max number of coded coefficients
        int exponent_high_sizes[BLOCK_NB_SIZES];
        int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE];
@@ -208,7 +212,6 @@ static void compute_scale_factor_band_sizes(struct private_wmadec_data *pwd,
        int a, b, pos, lpos, k, block_len, i, j, n;
        const uint8_t *table;
 
-       pwd->coefs_start = 0;
        for (k = 0; k < pwd->nb_block_sizes; k++) {
                block_len = pwd->frame_len >> k;
 
@@ -745,51 +748,29 @@ static void compute_mdct_coefficients(struct private_wmadec_data *pwd,
                coefs = pwd->coefs[ch];
                if (!pwd->use_noise_coding) {
                        /* XXX: optimize more */
-                       for (i = 0; i < pwd->coefs_start; i++)
-                               *coefs++ = 0.0;
                        n = nb_coefs[ch];
-                       for (i = 0; i < n; i++) {
-                               *coefs++ =
-                                   coefs1[i] *
-                                   exponents[i << bsize >> esize] *
-                                   mult;
-                       }
+                       for (i = 0; i < n; i++)
+                               *coefs++ = coefs1[i] *
+                                       exponents[i << bsize >> esize] * mult;
                        n = pwd->block_len - pwd->coefs_end[bsize];
                        for (i = 0; i < n; i++)
                                *coefs++ = 0.0;
                        continue;
                }
                mult1 = mult;
-               /* very low freqs : noise */
-               for (i = 0; i < pwd->coefs_start; i++) {
-                       *coefs++ =
-                           pwd->noise_table[pwd->noise_index] *
-                           exponents[i << bsize >> esize] *
-                           mult1;
-                       pwd->noise_index =
-                           (pwd->noise_index +
-                            1) & (NOISE_TAB_SIZE - 1);
-               }
-
                n1 = pwd->exponent_high_sizes[bsize];
-
                /* compute power of high bands */
                exponents = pwd->exponents[ch] +
-                   (pwd->high_band_start[bsize] << bsize);
-               last_high_band = 0;     /* avoid warning */
+                       (pwd->high_band_start[bsize] << bsize);
+               last_high_band = 0; /* avoid warning */
                for (j = 0; j < n1; j++) {
-                       n = pwd->exponent_high_bands[pwd->
-                                                  frame_len_bits
-                                                  -
-                                                  pwd->
-                                                  block_len_bits]
-                           [j];
+                       n = pwd->exponent_high_bands[
+                               pwd->frame_len_bits - pwd->block_len_bits][j];
                        if (pwd->high_band_coded[ch][j]) {
                                float e2, val;
                                e2 = 0;
                                for (i = 0; i < n; i++) {
-                                       val = exponents[i << bsize
-                                                     >> esize];
+                                       val = exponents[i << bsize >> esize];
                                        e2 += val * val;
                                }
                                exp_power[j] = e2 / n;
@@ -797,89 +778,51 @@ static void compute_mdct_coefficients(struct private_wmadec_data *pwd,
                        }
                        exponents += n << bsize;
                }
-
                /* main freqs and high freqs */
-               exponents =
-                   pwd->exponents[ch] +
-                   (pwd->coefs_start << bsize);
+               exponents = pwd->exponents[ch];
                for (j = -1; j < n1; j++) {
-                       if (j < 0) {
-                               n = pwd->high_band_start[bsize] -
-                                   pwd->coefs_start;
-                       } else {
-                               n = pwd->exponent_high_bands[pwd->
-                                                          frame_len_bits
-                                                          -
-                                                          pwd->
-                                                          block_len_bits]
-                                   [j];
-                       }
+                       if (j < 0)
+                               n = pwd->high_band_start[bsize];
+                       else
+                               n = pwd->exponent_high_bands[pwd->frame_len_bits
+                                       - pwd->block_len_bits][j];
                        if (j >= 0 && pwd->high_band_coded[ch][j]) {
                                /* use noise with specified power */
-                               mult1 =
-                                   sqrt(exp_power[j] /
-                                        exp_power
-                                        [last_high_band]);
+                               mult1 = sqrt(exp_power[j]
+                                       / exp_power[last_high_band]);
                                /* XXX: use a table */
-                               mult1 =
-                                   mult1 * pow(10,
-                                               pwd->
-                                               high_band_values
-                                               [ch][j] * 0.05);
-                               mult1 =
-                                   mult1 /
-                                   (pwd->max_exponent[ch] *
-                                    pwd->noise_mult);
+                               mult1 = mult1 * pow(10,
+                                       pwd->high_band_values[ch][j] * 0.05);
+                               mult1 /= (pwd->max_exponent[ch] * pwd->noise_mult);
                                mult1 *= mdct_norm;
                                for (i = 0; i < n; i++) {
-                                       noise =
-                                           pwd->noise_table[pwd->
-                                                          noise_index];
-                                       pwd->noise_index =
-                                           (pwd->noise_index +
-                                            1) &
-                                           (NOISE_TAB_SIZE -
-                                            1);
-                                       *coefs++ =
-                                           noise *
-                                           exponents[i << bsize
-                                                     >> esize]
-                                           * mult1;
+                                       noise = pwd->noise_table[pwd->noise_index];
+                                       pwd->noise_index = (pwd->noise_index + 1)
+                                               & (NOISE_TAB_SIZE - 1);
+                                       *coefs++ = noise * exponents[
+                                               i << bsize >> esize] * mult1;
                                }
                                exponents += n << bsize;
                        } else {
                                /* coded values + small noise */
                                for (i = 0; i < n; i++) {
-                                       noise =
-                                           pwd->noise_table[pwd->
-                                                          noise_index];
-                                       pwd->noise_index =
-                                           (pwd->noise_index +
-                                            1) &
-                                           (NOISE_TAB_SIZE -
-                                            1);
-                                       *coefs++ =
-                                           ((*coefs1++) +
-                                            noise) *
-                                           exponents[i << bsize
-                                                     >> esize]
-                                           * mult;
+                                       noise = pwd->noise_table[pwd->noise_index];
+                                       pwd->noise_index = (pwd->noise_index + 1)
+                                               & (NOISE_TAB_SIZE - 1);
+                                       *coefs++ = ((*coefs1++) + noise) *
+                                               exponents[i << bsize >> esize]
+                                               * mult;
                                }
                                exponents += n << bsize;
                        }
                }
-
-               /* very high freqs : noise */
+               /* very high freqs: noise */
                n = pwd->block_len - pwd->coefs_end[bsize];
-               mult1 =
-                   mult * exponents[((-1 << bsize)) >> esize];
+               mult1 = mult * exponents[((-1 << bsize)) >> esize];
                for (i = 0; i < n; i++) {
-                       *coefs++ =
-                           pwd->noise_table[pwd->noise_index] *
-                           mult1;
-                       pwd->noise_index =
-                           (pwd->noise_index +
-                            1) & (NOISE_TAB_SIZE - 1);
+                       *coefs++ = pwd->noise_table[pwd->noise_index] * mult1;
+                       pwd->noise_index = (pwd->noise_index + 1)
+                               & (NOISE_TAB_SIZE - 1);
                }
        }
 }
@@ -945,8 +888,10 @@ static int wma_decode_block(struct private_wmadec_data *pwd)
        if (!v)
                goto next;
 
-       /* read total gain and extract corresponding number of bits for
-          coef escape coding */
+       /*
+        * Read total gain and extract corresponding number of bits for coef
+        * escape coding.
+        */
        total_gain = 1;
        for (;;) {
                int a = get_bits(&pwd->gb, 7);
@@ -958,7 +903,7 @@ static int wma_decode_block(struct private_wmadec_data *pwd)
        coef_nb_bits = wma_total_gain_to_bits(total_gain);
 
        /* compute number of coefficients */
-       n = pwd->coefs_end[bsize] - pwd->coefs_start;
+       n = pwd->coefs_end[bsize];
        for (ch = 0; ch < pwd->ahi.channels; ch++)
                nb_coefs[ch] = n;
 
@@ -1028,13 +973,10 @@ static int wma_decode_block(struct private_wmadec_data *pwd)
                                break;
                }
        }
-
        compute_mdct_coefficients(pwd, bsize, total_gain, nb_coefs);
-
        if (pwd->ms_stereo && pwd->channel_coded[1]) {
                float a, b;
                int i;
-
                /*
                 * Nominal case for ms stereo: we do it before mdct.
                 *
@@ -1053,7 +995,6 @@ static int wma_decode_block(struct private_wmadec_data *pwd)
                        pwd->coefs[1][i] = a - b;
                }
        }
-
 next:
        for (ch = 0; ch < pwd->ahi.channels; ch++) {
                int n4, index;