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