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     GetBitContext gb;
00069     PutBitContext pb;
00070     int sample_rate;
00071     int nb_channels;
00072     int bit_rate;
00073     int version;                            
00074     int block_align;
00075     int use_bit_reservoir;
00076     int use_variable_block_len;
00077     int use_exp_vlc;                        
00078     int use_noise_coding;                   
00079     int byte_offset_bits;
00080     VLC exp_vlc;
00081     int exponent_sizes[BLOCK_NB_SIZES];
00082     uint16_t exponent_bands[BLOCK_NB_SIZES][25];
00083     int high_band_start[BLOCK_NB_SIZES];    
00084     int coefs_start;                        
00085     int coefs_end[BLOCK_NB_SIZES];          
00086     int exponent_high_sizes[BLOCK_NB_SIZES];
00087     int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE];
00088     VLC hgain_vlc;
00089 
00090     
00091     int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
00092     int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
00093 
00094     
00095 
00096     VLC coef_vlc[2];
00097     uint16_t *run_table[2];
00098     float *level_table[2];
00099     uint16_t *int_table[2];
00100     const CoefVLCTable *coef_vlcs[2];
00101     
00102     int frame_len;                          
00103     int frame_len_bits;                     
00104     int nb_block_sizes;                     
00105     
00106     int reset_block_lengths;
00107     int block_len_bits;                     
00108     int next_block_len_bits;                
00109     int prev_block_len_bits;                
00110     int block_len;                          
00111     int block_num;                          
00112     int block_pos;                          
00113     uint8_t ms_stereo;                      
00114     uint8_t channel_coded[MAX_CHANNELS];    
00115     int exponents_bsize[MAX_CHANNELS];      
00116     DECLARE_ALIGNED(32, float, exponents)[MAX_CHANNELS][BLOCK_MAX_SIZE];
00117     float max_exponent[MAX_CHANNELS];
00118     WMACoef coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE];
00119     DECLARE_ALIGNED(32, float, coefs)[MAX_CHANNELS][BLOCK_MAX_SIZE];
00120     DECLARE_ALIGNED(32, FFTSample, output)[BLOCK_MAX_SIZE * 2];
00121     FFTContext mdct_ctx[BLOCK_NB_SIZES];
00122     float *windows[BLOCK_NB_SIZES];
00123     
00124     DECLARE_ALIGNED(32, float, frame_out)[MAX_CHANNELS][BLOCK_MAX_SIZE * 2];
00125     
00126     uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; 
00127     int last_bitoffset;
00128     int last_superframe_len;
00129     float noise_table[NOISE_TAB_SIZE];
00130     int noise_index;
00131     float noise_mult; 
00132     
00133     float lsp_cos_table[BLOCK_MAX_SIZE];
00134     float lsp_pow_e_table[256];
00135     float lsp_pow_m_table1[(1 << LSP_POW_BITS)];
00136     float lsp_pow_m_table2[(1 << LSP_POW_BITS)];
00137     DSPContext dsp;
00138     FmtConvertContext fmt_conv;
00139 
00140 #ifdef TRACE
00141     int frame_count;
00142 #endif
00143 } WMACodecContext;
00144 
00145 extern const uint16_t ff_wma_critical_freqs[25];
00146 extern const uint16_t ff_wma_hgain_huffcodes[37];
00147 extern const uint8_t ff_wma_hgain_huffbits[37];
00148 extern const float ff_wma_lsp_codebook[NB_LSP_COEFS][16];
00149 extern const uint32_t ff_aac_scalefactor_code[121];
00150 extern const uint8_t  ff_aac_scalefactor_bits[121];
00151 
00152 int av_cold ff_wma_get_frame_len_bits(int sample_rate, int version,
00153                                       unsigned int decode_flags);
00154 int ff_wma_init(AVCodecContext * avctx, int flags2);
00155 int ff_wma_total_gain_to_bits(int total_gain);
00156 int ff_wma_end(AVCodecContext *avctx);
00157 unsigned int ff_wma_get_large_val(GetBitContext* gb);
00158 int ff_wma_run_level_decode(AVCodecContext* avctx, GetBitContext* gb,
00159                             VLC *vlc,
00160                             const float *level_table, const uint16_t *run_table,
00161                             int version, WMACoef *ptr, int offset,
00162                             int num_coefs, int block_len, int frame_len_bits,
00163                             int coef_nb_bits);
00164 
00165 #endif