FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
wma.h
Go to the documentation of this file.
1 /*
2  * WMA compatible codec
3  * Copyright (c) 2002-2007 The FFmpeg Project
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef AVCODEC_WMA_H
23 #define AVCODEC_WMA_H
24 
25 #include "libavutil/float_dsp.h"
26 
27 #include "fft.h"
28 #include "fmtconvert.h"
29 #include "get_bits.h"
30 #include "put_bits.h"
31 
32 /* size of blocks */
33 #define BLOCK_MIN_BITS 7
34 #define BLOCK_MAX_BITS 11
35 #define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS)
36 
37 #define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1)
38 
39 /* XXX: find exact max size */
40 #define HIGH_BAND_MAX_SIZE 16
41 
42 #define NB_LSP_COEFS 10
43 
44 /* XXX: is it a suitable value ? */
45 #define MAX_CODED_SUPERFRAME_SIZE 16384
46 
47 #define MAX_CHANNELS 2
48 
49 #define NOISE_TAB_SIZE 8192
50 
51 #define LSP_POW_BITS 7
52 
53 // FIXME should be in wmadec
54 #define VLCBITS 9
55 #define VLCMAX ((22 + VLCBITS - 1) / VLCBITS)
56 
57 typedef float WMACoef; ///< type for decoded coefficients, int16_t would be enough for wma 1/2
58 
59 typedef struct CoefVLCTable {
60  int n; ///< total number of codes
61  int max_level;
62  const uint32_t *huffcodes; ///< VLC bit values
63  const uint8_t *huffbits; ///< VLC bit size
64  const uint16_t *levels; ///< table to build run/level tables
65 } CoefVLCTable;
66 
67 typedef struct WMACodecContext {
71  int version; ///< 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2)
74  int use_exp_vlc; ///< exponent coding: 0 = lsp, 1 = vlc + delta
75  int use_noise_coding; ///< true if perceptual noise is added
80  int high_band_start[BLOCK_NB_SIZES]; ///< index of first coef in high band
81  int coefs_start; ///< first coded coef
82  int coefs_end[BLOCK_NB_SIZES]; ///< max number of coded coefficients
86 
87  /* coded values in high bands */
90 
91  /* there are two possible tables for spectral coefficients */
92 // FIXME the following 3 tables should be shared between decoders
94  uint16_t *run_table[2];
95  float *level_table[2];
96  uint16_t *int_table[2];
98  /* frame info */
99  int frame_len; ///< frame length in samples
100  int frame_len_bits; ///< frame_len = 1 << frame_len_bits
101  int nb_block_sizes; ///< number of block sizes
102  /* block info */
104  int block_len_bits; ///< log2 of current block length
105  int next_block_len_bits; ///< log2 of next block length
106  int prev_block_len_bits; ///< log2 of prev block length
107  int block_len; ///< block length in samples
108  int block_num; ///< block number in current frame
109  int block_pos; ///< current position in frame
110  uint8_t ms_stereo; ///< true if mid/side stereo mode
111  uint8_t channel_coded[MAX_CHANNELS]; ///< true if channel is coded
112  int exponents_bsize[MAX_CHANNELS]; ///< log2 ratio frame/exp. length
119  const float *windows[BLOCK_NB_SIZES];
120  /* output buffer for one frame and the last for IMDCT windowing */
122  /* last frame info */
128  float noise_mult; /* XXX: suppress that and integrate it in the noise array */
129  /* lsp_to_curve tables */
131  float lsp_pow_e_table[256];
136 
137 #ifdef TRACE
138  int frame_count;
139 #endif /* TRACE */
141 
142 extern const uint16_t ff_wma_hgain_huffcodes[37];
143 extern const uint8_t ff_wma_hgain_huffbits[37];
144 extern const float ff_wma_lsp_codebook[NB_LSP_COEFS][16];
145 extern const uint32_t ff_aac_scalefactor_code[121];
146 extern const uint8_t ff_aac_scalefactor_bits[121];
147 
148 int ff_wma_init(AVCodecContext *avctx, int flags2);
149 int ff_wma_total_gain_to_bits(int total_gain);
150 int ff_wma_end(AVCodecContext *avctx);
151 unsigned int ff_wma_get_large_val(GetBitContext *gb);
153  VLC *vlc, const float *level_table,
154  const uint16_t *run_table, int version,
155  WMACoef *ptr, int offset, int num_coefs,
156  int block_len, int frame_len_bits,
157  int coef_nb_bits);
158 
159 #endif /* AVCODEC_WMA_H */