get rid of the last svn mentions
[libav.git] / libavcodec / wma.h
CommitLineData
59686073
MN
1/*
2 * WMA compatible codec
406792e7 3 * Copyright (c) 2002-2007 The FFmpeg Project
59686073
MN
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
98790382
SS
22#ifndef AVCODEC_WMA_H
23#define AVCODEC_WMA_H
59686073 24
9106a698 25#include "get_bits.h"
b2755007 26#include "put_bits.h"
59686073 27#include "dsputil.h"
1429224b 28#include "fft.h"
c73d99e6 29#include "fmtconvert.h"
59686073
MN
30
31/* size of blocks */
32#define BLOCK_MIN_BITS 7
33#define BLOCK_MAX_BITS 11
34#define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS)
35
36#define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1)
37
38/* XXX: find exact max size */
39#define HIGH_BAND_MAX_SIZE 16
40
41#define NB_LSP_COEFS 10
42
43/* XXX: is it a suitable value ? */
44#define MAX_CODED_SUPERFRAME_SIZE 16384
45
46#define MAX_CHANNELS 2
47
48#define NOISE_TAB_SIZE 8192
49
50#define LSP_POW_BITS 7
51
52//FIXME should be in wmadec
53#define VLCBITS 9
54#define VLCMAX ((22+VLCBITS-1)/VLCBITS)
55
9970c61b
SS
56typedef float WMACoef; ///< type for decoded coefficients, int16_t would be enough for wma 1/2
57
59686073 58typedef struct CoefVLCTable {
6836af52 59 int n; ///< total number of codes
59686073 60 int max_level;
6836af52
MN
61 const uint32_t *huffcodes; ///< VLC bit values
62 const uint8_t *huffbits; ///< VLC bit size
63 const uint16_t *levels; ///< table to build run/level tables
59686073
MN
64} CoefVLCTable;
65
911b9faf 66typedef struct WMACodecContext {
a9c9a240 67 AVCodecContext* avctx;
59686073
MN
68 GetBitContext gb;
69 PutBitContext pb;
70 int sample_rate;
71 int nb_channels;
72 int bit_rate;
6836af52 73 int version; ///< 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2)
59686073
MN
74 int block_align;
75 int use_bit_reservoir;
76 int use_variable_block_len;
6836af52
MN
77 int use_exp_vlc; ///< exponent coding: 0 = lsp, 1 = vlc + delta
78 int use_noise_coding; ///< true if perceptual noise is added
59686073
MN
79 int byte_offset_bits;
80 VLC exp_vlc;
81 int exponent_sizes[BLOCK_NB_SIZES];
82 uint16_t exponent_bands[BLOCK_NB_SIZES][25];
6836af52
MN
83 int high_band_start[BLOCK_NB_SIZES]; ///< index of first coef in high band
84 int coefs_start; ///< first coded coef
85 int coefs_end[BLOCK_NB_SIZES]; ///< max number of coded coefficients
59686073
MN
86 int exponent_high_sizes[BLOCK_NB_SIZES];
87 int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE];
88 VLC hgain_vlc;
89
90 /* coded values in high bands */
91 int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
92 int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
93
94 /* there are two possible tables for spectral coefficients */
95//FIXME the following 3 tables should be shared between decoders
96 VLC coef_vlc[2];
97 uint16_t *run_table[2];
076a9dea 98 float *level_table[2];
59686073 99 uint16_t *int_table[2];
6785cae3 100 const CoefVLCTable *coef_vlcs[2];
59686073 101 /* frame info */
6836af52
MN
102 int frame_len; ///< frame length in samples
103 int frame_len_bits; ///< frame_len = 1 << frame_len_bits
104 int nb_block_sizes; ///< number of block sizes
59686073
MN
105 /* block info */
106 int reset_block_lengths;
6836af52
MN
107 int block_len_bits; ///< log2 of current block length
108 int next_block_len_bits; ///< log2 of next block length
109 int prev_block_len_bits; ///< log2 of prev block length
110 int block_len; ///< block length in samples
111 int block_num; ///< block number in current frame
112 int block_pos; ///< current position in frame
113 uint8_t ms_stereo; ///< true if mid/side stereo mode
114 uint8_t channel_coded[MAX_CHANNELS]; ///< true if channel is coded
5bd526d9 115 int exponents_bsize[MAX_CHANNELS]; ///< log2 ratio frame/exp. length
84dc2d8a 116 DECLARE_ALIGNED(16, float, exponents)[MAX_CHANNELS][BLOCK_MAX_SIZE];
59686073 117 float max_exponent[MAX_CHANNELS];
9970c61b 118 WMACoef coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE];
84dc2d8a
MR
119 DECLARE_ALIGNED(16, float, coefs)[MAX_CHANNELS][BLOCK_MAX_SIZE];
120 DECLARE_ALIGNED(16, FFTSample, output)[BLOCK_MAX_SIZE * 2];
01b22147 121 FFTContext mdct_ctx[BLOCK_NB_SIZES];
59686073 122 float *windows[BLOCK_NB_SIZES];
59686073 123 /* output buffer for one frame and the last for IMDCT windowing */
84dc2d8a 124 DECLARE_ALIGNED(16, float, frame_out)[MAX_CHANNELS][BLOCK_MAX_SIZE * 2];
59686073
MN
125 /* last frame info */
126 uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */
127 int last_bitoffset;
128 int last_superframe_len;
129 float noise_table[NOISE_TAB_SIZE];
130 int noise_index;
131 float noise_mult; /* XXX: suppress that and integrate it in the noise array */
132 /* lsp_to_curve tables */
133 float lsp_cos_table[BLOCK_MAX_SIZE];
134 float lsp_pow_e_table[256];
135 float lsp_pow_m_table1[(1 << LSP_POW_BITS)];
136 float lsp_pow_m_table2[(1 << LSP_POW_BITS)];
137 DSPContext dsp;
c73d99e6 138 FmtConvertContext fmt_conv;
59686073
MN
139
140#ifdef TRACE
141 int frame_count;
142#endif
911b9faf 143} WMACodecContext;
59686073 144
a7e6328c 145extern const uint16_t ff_wma_critical_freqs[25];
59686073
MN
146extern const uint16_t ff_wma_hgain_huffcodes[37];
147extern const uint8_t ff_wma_hgain_huffbits[37];
148extern const float ff_wma_lsp_codebook[NB_LSP_COEFS][16];
3a201bd0
SG
149extern const uint32_t ff_aac_scalefactor_code[121];
150extern const uint8_t ff_aac_scalefactor_bits[121];
59686073 151
cee4bb89
SS
152int av_cold ff_wma_get_frame_len_bits(int sample_rate, int version,
153 unsigned int decode_flags);
59686073
MN
154int ff_wma_init(AVCodecContext * avctx, int flags2);
155int ff_wma_total_gain_to_bits(int total_gain);
156int ff_wma_end(AVCodecContext *avctx);
891bd2e5 157unsigned int ff_wma_get_large_val(GetBitContext* gb);
c0e9b2e8
SS
158int ff_wma_run_level_decode(AVCodecContext* avctx, GetBitContext* gb,
159 VLC *vlc,
076a9dea 160 const float *level_table, const uint16_t *run_table,
9970c61b 161 int version, WMACoef *ptr, int offset,
c0e9b2e8
SS
162 int num_coefs, int block_len, int frame_len_bits,
163 int coef_nb_bits);
59686073 164
98790382 165#endif /* AVCODEC_WMA_H */