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