]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/wmadec.c
Fix svq3_* function declarations.
[ffmpeg] / libavcodec / wmadec.c
index ce2940d24d0fdc9dfa828837560f47bd3bd284a9..958e18553485ef2d378435a39e8f99d38cd49c90 100644 (file)
@@ -240,8 +240,8 @@ static void decode_exp_lsp(WMACodecContext *s, int ch)
                      s->block_len, lsp_coefs);
 }
 
-/** pow(10, i / 16.0) for i in -60..67 */
-static const float pow_tab[128] = {
+/** pow(10, i / 16.0) for i in -60..95 */
+static const float pow_tab[] = {
     1.7782794100389e-04, 2.0535250264571e-04,
     2.3713737056617e-04, 2.7384196342644e-04,
     3.1622776601684e-04, 3.6517412725484e-04,
@@ -306,6 +306,20 @@ static const float pow_tab[128] = {
     7.4989420933246e+03, 8.6596432336007e+03,
     1.0000000000000e+04, 1.1547819846895e+04,
     1.3335214321633e+04, 1.5399265260595e+04,
+    1.7782794100389e+04, 2.0535250264571e+04,
+    2.3713737056617e+04, 2.7384196342644e+04,
+    3.1622776601684e+04, 3.6517412725484e+04,
+    4.2169650342858e+04, 4.8696752516586e+04,
+    5.6234132519035e+04, 6.4938163157621e+04,
+    7.4989420933246e+04, 8.6596432336007e+04,
+    1.0000000000000e+05, 1.1547819846895e+05,
+    1.3335214321633e+05, 1.5399265260595e+05,
+    1.7782794100389e+05, 2.0535250264571e+05,
+    2.3713737056617e+05, 2.7384196342644e+05,
+    3.1622776601684e+05, 3.6517412725484e+05,
+    4.2169650342858e+05, 4.8696752516586e+05,
+    5.6234132519035e+05, 6.4938163157621e+05,
+    7.4989420933246e+05, 8.6596432336007e+05,
 };
 
 /**
@@ -315,39 +329,54 @@ static int decode_exp_vlc(WMACodecContext *s, int ch)
 {
     int last_exp, n, code;
     const uint16_t *ptr;
-    float v, *q, max_scale, *q_end;
+    float v, max_scale;
+    uint32_t *q, *q_end, iv;
     const float *ptab = pow_tab + 60;
+    const uint32_t *iptab = (const uint32_t*)ptab;
 
     ptr = s->exponent_bands[s->frame_len_bits - s->block_len_bits];
-    q = s->exponents[ch];
+    q = (uint32_t *)s->exponents[ch];
     q_end = q + s->block_len;
     max_scale = 0;
     if (s->version == 1) {
         last_exp = get_bits(&s->gb, 5) + 10;
         v = ptab[last_exp];
+        iv = iptab[last_exp];
         max_scale = v;
         n = *ptr++;
-        do {
-            *q++ = v;
-        } while (--n);
+        switch (n & 3) do {
+        case 0: *q++ = iv;
+        case 3: *q++ = iv;
+        case 2: *q++ = iv;
+        case 1: *q++ = iv;
+        } while ((n -= 4) > 0);
     }else
         last_exp = 36;
 
     while (q < q_end) {
         code = get_vlc2(&s->gb, s->exp_vlc.table, EXPVLCBITS, EXPMAX);
-        if (code < 0)
+        if (code < 0){
+            av_log(s->avctx, AV_LOG_ERROR, "Exponent vlc invalid\n");
             return -1;
+        }
         /* NOTE: this offset is the same as MPEG4 AAC ! */
         last_exp += code - 60;
-        if ((unsigned)last_exp + 60 > FF_ARRAY_ELEMS(pow_tab))
+        if ((unsigned)last_exp + 60 > FF_ARRAY_ELEMS(pow_tab)) {
+            av_log(s->avctx, AV_LOG_ERROR, "Exponent out of range: %d\n",
+                   last_exp);
             return -1;
+        }
         v = ptab[last_exp];
+        iv = iptab[last_exp];
         if (v > max_scale)
             max_scale = v;
         n = *ptr++;
-        do {
-            *q++ = v;
-        } while (--n);
+        switch (n & 3) do {
+        case 0: *q++ = iv;
+        case 3: *q++ = iv;
+        case 2: *q++ = iv;
+        case 1: *q++ = iv;
+        } while ((n -= 4) > 0);
     }
     s->max_exponent[ch] = max_scale;
     return 0;
@@ -430,12 +459,16 @@ static int wma_decode_block(WMACodecContext *s)
         if (s->reset_block_lengths) {
             s->reset_block_lengths = 0;
             v = get_bits(&s->gb, n);
-            if (v >= s->nb_block_sizes)
+            if (v >= s->nb_block_sizes){
+                av_log(s->avctx, AV_LOG_ERROR, "prev_block_len_bits %d out of range\n", s->frame_len_bits - v);
                 return -1;
+            }
             s->prev_block_len_bits = s->frame_len_bits - v;
             v = get_bits(&s->gb, n);
-            if (v >= s->nb_block_sizes)
+            if (v >= s->nb_block_sizes){
+                av_log(s->avctx, AV_LOG_ERROR, "block_len_bits %d out of range\n", s->frame_len_bits - v);
                 return -1;
+            }
             s->block_len_bits = s->frame_len_bits - v;
         } else {
             /* update block lengths */
@@ -443,8 +476,10 @@ static int wma_decode_block(WMACodecContext *s)
             s->block_len_bits = s->next_block_len_bits;
         }
         v = get_bits(&s->gb, n);
-        if (v >= s->nb_block_sizes)
+        if (v >= s->nb_block_sizes){
+            av_log(s->avctx, AV_LOG_ERROR, "next_block_len_bits %d out of range\n", s->frame_len_bits - v);
             return -1;
+        }
         s->next_block_len_bits = s->frame_len_bits - v;
     } else {
         /* fixed block len */
@@ -455,8 +490,10 @@ static int wma_decode_block(WMACodecContext *s)
 
     /* now check if the block length is coherent with the frame length */
     s->block_len = 1 << s->block_len_bits;
-    if ((s->block_pos + s->block_len) > s->frame_len)
+    if ((s->block_pos + s->block_len) > s->frame_len){
+        av_log(s->avctx, AV_LOG_ERROR, "frame_len overflow\n");
         return -1;
+    }
 
     if (s->nb_channels == 2) {
         s->ms_stereo = get_bits1(&s->gb);
@@ -520,8 +557,10 @@ static int wma_decode_block(WMACodecContext *s)
                             val = get_bits(&s->gb, 7) - 19;
                         } else {
                             code = get_vlc2(&s->gb, s->hgain_vlc.table, HGAINVLCBITS, HGAINMAX);
-                            if (code < 0)
+                            if (code < 0){
+                                av_log(s->avctx, AV_LOG_ERROR, "hgain vlc invalid\n");
                                 return -1;
+                            }
                             val += code - 18;
                         }
                         s->high_band_values[ch][i] = val;
@@ -603,7 +642,7 @@ static int wma_decode_block(WMACodecContext *s)
 
                 /* compute power of high bands */
                 exponents = s->exponents[ch] +
-                    (s->high_band_start[bsize]<<bsize);
+                    (s->high_band_start[bsize]<<bsize>>esize);
                 last_high_band = 0; /* avoid warning */
                 for(j=0;j<n1;j++) {
                     n = s->exponent_high_bands[s->frame_len_bits -
@@ -619,11 +658,11 @@ static int wma_decode_block(WMACodecContext *s)
                         last_high_band = j;
                         tprintf(s->avctx, "%d: power=%f (%d)\n", j, exp_power[j], n);
                     }
-                    exponents += n<<bsize;
+                    exponents += n<<bsize>>esize;
                 }
 
                 /* main freqs and high freqs */
-                exponents = s->exponents[ch] + (s->coefs_start<<bsize);
+                exponents = s->exponents[ch] + (s->coefs_start<<bsize>>esize);
                 for(j=-1;j<n1;j++) {
                     if (j < 0) {
                         n = s->high_band_start[bsize] -
@@ -645,7 +684,7 @@ static int wma_decode_block(WMACodecContext *s)
                             *coefs++ =  noise *
                                 exponents[i<<bsize>>esize] * mult1;
                         }
-                        exponents += n<<bsize;
+                        exponents += n<<bsize>>esize;
                     } else {
                         /* coded values + small noise */
                         for(i = 0;i < n; i++) {
@@ -654,7 +693,7 @@ static int wma_decode_block(WMACodecContext *s)
                             *coefs++ = ((*coefs1++) + noise) *
                                 exponents[i<<bsize>>esize] * mult;
                         }
-                        exponents += n<<bsize;
+                        exponents += n<<bsize>>esize;
                     }
                 }
 
@@ -855,6 +894,7 @@ static int wma_decode_superframe(AVCodecContext *avctx,
         pos >>= 3;
         len = buf_size - pos;
         if (len > MAX_CODED_SUPERFRAME_SIZE || len < 0) {
+            av_log(s->avctx, AV_LOG_ERROR, "len %d invalid\n", len);
             goto fail;
         }
         s->last_superframe_len = len;