annotate wma.h @ 9956:0448219eb490 libavcodec

IIR filter test program.
author alexc
date Thu, 16 Jul 2009 22:17:20 +0000
parents 1f6b569bf958
children 38ab367d4231
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
1 /*
0efc832d9102 wma encoder
michael
parents:
diff changeset
2 * WMA compatible codec
8629
04423b2f6e0b cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 7760
diff changeset
3 * Copyright (c) 2002-2007 The FFmpeg Project
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
4 *
0efc832d9102 wma encoder
michael
parents:
diff changeset
5 * This file is part of FFmpeg.
0efc832d9102 wma encoder
michael
parents:
diff changeset
6 *
0efc832d9102 wma encoder
michael
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
0efc832d9102 wma encoder
michael
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
0efc832d9102 wma encoder
michael
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
0efc832d9102 wma encoder
michael
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
0efc832d9102 wma encoder
michael
parents:
diff changeset
11 *
0efc832d9102 wma encoder
michael
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
0efc832d9102 wma encoder
michael
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0efc832d9102 wma encoder
michael
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0efc832d9102 wma encoder
michael
parents:
diff changeset
15 * Lesser General Public License for more details.
0efc832d9102 wma encoder
michael
parents:
diff changeset
16 *
0efc832d9102 wma encoder
michael
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
0efc832d9102 wma encoder
michael
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
0efc832d9102 wma encoder
michael
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0efc832d9102 wma encoder
michael
parents:
diff changeset
20 */
0efc832d9102 wma encoder
michael
parents:
diff changeset
21
7760
c4a4495715dd Globally rename the header inclusion guard names.
stefano
parents: 7546
diff changeset
22 #ifndef AVCODEC_WMA_H
c4a4495715dd Globally rename the header inclusion guard names.
stefano
parents: 7546
diff changeset
23 #define AVCODEC_WMA_H
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
24
9428
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents: 9411
diff changeset
25 #include "get_bits.h"
9411
4cb7c65fc775 Split bitstream.h, put the bitstream writer stuff in the new file
stefano
parents: 8629
diff changeset
26 #include "put_bits.h"
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
27 #include "dsputil.h"
0efc832d9102 wma encoder
michael
parents:
diff changeset
28
0efc832d9102 wma encoder
michael
parents:
diff changeset
29 /* size of blocks */
0efc832d9102 wma encoder
michael
parents:
diff changeset
30 #define BLOCK_MIN_BITS 7
0efc832d9102 wma encoder
michael
parents:
diff changeset
31 #define BLOCK_MAX_BITS 11
0efc832d9102 wma encoder
michael
parents:
diff changeset
32 #define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS)
0efc832d9102 wma encoder
michael
parents:
diff changeset
33
0efc832d9102 wma encoder
michael
parents:
diff changeset
34 #define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1)
0efc832d9102 wma encoder
michael
parents:
diff changeset
35
0efc832d9102 wma encoder
michael
parents:
diff changeset
36 /* XXX: find exact max size */
0efc832d9102 wma encoder
michael
parents:
diff changeset
37 #define HIGH_BAND_MAX_SIZE 16
0efc832d9102 wma encoder
michael
parents:
diff changeset
38
0efc832d9102 wma encoder
michael
parents:
diff changeset
39 #define NB_LSP_COEFS 10
0efc832d9102 wma encoder
michael
parents:
diff changeset
40
0efc832d9102 wma encoder
michael
parents:
diff changeset
41 /* XXX: is it a suitable value ? */
0efc832d9102 wma encoder
michael
parents:
diff changeset
42 #define MAX_CODED_SUPERFRAME_SIZE 16384
0efc832d9102 wma encoder
michael
parents:
diff changeset
43
0efc832d9102 wma encoder
michael
parents:
diff changeset
44 #define MAX_CHANNELS 2
0efc832d9102 wma encoder
michael
parents:
diff changeset
45
0efc832d9102 wma encoder
michael
parents:
diff changeset
46 #define NOISE_TAB_SIZE 8192
0efc832d9102 wma encoder
michael
parents:
diff changeset
47
0efc832d9102 wma encoder
michael
parents:
diff changeset
48 #define LSP_POW_BITS 7
0efc832d9102 wma encoder
michael
parents:
diff changeset
49
0efc832d9102 wma encoder
michael
parents:
diff changeset
50 //FIXME should be in wmadec
0efc832d9102 wma encoder
michael
parents:
diff changeset
51 #define VLCBITS 9
0efc832d9102 wma encoder
michael
parents:
diff changeset
52 #define VLCMAX ((22+VLCBITS-1)/VLCBITS)
0efc832d9102 wma encoder
michael
parents:
diff changeset
53
9868
5cc32c474caf Introduce WMACoef typedef for decoded coefficients
faust3
parents: 9844
diff changeset
54 typedef float WMACoef; ///< type for decoded coefficients, int16_t would be enough for wma 1/2
5cc32c474caf Introduce WMACoef typedef for decoded coefficients
faust3
parents: 9844
diff changeset
55
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
56 typedef struct CoefVLCTable {
4497
3975e734e07e doxygenize
michael
parents: 4490
diff changeset
57 int n; ///< total number of codes
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
58 int max_level;
4497
3975e734e07e doxygenize
michael
parents: 4490
diff changeset
59 const uint32_t *huffcodes; ///< VLC bit values
3975e734e07e doxygenize
michael
parents: 4490
diff changeset
60 const uint8_t *huffbits; ///< VLC bit size
3975e734e07e doxygenize
michael
parents: 4490
diff changeset
61 const uint16_t *levels; ///< table to build run/level tables
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
62 } CoefVLCTable;
0efc832d9102 wma encoder
michael
parents:
diff changeset
63
4601
7b9ce6f729ae Rename WMADecodeContext to WMACodecContext
mbardiaux
parents: 4600
diff changeset
64 typedef struct WMACodecContext {
4600
6ac364a4ce2b Supply context to tprintf
mbardiaux
parents: 4497
diff changeset
65 AVCodecContext* avctx;
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
66 GetBitContext gb;
0efc832d9102 wma encoder
michael
parents:
diff changeset
67 PutBitContext pb;
0efc832d9102 wma encoder
michael
parents:
diff changeset
68 int sample_rate;
0efc832d9102 wma encoder
michael
parents:
diff changeset
69 int nb_channels;
0efc832d9102 wma encoder
michael
parents:
diff changeset
70 int bit_rate;
4497
3975e734e07e doxygenize
michael
parents: 4490
diff changeset
71 int version; ///< 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2)
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
72 int block_align;
0efc832d9102 wma encoder
michael
parents:
diff changeset
73 int use_bit_reservoir;
0efc832d9102 wma encoder
michael
parents:
diff changeset
74 int use_variable_block_len;
4497
3975e734e07e doxygenize
michael
parents: 4490
diff changeset
75 int use_exp_vlc; ///< exponent coding: 0 = lsp, 1 = vlc + delta
3975e734e07e doxygenize
michael
parents: 4490
diff changeset
76 int use_noise_coding; ///< true if perceptual noise is added
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
77 int byte_offset_bits;
0efc832d9102 wma encoder
michael
parents:
diff changeset
78 VLC exp_vlc;
0efc832d9102 wma encoder
michael
parents:
diff changeset
79 int exponent_sizes[BLOCK_NB_SIZES];
0efc832d9102 wma encoder
michael
parents:
diff changeset
80 uint16_t exponent_bands[BLOCK_NB_SIZES][25];
4497
3975e734e07e doxygenize
michael
parents: 4490
diff changeset
81 int high_band_start[BLOCK_NB_SIZES]; ///< index of first coef in high band
3975e734e07e doxygenize
michael
parents: 4490
diff changeset
82 int coefs_start; ///< first coded coef
3975e734e07e doxygenize
michael
parents: 4490
diff changeset
83 int coefs_end[BLOCK_NB_SIZES]; ///< max number of coded coefficients
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
84 int exponent_high_sizes[BLOCK_NB_SIZES];
0efc832d9102 wma encoder
michael
parents:
diff changeset
85 int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE];
0efc832d9102 wma encoder
michael
parents:
diff changeset
86 VLC hgain_vlc;
0efc832d9102 wma encoder
michael
parents:
diff changeset
87
0efc832d9102 wma encoder
michael
parents:
diff changeset
88 /* coded values in high bands */
0efc832d9102 wma encoder
michael
parents:
diff changeset
89 int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
0efc832d9102 wma encoder
michael
parents:
diff changeset
90 int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
0efc832d9102 wma encoder
michael
parents:
diff changeset
91
0efc832d9102 wma encoder
michael
parents:
diff changeset
92 /* there are two possible tables for spectral coefficients */
0efc832d9102 wma encoder
michael
parents:
diff changeset
93 //FIXME the following 3 tables should be shared between decoders
0efc832d9102 wma encoder
michael
parents:
diff changeset
94 VLC coef_vlc[2];
0efc832d9102 wma encoder
michael
parents:
diff changeset
95 uint16_t *run_table[2];
0efc832d9102 wma encoder
michael
parents:
diff changeset
96 uint16_t *level_table[2];
0efc832d9102 wma encoder
michael
parents:
diff changeset
97 uint16_t *int_table[2];
5258
4372aeade5dc trivial warning fixes
mru
parents: 4785
diff changeset
98 const CoefVLCTable *coef_vlcs[2];
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
99 /* frame info */
4497
3975e734e07e doxygenize
michael
parents: 4490
diff changeset
100 int frame_len; ///< frame length in samples
3975e734e07e doxygenize
michael
parents: 4490
diff changeset
101 int frame_len_bits; ///< frame_len = 1 << frame_len_bits
3975e734e07e doxygenize
michael
parents: 4490
diff changeset
102 int nb_block_sizes; ///< number of block sizes
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
103 /* block info */
0efc832d9102 wma encoder
michael
parents:
diff changeset
104 int reset_block_lengths;
4497
3975e734e07e doxygenize
michael
parents: 4490
diff changeset
105 int block_len_bits; ///< log2 of current block length
3975e734e07e doxygenize
michael
parents: 4490
diff changeset
106 int next_block_len_bits; ///< log2 of next block length
3975e734e07e doxygenize
michael
parents: 4490
diff changeset
107 int prev_block_len_bits; ///< log2 of prev block length
3975e734e07e doxygenize
michael
parents: 4490
diff changeset
108 int block_len; ///< block length in samples
3975e734e07e doxygenize
michael
parents: 4490
diff changeset
109 int block_num; ///< block number in current frame
3975e734e07e doxygenize
michael
parents: 4490
diff changeset
110 int block_pos; ///< current position in frame
3975e734e07e doxygenize
michael
parents: 4490
diff changeset
111 uint8_t ms_stereo; ///< true if mid/side stereo mode
3975e734e07e doxygenize
michael
parents: 4490
diff changeset
112 uint8_t channel_coded[MAX_CHANNELS]; ///< true if channel is coded
4785
4ae9ab738aec WMA decoder improvement, output closer to the dmo binary.
banan
parents: 4737
diff changeset
113 int exponents_bsize[MAX_CHANNELS]; ///< log2 ratio frame/exp. length
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
114 DECLARE_ALIGNED_16(float, exponents[MAX_CHANNELS][BLOCK_MAX_SIZE]);
0efc832d9102 wma encoder
michael
parents:
diff changeset
115 float max_exponent[MAX_CHANNELS];
9868
5cc32c474caf Introduce WMACoef typedef for decoded coefficients
faust3
parents: 9844
diff changeset
116 WMACoef coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE];
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
117 DECLARE_ALIGNED_16(float, coefs[MAX_CHANNELS][BLOCK_MAX_SIZE]);
0efc832d9102 wma encoder
michael
parents:
diff changeset
118 DECLARE_ALIGNED_16(FFTSample, output[BLOCK_MAX_SIZE * 2]);
0efc832d9102 wma encoder
michael
parents:
diff changeset
119 MDCTContext mdct_ctx[BLOCK_NB_SIZES];
0efc832d9102 wma encoder
michael
parents:
diff changeset
120 float *windows[BLOCK_NB_SIZES];
0efc832d9102 wma encoder
michael
parents:
diff changeset
121 /* output buffer for one frame and the last for IMDCT windowing */
0efc832d9102 wma encoder
michael
parents:
diff changeset
122 DECLARE_ALIGNED_16(float, frame_out[MAX_CHANNELS][BLOCK_MAX_SIZE * 2]);
0efc832d9102 wma encoder
michael
parents:
diff changeset
123 /* last frame info */
0efc832d9102 wma encoder
michael
parents:
diff changeset
124 uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */
0efc832d9102 wma encoder
michael
parents:
diff changeset
125 int last_bitoffset;
0efc832d9102 wma encoder
michael
parents:
diff changeset
126 int last_superframe_len;
0efc832d9102 wma encoder
michael
parents:
diff changeset
127 float noise_table[NOISE_TAB_SIZE];
0efc832d9102 wma encoder
michael
parents:
diff changeset
128 int noise_index;
0efc832d9102 wma encoder
michael
parents:
diff changeset
129 float noise_mult; /* XXX: suppress that and integrate it in the noise array */
0efc832d9102 wma encoder
michael
parents:
diff changeset
130 /* lsp_to_curve tables */
0efc832d9102 wma encoder
michael
parents:
diff changeset
131 float lsp_cos_table[BLOCK_MAX_SIZE];
0efc832d9102 wma encoder
michael
parents:
diff changeset
132 float lsp_pow_e_table[256];
0efc832d9102 wma encoder
michael
parents:
diff changeset
133 float lsp_pow_m_table1[(1 << LSP_POW_BITS)];
0efc832d9102 wma encoder
michael
parents:
diff changeset
134 float lsp_pow_m_table2[(1 << LSP_POW_BITS)];
0efc832d9102 wma encoder
michael
parents:
diff changeset
135 DSPContext dsp;
0efc832d9102 wma encoder
michael
parents:
diff changeset
136
0efc832d9102 wma encoder
michael
parents:
diff changeset
137 #ifdef TRACE
0efc832d9102 wma encoder
michael
parents:
diff changeset
138 int frame_count;
0efc832d9102 wma encoder
michael
parents:
diff changeset
139 #endif
4601
7b9ce6f729ae Rename WMADecodeContext to WMACodecContext
mbardiaux
parents: 4600
diff changeset
140 } WMACodecContext;
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
141
0efc832d9102 wma encoder
michael
parents:
diff changeset
142 extern const uint16_t ff_wma_hgain_huffcodes[37];
0efc832d9102 wma encoder
michael
parents:
diff changeset
143 extern const uint8_t ff_wma_hgain_huffbits[37];
0efc832d9102 wma encoder
michael
parents:
diff changeset
144 extern const float ff_wma_lsp_codebook[NB_LSP_COEFS][16];
0efc832d9102 wma encoder
michael
parents:
diff changeset
145 extern const uint32_t ff_wma_scale_huffcodes[121];
0efc832d9102 wma encoder
michael
parents:
diff changeset
146 extern const uint8_t ff_wma_scale_huffbits[121];
0efc832d9102 wma encoder
michael
parents:
diff changeset
147
9841
39bb2646fe00 Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents: 9428
diff changeset
148 int av_cold ff_wma_get_frame_len_bits(int sample_rate, int version,
39bb2646fe00 Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents: 9428
diff changeset
149 unsigned int decode_flags);
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
150 int ff_wma_init(AVCodecContext * avctx, int flags2);
0efc832d9102 wma encoder
michael
parents:
diff changeset
151 int ff_wma_total_gain_to_bits(int total_gain);
0efc832d9102 wma encoder
michael
parents:
diff changeset
152 int ff_wma_end(AVCodecContext *avctx);
9869
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
153 unsigned int ff_wma_get_large_val(GetBitContext* gb);
9844
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9841
diff changeset
154 int ff_wma_run_level_decode(AVCodecContext* avctx, GetBitContext* gb,
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9841
diff changeset
155 VLC *vlc,
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9841
diff changeset
156 const uint16_t *level_table, const uint16_t *run_table,
9868
5cc32c474caf Introduce WMACoef typedef for decoded coefficients
faust3
parents: 9844
diff changeset
157 int version, WMACoef *ptr, int offset,
9844
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9841
diff changeset
158 int num_coefs, int block_len, int frame_len_bits,
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9841
diff changeset
159 int coef_nb_bits);
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
160
7760
c4a4495715dd Globally rename the header inclusion guard names.
stefano
parents: 7546
diff changeset
161 #endif /* AVCODEC_WMA_H */