wmadec.h

Go to the documentation of this file.
00001 /*
00002  * WMA compatible decoder
00003  * Copyright (c) 2002 The FFmpeg Project.
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00020 #ifndef _WMADEC_H
00021 #define _WMADEC_H
00022 
00023 #include <inttypes.h>
00024 
00025 #include "asf.h"
00026 #include "bitstream.h" /* For GetBitContext */
00027 #include "mdct.h"
00028 
00029 #undef TRACE
00030 
00031 /* size of blocks */
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 /* XXX: find exact max size */
00039 #define HIGH_BAND_MAX_SIZE 16
00040 
00041 #define NB_LSP_COEFS 10
00042 
00043 /* XXX: is it a suitable value ? */
00044 #define MAX_CODED_SUPERFRAME_SIZE 16384
00045 
00046 #define M_PI    3.14159265358979323846
00047 
00048 #define M_PI_F  0x3243f // in fixed 32 format
00049 #define TWO_M_PI_F  0x6487f   //in fixed 32
00050 
00051 #define MAX_CHANNELS 2
00052 
00053 #define NOISE_TAB_SIZE 8192
00054 
00055 #define LSP_POW_BITS 7
00056 
00057 typedef struct WMADecodeContext
00058 {
00059     GetBitContext gb;
00060 
00061     int nb_block_sizes;  /* number of block sizes */
00062 
00063     int sample_rate;
00064     int nb_channels;
00065     int bit_rate;
00066     int version; /* 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2) */
00067     int block_align;
00068     int use_bit_reservoir;
00069     int use_variable_block_len;
00070     int use_exp_vlc;  /* exponent coding: 0 = lsp, 1 = vlc + delta */
00071     int use_noise_coding; /* true if perceptual noise is added */
00072     int byte_offset_bits;
00073     VLC exp_vlc;
00074     int exponent_sizes[BLOCK_NB_SIZES];
00075     uint16_t exponent_bands[BLOCK_NB_SIZES][25];
00076     int high_band_start[BLOCK_NB_SIZES]; /* index of first coef in high band */
00077     int coefs_start;               /* first coded coef */
00078     int coefs_end[BLOCK_NB_SIZES]; /* max number of coded coefficients */
00079     int exponent_high_sizes[BLOCK_NB_SIZES];
00080     int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE];
00081     VLC hgain_vlc;
00082 
00083     /* coded values in high bands */
00084     int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
00085     int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
00086 
00087     /* there are two possible tables for spectral coefficients */
00088     VLC coef_vlc[2];
00089     uint16_t *run_table[2];
00090     uint16_t *level_table[2];
00091     /* frame info */
00092     int frame_len;       /* frame length in samples */
00093     int frame_len_bits;  /* frame_len = 1 << frame_len_bits */
00094 
00095     /* block info */
00096     int reset_block_lengths;
00097     int block_len_bits; /* log2 of current block length */
00098     int next_block_len_bits; /* log2 of next block length */
00099     int prev_block_len_bits; /* log2 of prev block length */
00100     int block_len; /* block length in samples */
00101     int block_num; /* block number in current frame */
00102     int block_pos; /* current position in frame */
00103     uint8_t ms_stereo; /* true if mid/side stereo mode */
00104     uint8_t channel_coded[MAX_CHANNELS]; /* true if channel is coded */
00105     int exponents_bsize[MAX_CHANNELS];      // log2 ratio frame/exp. length
00106     int32_t exponents[MAX_CHANNELS][BLOCK_MAX_SIZE];
00107     int32_t max_exponent[MAX_CHANNELS];
00108     int16_t coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE];
00109     int32_t (*coefs)[MAX_CHANNELS][BLOCK_MAX_SIZE];
00110     MDCTContext mdct_ctx[BLOCK_NB_SIZES];
00111     int32_t *windows[BLOCK_NB_SIZES];
00112     /* output buffer for one frame and the last for IMDCT windowing */
00113     int32_t frame_out[MAX_CHANNELS][BLOCK_MAX_SIZE * 2];
00114     /* last frame info */
00115     uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */
00116     int last_bitoffset;
00117     int last_superframe_len;
00118     int32_t *noise_table;
00119     int noise_index;
00120     int32_t noise_mult; /* XXX: suppress that and integrate it in the noise array */
00121     /* lsp_to_curve tables */
00122     int32_t lsp_cos_table[BLOCK_MAX_SIZE];
00123     int64_t lsp_pow_e_table[256];
00124     int32_t lsp_pow_m_table1[(1 << LSP_POW_BITS)];
00125     int32_t lsp_pow_m_table2[(1 << LSP_POW_BITS)];
00126 
00127     /* State of current superframe decoding */
00128     int bit_offset;
00129     int nb_frames;
00130     int current_frame;
00131 
00132 #ifdef TRACE
00133 
00134     int frame_count;
00135 #endif
00136 }
00137 WMADecodeContext;
00138 
00139 int wma_decode_init(WMADecodeContext* s, asf_waveformatex_t *wfx);
00140 int wma_decode_superframe_init(WMADecodeContext* s,
00141                                uint8_t *buf, int buf_size);
00142 int wma_decode_superframe_frame(WMADecodeContext* s,
00143                                 int32_t *samples,
00144                                 uint8_t *buf, int buf_size);
00145 #endif

Generated on Tue May 25 08:04:54 2010 for VLC by  doxygen 1.5.6