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