lcd-m6sp.c: remove \r
[kugel-rb.git] / apps / codecs / libwma / wmadec.h
blob5672bfe0631bb947b5400dbec3a3e73d9b4b4456
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 <codecs/libasf/asf.h>
24 #include "bitstream.h" /* For GetBitContext */
25 #include "types.h"
27 //#define TRACE
28 /* size of blocks */
29 #define BLOCK_MIN_BITS 7
30 #define BLOCK_MAX_BITS 11
31 #define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS)
33 #define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1)
35 /* XXX: find exact max size */
36 #define HIGH_BAND_MAX_SIZE 16
38 #define NB_LSP_COEFS 10
40 /* XXX: is it a suitable value ? */
41 #define MAX_CODED_SUPERFRAME_SIZE 16384
43 #define M_PI 3.14159265358979323846
45 #define M_PI_F 0x3243f // in fixed 32 format
46 #define TWO_M_PI_F 0x6487f //in fixed 32
48 #define MAX_CHANNELS 2
50 #define NOISE_TAB_SIZE 8192
52 #define LSP_POW_BITS 7
54 /*define IRAM for targets with 48k/80k IRAM split*/
55 #ifndef IBSS_ATTR_WMA_LARGE_IRAM
56 #if (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) || defined(CPU_S5L870X) || (CONFIG_CPU == MCF5250)
57 /* PP5022/24, MCF5250 have 128KB of IRAM. 80KB are allocated for codecs */
58 #define IBSS_ATTR_WMA_LARGE_IRAM IBSS_ATTR
59 #else
60 /* other PP's and MCF5249 have 96KB of IRAM */
61 #define IBSS_ATTR_WMA_LARGE_IRAM
62 #endif
63 #endif
65 #define VLCBITS 7 /*7 is the lowest without glitching*/
66 #define VLCMAX ((22+VLCBITS-1)/VLCBITS)
68 #define EXPVLCBITS 7
69 #define EXPMAX ((19+EXPVLCBITS-1)/EXPVLCBITS)
71 #define HGAINVLCBITS 9
72 #define HGAINMAX ((13+HGAINVLCBITS-1)/HGAINVLCBITS)
75 typedef struct CoefVLCTable
77 int n; /* total number of codes */
78 const uint32_t *huffcodes; /* VLC bit values */
79 const uint8_t *huffbits; /* VLC bit size */
80 const uint16_t *levels; /* table to build run/level tables */
82 CoefVLCTable;
84 typedef struct WMADecodeContext
86 GetBitContext gb;
88 int nb_block_sizes; /* number of block sizes */
90 int sample_rate;
91 int nb_channels;
92 int bit_rate;
93 int version; /* 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2) */
94 int block_align;
95 int use_bit_reservoir;
96 int use_variable_block_len;
97 int use_exp_vlc; /* exponent coding: 0 = lsp, 1 = vlc + delta */
98 int use_noise_coding; /* true if perceptual noise is added */
99 int byte_offset_bits;
100 VLC exp_vlc;
101 int exponent_sizes[BLOCK_NB_SIZES];
102 uint16_t exponent_bands[BLOCK_NB_SIZES][25];
103 int high_band_start[BLOCK_NB_SIZES]; /* index of first coef in high band */
104 int coefs_start; /* first coded coef */
105 int coefs_end[BLOCK_NB_SIZES]; /* max number of coded coefficients */
106 int exponent_high_sizes[BLOCK_NB_SIZES];
107 int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE];
108 VLC hgain_vlc;
110 /* coded values in high bands */
111 int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
112 int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
114 /* there are two possible tables for spectral coefficients */
115 VLC coef_vlc[2];
116 uint16_t *run_table[2];
117 uint16_t *level_table[2];
118 /* frame info */
119 int frame_len; /* frame length in samples */
120 int frame_len_bits; /* frame_len = 1 << frame_len_bits */
122 /* block info */
123 int reset_block_lengths;
124 int block_len_bits; /* log2 of current block length */
125 int next_block_len_bits; /* log2 of next block length */
126 int prev_block_len_bits; /* log2 of prev block length */
127 int block_len; /* block length in samples */
128 int block_num; /* block number in current frame */
129 int block_pos; /* current position in frame */
130 uint8_t ms_stereo; /* true if mid/side stereo mode */
131 uint8_t channel_coded[MAX_CHANNELS]; /* true if channel is coded */
132 int exponents_bsize[MAX_CHANNELS]; // log2 ratio frame/exp. length
133 fixed32 exponents[MAX_CHANNELS][BLOCK_MAX_SIZE];
134 fixed32 max_exponent[MAX_CHANNELS];
135 int16_t coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE];
136 fixed32 (*coefs)[MAX_CHANNELS][BLOCK_MAX_SIZE];
137 fixed32 *windows[BLOCK_NB_SIZES];
138 /* output buffer for one frame and the last for IMDCT windowing */
139 fixed32 (*frame_out)[MAX_CHANNELS][BLOCK_MAX_SIZE*2];
141 /* last frame info */
142 uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */
143 int last_bitoffset;
144 int last_superframe_len;
145 fixed32 *noise_table;
146 int noise_index;
147 fixed32 noise_mult; /* XXX: suppress that and integrate it in the noise array */
148 /* lsp_to_curve tables */
149 fixed32 lsp_cos_table[BLOCK_MAX_SIZE];
150 fixed64 lsp_pow_e_table[256];
151 fixed32 lsp_pow_m_table1[(1 << LSP_POW_BITS)];
152 fixed32 lsp_pow_m_table2[(1 << LSP_POW_BITS)];
154 /* State of current superframe decoding */
155 int bit_offset;
156 int nb_frames;
157 int current_frame;
159 #ifdef TRACE
161 int frame_count;
162 #endif
164 WMADecodeContext;
166 int wma_decode_init(WMADecodeContext* s, asf_waveformatex_t *wfx);
167 int wma_decode_superframe_init(WMADecodeContext* s,
168 const uint8_t *buf, int buf_size);
169 int wma_decode_superframe_frame(WMADecodeContext* s,
170 int32_t *samples,
171 const uint8_t *buf, int buf_size);
172 #endif