00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef AVCODEC_WMA_H
00023 #define AVCODEC_WMA_H
00024
00025 #include "libavutil/float_dsp.h"
00026 #include "get_bits.h"
00027 #include "put_bits.h"
00028 #include "dsputil.h"
00029 #include "fft.h"
00030 #include "fmtconvert.h"
00031
00032
00033 #define BLOCK_MIN_BITS 7
00034 #define BLOCK_MAX_BITS 11
00035 #define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS)
00036
00037 #define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1)
00038
00039
00040 #define HIGH_BAND_MAX_SIZE 16
00041
00042 #define NB_LSP_COEFS 10
00043
00044
00045 #define MAX_CODED_SUPERFRAME_SIZE 16384
00046
00047 #define MAX_CHANNELS 2
00048
00049 #define NOISE_TAB_SIZE 8192
00050
00051 #define LSP_POW_BITS 7
00052
00053
00054 #define VLCBITS 9
00055 #define VLCMAX ((22+VLCBITS-1)/VLCBITS)
00056
00057 typedef float WMACoef;
00058
00059 typedef struct CoefVLCTable {
00060 int n;
00061 int max_level;
00062 const uint32_t *huffcodes;
00063 const uint8_t *huffbits;
00064 const uint16_t *levels;
00065 } CoefVLCTable;
00066
00067 typedef struct WMACodecContext {
00068 AVCodecContext* avctx;
00069 AVFrame frame;
00070 GetBitContext gb;
00071 PutBitContext pb;
00072 int version;
00073 int use_bit_reservoir;
00074 int use_variable_block_len;
00075 int use_exp_vlc;
00076 int use_noise_coding;
00077 int byte_offset_bits;
00078 VLC exp_vlc;
00079 int exponent_sizes[BLOCK_NB_SIZES];
00080 uint16_t exponent_bands[BLOCK_NB_SIZES][25];
00081 int high_band_start[BLOCK_NB_SIZES];
00082 int coefs_start;
00083 int coefs_end[BLOCK_NB_SIZES];
00084 int exponent_high_sizes[BLOCK_NB_SIZES];
00085 int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE];
00086 VLC hgain_vlc;
00087
00088
00089 int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
00090 int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
00091
00092
00093
00094 VLC coef_vlc[2];
00095 uint16_t *run_table[2];
00096 float *level_table[2];
00097 uint16_t *int_table[2];
00098 const CoefVLCTable *coef_vlcs[2];
00099
00100 int frame_len;
00101 int frame_len_bits;
00102 int nb_block_sizes;
00103
00104 int reset_block_lengths;
00105 int block_len_bits;
00106 int next_block_len_bits;
00107 int prev_block_len_bits;
00108 int block_len;
00109 int block_num;
00110 int block_pos;
00111 uint8_t ms_stereo;
00112 uint8_t channel_coded[MAX_CHANNELS];
00113 int exponents_bsize[MAX_CHANNELS];
00114 DECLARE_ALIGNED(32, float, exponents)[MAX_CHANNELS][BLOCK_MAX_SIZE];
00115 float max_exponent[MAX_CHANNELS];
00116 WMACoef coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE];
00117 DECLARE_ALIGNED(32, float, coefs)[MAX_CHANNELS][BLOCK_MAX_SIZE];
00118 DECLARE_ALIGNED(32, FFTSample, output)[BLOCK_MAX_SIZE * 2];
00119 FFTContext mdct_ctx[BLOCK_NB_SIZES];
00120 float *windows[BLOCK_NB_SIZES];
00121
00122 DECLARE_ALIGNED(32, float, frame_out)[MAX_CHANNELS][BLOCK_MAX_SIZE * 2];
00123
00124 uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
00125 int last_bitoffset;
00126 int last_superframe_len;
00127 float noise_table[NOISE_TAB_SIZE];
00128 int noise_index;
00129 float noise_mult;
00130
00131 float lsp_cos_table[BLOCK_MAX_SIZE];
00132 float lsp_pow_e_table[256];
00133 float lsp_pow_m_table1[(1 << LSP_POW_BITS)];
00134 float lsp_pow_m_table2[(1 << LSP_POW_BITS)];
00135 DSPContext dsp;
00136 FmtConvertContext fmt_conv;
00137 AVFloatDSPContext fdsp;
00138
00139 #ifdef TRACE
00140 int frame_count;
00141 #endif
00142 } WMACodecContext;
00143
00144 extern const uint16_t ff_wma_critical_freqs[25];
00145 extern const uint16_t ff_wma_hgain_huffcodes[37];
00146 extern const uint8_t ff_wma_hgain_huffbits[37];
00147 extern const float ff_wma_lsp_codebook[NB_LSP_COEFS][16];
00148 extern const uint32_t ff_aac_scalefactor_code[121];
00149 extern const uint8_t ff_aac_scalefactor_bits[121];
00150
00151 int ff_wma_init(AVCodecContext * avctx, int flags2);
00152 int ff_wma_total_gain_to_bits(int total_gain);
00153 int ff_wma_end(AVCodecContext *avctx);
00154 unsigned int ff_wma_get_large_val(GetBitContext* gb);
00155 int ff_wma_run_level_decode(AVCodecContext* avctx, GetBitContext* gb,
00156 VLC *vlc,
00157 const float *level_table, const uint16_t *run_table,
00158 int version, WMACoef *ptr, int offset,
00159 int num_coefs, int block_len, int frame_len_bits,
00160 int coef_nb_bits);
00161
00162 #endif