]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/wma.c
aacpsy: cosmetics, change a FIXME to a NOTE about subshort comparisons
[ffmpeg] / libavcodec / wma.c
index 86b3212764a598ef9fadf01e7ffcb95a41555260..4cdffcd1013e9e17df085c23440ac8e17397e1ec 100644 (file)
@@ -1,25 +1,26 @@
 /*
  * WMA compatible codec
- * Copyright (c) 2002-2007 The FFmpeg Project
+ * Copyright (c) 2002-2007 The Libav Project
  *
- * This file is part of FFmpeg.
+ * This file is part of Libav.
  *
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include "avcodec.h"
+#include "sinewin.h"
 #include "wma.h"
 #include "wmadata.h"
 
@@ -29,7 +30,7 @@
 /* XXX: use same run/length optimization as mpeg decoders */
 //FIXME maybe split decode / encode or pass flag
 static void init_coef_vlc(VLC *vlc, uint16_t **prun_table,
-                          uint16_t **plevel_table, uint16_t **pint_table,
+                          float **plevel_table, uint16_t **pint_table,
                           const CoefVLCTable *vlc_table)
 {
     int n = vlc_table->n;
@@ -37,12 +38,14 @@ static void init_coef_vlc(VLC *vlc, uint16_t **prun_table,
     const uint32_t *table_codes  = vlc_table->huffcodes;
     const uint16_t *levels_table = vlc_table->levels;
     uint16_t *run_table, *level_table, *int_table;
+    float *flevel_table;
     int i, l, j, k, level;
 
     init_vlc(vlc, VLCBITS, n, table_bits, 1, 1, table_codes, 4, 4, 0);
 
     run_table   = av_malloc(n * sizeof(uint16_t));
     level_table = av_malloc(n * sizeof(uint16_t));
+    flevel_table= av_malloc(n * sizeof(*flevel_table));
     int_table   = av_malloc(n * sizeof(uint16_t));
     i = 2;
     level = 1;
@@ -53,13 +56,15 @@ static void init_coef_vlc(VLC *vlc, uint16_t **prun_table,
         for (j = 0; j < l; j++) {
             run_table[i]   = j;
             level_table[i] = level;
+            flevel_table[i]= level;
             i++;
         }
         level++;
     }
     *prun_table   = run_table;
-    *plevel_table = level_table;
+    *plevel_table = flevel_table;
     *pint_table   = int_table;
+    av_free(level_table);
 }
 
 /**
@@ -122,6 +127,7 @@ int ff_wma_init(AVCodecContext *avctx, int flags2)
     s->block_align = avctx->block_align;
 
     dsputil_init(&s->dsp, avctx);
+    ff_fmt_convert_init(&s->fmt_conv, avctx);
 
     if (avctx->codec->id == CODEC_ID_WMAV1) {
         s->version = 1;
@@ -131,6 +137,9 @@ int ff_wma_init(AVCodecContext *avctx, int flags2)
 
     /* compute MDCT block size */
     s->frame_len_bits = ff_wma_get_frame_len_bits(s->sample_rate, s->version, 0);
+    s->next_block_len_bits = s->frame_len_bits;
+    s->prev_block_len_bits = s->frame_len_bits;
+    s->block_len_bits      = s->frame_len_bits;
 
     s->frame_len = 1 << s->frame_len_bits;
     if (s->use_variable_block_len) {
@@ -213,13 +222,13 @@ int ff_wma_init(AVCodecContext *avctx, int flags2)
             high_freq = high_freq * 0.5;
         }
     }
