Old RC: "rate" is a float nowadays (fix #4088)
[vlc/asuraparaju-public.git] / modules / codec / wmafixed / wmadec.h
blobee7f35d1d1ddd59d017ab0cda2c736a335aacb22
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 <inttypes.h>
25 #include "asf.h"
26 #include "bitstream.h" /* For GetBitContext */
27 #include "mdct.h"
29 #undef TRACE
31 /* size of blocks */
32 #define BLOCK_MIN_BITS 7
33 #define BLOCK_MAX_BITS 11
34 #define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS)
36 #define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1)
38 /* XXX: find exact max size */
39 #define HIGH_BAND_MAX_SIZE 16
41 #define NB_LSP_COEFS 10
43 /* XXX: is it a suitable value ? */
44 #define MAX_CODED_SUPERFRAME_SIZE 16384
46 #define M_PI 3.14159265358979323846
48 #define M_PI_F 0x3243f // in fixed 32 format
49 #define TWO_M_PI_F 0x6487f //in fixed 32
51 #define MAX_CHANNELS 2
53 #define NOISE_TAB_SIZE 8192
55 #define LSP_POW_BITS 7
57 typedef struct WMADecodeContext
59 GetBitContext gb;
61 int nb_block_sizes; /* number of block sizes */
63 int sample_rate;
64 int nb_channels;
65 int bit_rate;
66 int version; /* 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2) */
67 int block_align;
68 int use_bit_reservoir;
69 int use_variable_block_len;
70 int use_exp_vlc; /* exponent coding: 0 = lsp, 1 = vlc + delta */
71 int use_noise_coding; /* true if perceptual noise is added */
72 int byte_offset_bits;
73 VLC exp_vlc;
74 int exponent_sizes[BLOCK_NB_SIZES];
75 uint16_t exponent_bands[BLOCK_NB_SIZES][25];
76 int high_band_start[BLOCK_NB_SIZES]; /* index of first coef in high band */
77 int coefs_start; /* first coded coef */
78 int coefs_end[BLOCK_NB_SIZES]; /* max number of coded coefficients */
79 int exponent_high_sizes[BLOCK_NB_SIZES];
80 int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE];
81 VLC hgain_vlc;
83 /* coded values in high bands */
84 int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
85 int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
87 /* there are two possible tables for spectral coefficients */
88 VLC coef_vlc[2];
89 uint16_t *run_table[2];
90 uint16_t *level_table[2];
91 /* frame info */
92 int frame_len; /* frame length in samples */
93 int frame_len_bits; /* frame_len = 1 << frame_len_bits */
95 /* block info */
96 int reset_block_lengths;
97 int block_len_bits; /* log2 of current block length */
98 int next_block_len_bits; /* log2 of next block length */
99 int prev_block_len_bits; /* log2 of prev block length */
100 int block_len; /* block length in samples */
101 int block_num; /* block number in current frame */
102 int block_pos; /* current position in frame */
103 uint8_t ms_stereo; /* true if mid/side stereo mode */
104 uint8_t channel_coded[MAX_CHANNELS]; /* true if channel is coded */
105 int exponents_bsize[MAX_CHANNELS]; // log2 ratio frame/exp. length
106 int32_t exponents[MAX_CHANNELS][BLOCK_MAX_SIZE];
107 int32_t max_exponent[MAX_CHANNELS];
108 int16_t coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE];
109 int32_t (*coefs)[MAX_CHANNELS][BLOCK_MAX_SIZE];
110 MDCTContext mdct_ctx[BLOCK_NB_SIZES];
111 int32_t *windows[BLOCK_NB_SIZES];
112 /* output buffer for one frame and the last for IMDCT windowing */
113 int32_t frame_out[MAX_CHANNELS][BLOCK_MAX_SIZE * 2];
114 /* last frame info */
115 uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */
116 int last_bitoffset;
117 int last_superframe_len;
118 int32_t *noise_table;
119 int noise_index;
120 int32_t noise_mult; /* XXX: suppress that and integrate it in the noise array */
121 /* lsp_to_curve tables */
122 int32_t lsp_cos_table[BLOCK_MAX_SIZE];
123 int64_t lsp_pow_e_table[256];
124 int32_t lsp_pow_m_table1[(1 << LSP_POW_BITS)];
125 int32_t lsp_pow_m_table2[(1 << LSP_POW_BITS)];
127 /* State of current superframe decoding */
128 int bit_offset;
129 int nb_frames;
130 int current_frame;
132 #ifdef TRACE
134 int frame_count;
135 #endif
137 WMADecodeContext;
139 int wma_decode_init(WMADecodeContext* s, asf_waveformatex_t *wfx);
140 int wma_decode_superframe_init(WMADecodeContext* s,
141 uint8_t *buf, int buf_size);
142 int wma_decode_superframe_frame(WMADecodeContext* s,
143 int32_t *samples,
144 uint8_t *buf, int buf_size);
145 #endif