Put the WMA windowing and output buffer into IRAM on targets with > 96KB of it. ...
[kugel-rb.git] / apps / codecs / libwma / wmadec.h
blob30ba35b533c13dc854a1c3969a8a947ed958deae
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 "types.h"
26 #include "mdct.h"
27 //#include "dsputil.h" /* For MDCTContext */
30 //#define 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 /*define IRAM for targets with 48k/80k IRAM split*/
58 #ifndef IBSS_ATTR_WMA_LARGE_IRAM
59 #if (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) || (CONFIG_CPU == MCF5250)
60 /* PP5022/24 and MCF5250 have 128KB of IRAM, with 80KB allocated for codecs */
61 #define IBSS_ATTR_WMA_LARGE_IRAM IBSS_ATTR
62 #else
63 /* other PP's and MCF5249 have 96KB of IRAM */
64 #define IBSS_ATTR_WMA_LARGE_IRAM
65 #endif
66 #endif
68 typedef struct WMADecodeContext
70 GetBitContext gb;
72 int nb_block_sizes; /* number of block sizes */
74 int sample_rate;
75 int nb_channels;
76 int bit_rate;
77 int version; /* 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2) */
78 int block_align;
79 int use_bit_reservoir;
80 int use_variable_block_len;
81 int use_exp_vlc; /* exponent coding: 0 = lsp, 1 = vlc + delta */
82 int use_noise_coding; /* true if perceptual noise is added */
83 int byte_offset_bits;
84 VLC exp_vlc;
85 int exponent_sizes[BLOCK_NB_SIZES];
86 uint16_t exponent_bands[BLOCK_NB_SIZES][25];
87 int high_band_start[BLOCK_NB_SIZES]; /* index of first coef in high band */
88 int coefs_start; /* first coded coef */
89 int coefs_end[BLOCK_NB_SIZES]; /* max number of coded coefficients */
90 int exponent_high_sizes[BLOCK_NB_SIZES];
91 int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE];
92 VLC hgain_vlc;
94 /* coded values in high bands */
95 int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
96 int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
98 /* there are two possible tables for spectral coefficients */
99 VLC coef_vlc[2];
100 uint16_t *run_table[2];
101 uint16_t *level_table[2];
102 /* frame info */
103 int frame_len; /* frame length in samples */
104 int frame_len_bits; /* frame_len = 1 << frame_len_bits */
106 /* block info */
107 int reset_block_lengths;
108 int block_len_bits; /* log2 of current block length */
109 int next_block_len_bits; /* log2 of next block length */
110 int prev_block_len_bits; /* log2 of prev block length */
111 int block_len; /* block length in samples */
112 int block_num; /* block number in current frame */
113 int block_pos; /* current position in frame */
114 uint8_t ms_stereo; /* true if mid/side stereo mode */
115 uint8_t channel_coded[MAX_CHANNELS]; /* true if channel is coded */
116 int exponents_bsize[MAX_CHANNELS]; // log2 ratio frame/exp. length
117 fixed32 exponents[MAX_CHANNELS][BLOCK_MAX_SIZE];
118 fixed32 max_exponent[MAX_CHANNELS];
119 int16_t coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE];
120 fixed32 (*coefs)[MAX_CHANNELS][BLOCK_MAX_SIZE];
121 MDCTContext mdct_ctx[BLOCK_NB_SIZES];
122 fixed32 *windows[BLOCK_NB_SIZES];
123 /* output buffer for one frame and the last for IMDCT windowing */
124 fixed32 (*frame_out)[MAX_CHANNELS][BLOCK_MAX_SIZE*2];
126 /* last frame info */
127 uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */
128 int last_bitoffset;
129 int last_superframe_len;
130 fixed32 *noise_table;
131 int noise_index;
132 fixed32 noise_mult; /* XXX: suppress that and integrate it in the noise array */
133 /* lsp_to_curve tables */
134 fixed32 lsp_cos_table[BLOCK_MAX_SIZE];
135 fixed64 lsp_pow_e_table[256];
136 fixed32 lsp_pow_m_table1[(1 << LSP_POW_BITS)];
137 fixed32 lsp_pow_m_table2[(1 << LSP_POW_BITS)];
139 /* State of current superframe decoding */
140 int bit_offset;
141 int nb_frames;
142 int current_frame;
144 #ifdef TRACE
146 int frame_count;
147 #endif
149 WMADecodeContext;
151 int wma_decode_init(WMADecodeContext* s, asf_waveformatex_t *wfx);
152 int wma_decode_superframe_init(WMADecodeContext* s,
153 uint8_t *buf, int buf_size);
154 int wma_decode_superframe_frame(WMADecodeContext* s,
155 int32_t *samples,
156 uint8_t *buf, int buf_size);
157 #endif