-    dprintf(s->avctx, "flags2=0x%x\n", flags2);
-    dprintf(s->avctx, "version=%d channels=%d sample_rate=%d bitrate=%d block_align=%d\n",
+    av_dlog(s->avctx, "flags2=0x%x\n", flags2);
+    av_dlog(s->avctx, "version=%d channels=%d sample_rate=%d bitrate=%d block_align=%d\n",
             s->version, s->nb_channels, s->sample_rate, s->bit_rate,
             s->block_align);
-    dprintf(s->avctx, "bps=%f bps1=%f high_freq=%f bitoffset=%d\n",
+    av_dlog(s->avctx, "bps=%f bps1=%f high_freq=%f bitoffset=%d\n",
             bps, bps1, high_freq, s->byte_offset_bits);
-    dprintf(s->avctx, "use_noise_coding=%d use_exp_vlc=%d nb_block_sizes=%d\n",
+    av_dlog(s->avctx, "use_noise_coding=%d use_exp_vlc=%d nb_block_sizes=%d\n",
             s->use_noise_coding, s->use_exp_vlc, s->nb_block_sizes);
 
     /* compute the scale factor band sizes for each MDCT block size */
@@ -238,7 +247,7 @@ int ff_wma_init(AVCodecContext *avctx, int flags2)
             if (s->version == 1) {
                 lpos = 0;
                 for (i = 0; i < 25; i++) {
-                    a = wma_critical_freqs[i];
+                    a = ff_wma_critical_freqs[i];
                     b = s->sample_rate;
                     pos = ((block_len * 2 * a) + (b >> 1)) / b;
                     if (pos > block_len)
@@ -273,7 +282,7 @@ int ff_wma_init(AVCodecContext *avctx, int flags2)
                     j = 0;
                     lpos = 0;
                     for (i = 0; i < 25; i++) {
-                        a = wma_critical_freqs[i];
+                        a = ff_wma_critical_freqs[i];
                         b = s->sample_rate;
                         pos = ((block_len * 2 * a) + (b << 1)) / (4 * b);
                         pos <<= 2;
@@ -339,10 +348,8 @@ int ff_wma_init(AVCodecContext *avctx, int flags2)
 
     /* init MDCT windows : simple sinus window */
     for (i = 0; i < s->nb_block_sizes; i++) {
-        int n;
-        n = 1 << (s->frame_len_bits - i);
-        ff_sine_window_init(ff_sine_windows[s->frame_len_bits - i - 7], n);
-        s->windows[i] = ff_sine_windows[s->frame_len_bits - i - 7];
+        ff_init_ff_sine_windows(s->frame_len_bits - i);
+        s->windows[i] = ff_sine_windows[s->frame_len_bits - i];
     }
 
     s->reset_block_lengths = 1;
@@ -427,7 +434,7 @@ int ff_wma_end(AVCodecContext *avctx)
 
 /**
  * Decode an uncompressed coefficient.
- * @param s codec context
+ * @param gb GetBitContext
  * @return the decoded coefficient
  */
 unsigned int ff_wma_get_large_val(GetBitContext* gb)
@@ -465,28 +472,31 @@ unsigned int ff_wma_get_large_val(GetBitContext* gb)
  */
 int ff_wma_run_level_decode(AVCodecContext* avctx, GetBitContext* gb,
                             VLC *vlc,
-                            const uint16_t *level_table, const uint16_t *run_table,
+                            const float *level_table, const uint16_t *run_table,
                             int version, WMACoef *ptr, int offset,
                             int num_coefs, int block_len, int frame_len_bits,
                             int coef_nb_bits)
 {
     int code, level, sign;
+    const uint32_t *ilvl = (const uint32_t*)level_table;
+    uint32_t *iptr = (uint32_t*)ptr;
     const unsigned int coef_mask = block_len - 1;
     for (; offset < num_coefs; offset++) {
         code = get_vlc2(gb, vlc->table, VLCBITS, VLCMAX);
         if (code > 1) {
             /** normal code */
             offset += run_table[code];
-            level = level_table[code];
+            sign = get_bits1(gb) - 1;
+            iptr[offset & coef_mask] = ilvl[code] ^ sign<<31;
         } else if (code == 1) {
-            /* EOB */
+            /** EOB */
             break;
         } else {
-            /* escape */
+            /** escape */
             if (!version) {
                 level = get_bits(gb, coef_nb_bits);
-                /* NOTE: this is rather suboptimal. reading
-                   block_len_bits would be better */
+                /** NOTE: this is rather suboptimal. reading
+                    block_len_bits would be better */
                 offset += get_bits(gb, frame_len_bits);
             } else {
                 level = ff_wma_get_large_val(gb);
@@ -503,9 +513,9 @@ int ff_wma_run_level_decode(AVCodecContext* avctx, GetBitContext* gb,
                         offset += get_bits(gb, 2) + 1;
                 }
             }
+            sign = get_bits1(gb) - 1;
+            ptr[offset & coef_mask] = (level^sign) - sign;
         }
-        sign = get_bits1(gb) - 1;
-        ptr[offset & coef_mask] = (level^sign) - sign;
     }
     /** NOTE: EOB can be omitted */
     if (offset > num_coefs) {