use the full resolution we get from the WMA decoder and let the DSP code do the rest
[Rockbox.git] / apps / codecs / libwma / wmadec.h
blob95eb31956a926cfbe1eabe5c496bf517251ce68d
1 /*
2 * WMA compatible decoder
3 * Copyright (c) 2002 The FFmpeg Project.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #ifndef _WMADEC_H
21 #define _WMADEC_H
23 #include "asf.h"
24 #include "bitstream.h" /* For GetBitContext */
25 //#include "dsputil.h" /* For MDCTContext */
28 //#define TRACE
29 /* size of blocks */
30 #define BLOCK_MIN_BITS 7
31 #define BLOCK_MAX_BITS 11
32 #define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS)
34 #define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1)
36 /* XXX: find exact max size */
37 #define HIGH_BAND_MAX_SIZE 16
39 #define NB_LSP_COEFS 10
41 /* XXX: is it a suitable value ? */
42 #define MAX_CODED_SUPERFRAME_SIZE 16384
44 #define M_PI 3.14159265358979323846
46 #define M_PI_F 0x3243f // in fixed 32 format
47 #define TWO_M_PI_F 0x6487f //in fixed 32
49 #define MAX_CHANNELS 2
51 #define NOISE_TAB_SIZE 8192
53 #define LSP_POW_BITS 7
55 #define fixed32 int32_t
56 #define fixed64 int64_t
58 typedef fixed32 FFTSample;
60 typedef struct FFTComplex
62 fixed32 re, im;
64 FFTComplex;
66 typedef struct FFTContext
68 int nbits;
69 int inverse;
70 uint16_t *revtab;
71 FFTComplex *exptab;
72 FFTComplex *exptab1; /* only used by SSE code */
73 int (*fft_calc)(struct FFTContext *s, FFTComplex *z);
75 FFTContext;
77 typedef struct MDCTContext
79 int n; /* size of MDCT (i.e. number of input data * 2) */
80 int nbits; /* n = 2^nbits */
81 /* pre/post rotation tables */
82 fixed32 *tcos;
83 fixed32 *tsin;
84 FFTContext fft;
86 MDCTContext;
88 typedef struct WMADecodeContext
90 GetBitContext gb;
92 int nb_block_sizes; /* number of block sizes */
94 int sample_rate;
95 int nb_channels;
96 int bit_rate;
97 int version; /* 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2) */
98 int block_align;
99 int use_bit_reservoir;
100 int use_variable_block_len;
101 int use_exp_vlc; /* exponent coding: 0 = lsp, 1 = vlc + delta */
102 int use_noise_coding; /* true if perceptual noise is added */
103 int byte_offset_bits;
104 VLC exp_vlc;
105 int exponent_sizes[BLOCK_NB_SIZES];
106 uint16_t exponent_bands[BLOCK_NB_SIZES][25];
107 int high_band_start[BLOCK_NB_SIZES]; /* index of first coef in high band */
108 int coefs_start; /* first coded coef */
109 int coefs_end[BLOCK_NB_SIZES]; /* max number of coded coefficients */
110 int exponent_high_sizes[BLOCK_NB_SIZES];
111 int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE];
112 VLC hgain_vlc;
114 /* coded values in high bands */
115 int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
116 int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
118 /* there are two possible tables for spectral coefficients */
119 VLC coef_vlc[2];
120 uint16_t *run_table[2];
121 uint16_t *level_table[2];
122 /* frame info */
123 int frame_len; /* frame length in samples */
124 int frame_len_bits; /* frame_len = 1 << frame_len_bits */
126 /* block info */
127 int reset_block_lengths;
128 int block_len_bits; /* log2 of current block length */
129 int next_block_len_bits; /* log2 of next block length */
130 int prev_block_len_bits; /* log2 of prev block length */
131 int block_len; /* block length in samples */
132 int block_num; /* block number in current frame */
133 int block_pos; /* current position in frame */
134 uint8_t ms_stereo; /* true if mid/side stereo mode */
135 uint8_t channel_coded[MAX_CHANNELS]; /* true if channel is coded */
136 int exponents_bsize[MAX_CHANNELS]; // log2 ratio frame/exp. length
137 fixed32 exponents[MAX_CHANNELS][BLOCK_MAX_SIZE];
138 fixed32 max_exponent[MAX_CHANNELS];
139 int16_t coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE];
140 fixed32 (*coefs)[MAX_CHANNELS][BLOCK_MAX_SIZE];
141 MDCTContext mdct_ctx[BLOCK_NB_SIZES];
142 fixed32 *windows[BLOCK_NB_SIZES];
143 FFTComplex *mdct_tmp; /* temporary storage for imdct */
144 /* output buffer for one frame and the last for IMDCT windowing */
145 fixed32 frame_out[MAX_CHANNELS][BLOCK_MAX_SIZE * 2];
146 /* last frame info */
147 uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */
148 int last_bitoffset;
149 int last_superframe_len;
150 fixed32 *noise_table;
151 int noise_index;
152 fixed32 noise_mult; /* XXX: suppress that and integrate it in the noise array */
153 /* lsp_to_curve tables */
154 fixed32 lsp_cos_table[BLOCK_MAX_SIZE];
155 fixed64 lsp_pow_e_table[256];
156 fixed32 lsp_pow_m_table1[(1 << LSP_POW_BITS)];
157 fixed32 lsp_pow_m_table2[(1 << LSP_POW_BITS)];
159 /* State of current superframe decoding */
160 int bit_offset;
161 int nb_frames;
162 int current_frame;
164 #ifdef TRACE
166 int frame_count;
167 #endif
169 WMADecodeContext;
171 int wma_decode_init(WMADecodeContext* s, asf_waveformatex_t *wfx);
172 int wma_decode_superframe_init(WMADecodeContext* s,
173 uint8_t *buf, int buf_size);
174 int wma_decode_superframe_frame(WMADecodeContext* s,
175 int32_t *samples,
176 uint8_t *buf, int buf_size);
177 #endif