]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
wma: Move computation of high band values to a separate function.
authorAndre Noll <maan@systemlinux.org>
Sat, 7 Nov 2009 14:24:54 +0000 (15:24 +0100)
committerAndre Noll <maan@systemlinux.org>
Wed, 18 Nov 2009 18:34:29 +0000 (19:34 +0100)
wmadec_filter.c

index 16b9894ca5420bf226731d6330a5d21121ccbcdc..8c9132ebdc9e25994d00172cea4ff13d5f54ea45 100644 (file)
@@ -678,6 +678,61 @@ static int wma_total_gain_to_bits(int total_gain)
                return 9;
 }
 
+static int compute_high_band_values(struct private_wmadec_data *pwd,
+               int bsize, int nb_coefs[MAX_CHANNELS])
+{
+       int ch;
+
+       if (pwd->use_noise_coding) {
+               for (ch = 0; ch < pwd->ahi.channels; ch++) {
+                       if (pwd->channel_coded[ch]) {
+                               int i, m, a;
+                               m = pwd->exponent_high_sizes[bsize];
+                               for (i = 0; i < m; i++) {
+                                       a = get_bit(&pwd->gb);
+                                       pwd->high_band_coded[ch][i] = a;
+                                       /* if noise coding, the coefficients are not transmitted */
+                                       if (a)
+                                               nb_coefs[ch] -=
+                                                   pwd->
+                                                   exponent_high_bands[bsize]
+                                                   [i];
+                               }
+                       }
+               }
+               for (ch = 0; ch < pwd->ahi.channels; ch++) {
+                       if (pwd->channel_coded[ch]) {
+                               int i, n, val;
+
+                               n = pwd->exponent_high_sizes[bsize];
+                               val = (int) 0x80000000;
+                               for (i = 0; i < n; i++) {
+                                       if (pwd->high_band_coded[ch][i]) {
+                                               if (val == (int) 0x80000000) {
+                                                       val =
+                                                           get_bits(&pwd->gb,
+                                                                    7) - 19;
+                                               } else {
+                                                       int code =
+                                                           get_vlc(&pwd->gb,
+                                                                    pwd->
+                                                                    hgain_vlc.
+                                                                    table,
+                                                                    HGAINVLCBITS,
+                                                                    HGAINMAX);
+                                                       if (code < 0)
+                                                               return -1;
+                                                       val += code - 18;
+                                               }
+                                               pwd->high_band_values[ch][i] =
+                                                   val;
+                                       }
+                               }
+                       }
+               }
+       }
+       return 1;
+}
 /**
  * @return 0 if OK. 1 if last block of frame. return -1 if
  * unrecorrable error.
@@ -757,55 +812,8 @@ static int wma_decode_block(struct private_wmadec_data *pwd)
        for (ch = 0; ch < pwd->ahi.channels; ch++)
                nb_coefs[ch] = n;
 
-       /* complex coding */
-       if (pwd->use_noise_coding) {
-               for (ch = 0; ch < pwd->ahi.channels; ch++) {
-                       if (pwd->channel_coded[ch]) {
-                               int i, m, a;
-                               m = pwd->exponent_high_sizes[bsize];
-                               for (i = 0; i < m; i++) {
-                                       a = get_bit(&pwd->gb);
-                                       pwd->high_band_coded[ch][i] = a;
-                                       /* if noise coding, the coefficients are not transmitted */
-                                       if (a)
-                                               nb_coefs[ch] -=
-                                                   pwd->
-                                                   exponent_high_bands[bsize]
-                                                   [i];
-                               }
-                       }
-               }
-               for (ch = 0; ch < pwd->ahi.channels; ch++) {
-                       if (pwd->channel_coded[ch]) {
-                               int i, val;
-
-                               n = pwd->exponent_high_sizes[bsize];
-                               val = (int) 0x80000000;
-                               for (i = 0; i < n; i++) {
-                                       if (pwd->high_band_coded[ch][i]) {
-                                               if (val == (int) 0x80000000) {
-                                                       val =
-                                                           get_bits(&pwd->gb,
-                                                                    7) - 19;
-                                               } else {
-                                                       code =
-                                                           get_vlc(&pwd->gb,
-                                                                    pwd->
-                                                                    hgain_vlc.
-                                                                    table,
-                                                                    HGAINVLCBITS,
-                                                                    HGAINMAX);
-                                                       if (code < 0)
-                                                               return -1;
-                                                       val += code - 18;
-                                               }
-                                               pwd->high_band_values[ch][i] =
-                                                   val;
-                                       }
-                               }
-                       }
-               }
-       }
+       if (compute_high_band_values(pwd, bsize, nb_coefs) < 0)
+               return -1;
 
        /* exponents can be reused in short blocks. */
        if ((pwd->block_len_bits == pwd->frame_len_bits) || get_bit(&pwd->gb)) {