summaryrefslogtreecommitdiff
path: root/apps/codecs/libwma/wmadec.h
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2007-07-03 09:25:36 +0000
committerDave Chapman <dave@dchapman.com>2007-07-03 09:25:36 +0000
commitc72824786a0e8c68921ebb9b72f02a2e80aaee17 (patch)
treeadf8dac26d074ee3620df4ab482ff108561ead01 /apps/codecs/libwma/wmadec.h
parent2ca895bae7a25ea8ef7f295b4e8ab01ff75a4914 (diff)
downloadrockbox-c72824786a0e8c68921ebb9b72f02a2e80aaee17.tar.gz
rockbox-c72824786a0e8c68921ebb9b72f02a2e80aaee17.zip
Initial, work-in-progress, version of a WMA codec using Michael Giacomelli's fixed-point and malloc-less WMA decoder (based on the ffmpeg WMA decoder from early 2006, and also building on the work started by Paul Jones). The codec itself and the ASF parsing code were written by me, inspired by the ASF parser in libasf. Current performance is around 400% realtime on gigabeat, 100% realtime on PP and 20% realtime on Coldfire.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13769 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libwma/wmadec.h')
-rw-r--r--apps/codecs/libwma/wmadec.h162
1 files changed, 162 insertions, 0 deletions
diff --git a/apps/codecs/libwma/wmadec.h b/apps/codecs/libwma/wmadec.h
new file mode 100644
index 0000000000..89c100daba
--- /dev/null
+++ b/apps/codecs/libwma/wmadec.h
@@ -0,0 +1,162 @@
1#ifndef _WMADEC_H
2#define _WMADEC_H
3
4#include "asf.h"
5#include "common.h" /* For GetBitContext */
6//#include "dsputil.h" /* For MDCTContext */
7
8
9//#define TRACE
10/* size of blocks */
11#define BLOCK_MIN_BITS 7
12#define BLOCK_MAX_BITS 11
13#define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS)
14
15#define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1)
16
17/* XXX: find exact max size */
18#define HIGH_BAND_MAX_SIZE 16
19
20#define NB_LSP_COEFS 10
21
22/* XXX: is it a suitable value ? */
23#define MAX_CODED_SUPERFRAME_SIZE 16384
24
25#define M_PI 3.14159265358979323846
26
27#define M_PI_F 0x3243f // in fixed 32 format
28#define TWO_M_PI_F 0x6487f //in fixed 32
29
30#define MAX_CHANNELS 2
31
32#define NOISE_TAB_SIZE 8192
33
34#define LSP_POW_BITS 7
35
36#define VLC_TYPE int16_t
37
38typedef struct VLC
39{
40 int bits;
41 VLC_TYPE (*table)[2]; ///< code, bits
42 int table_size, table_allocated;
43}
44VLC;
45
46#define fixed32 int32_t
47#define fixed64 int64_t
48
49typedef fixed32 FFTSample;
50
51typedef struct FFTComplex
52{
53 fixed32 re, im;
54}
55FFTComplex;
56
57typedef struct FFTContext
58{
59 int nbits;
60 int inverse;
61 uint16_t *revtab;
62 FFTComplex *exptab;
63 FFTComplex *exptab1; /* only used by SSE code */
64 int (*fft_calc)(struct FFTContext *s, FFTComplex *z);
65}
66FFTContext;
67
68typedef struct MDCTContext
69{
70 int n; /* size of MDCT (i.e. number of input data * 2) */
71 int nbits; /* n = 2^nbits */
72 /* pre/post rotation tables */
73 fixed32 *tcos;
74 fixed32 *tsin;
75 FFTContext fft;
76}
77MDCTContext;
78
79typedef struct WMADecodeContext
80{
81 GetBitContext gb;
82
83 int nb_block_sizes; /* number of block sizes */
84
85 int sample_rate;
86 int nb_channels;
87 int bit_rate;
88 int version; /* 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2) */
89 int block_align;
90 int use_bit_reservoir;
91 int use_variable_block_len;
92 int use_exp_vlc; /* exponent coding: 0 = lsp, 1 = vlc + delta */
93 int use_noise_coding; /* true if perceptual noise is added */
94 int byte_offset_bits;
95 VLC exp_vlc;
96 int exponent_sizes[BLOCK_NB_SIZES];
97 uint16_t exponent_bands[BLOCK_NB_SIZES][25];
98 int high_band_start[BLOCK_NB_SIZES]; /* index of first coef in high band */
99 int coefs_start; /* first coded coef */
100 int coefs_end[BLOCK_NB_SIZES]; /* max number of coded coefficients */
101 int exponent_high_sizes[BLOCK_NB_SIZES];
102 int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE];
103 VLC hgain_vlc;
104
105 /* coded values in high bands */
106 int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
107 int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
108
109 /* there are two possible tables for spectral coefficients */
110 VLC coef_vlc[2];
111 uint16_t *run_table[2];
112 uint16_t *level_table[2];
113 /* frame info */
114 int frame_len; /* frame length in samples */
115 int frame_len_bits; /* frame_len = 1 << frame_len_bits */
116
117 /* block info */
118 int reset_block_lengths;
119 int block_len_bits; /* log2 of current block length */
120 int next_block_len_bits; /* log2 of next block length */
121 int prev_block_len_bits; /* log2 of prev block length */
122 int block_len; /* block length in samples */
123 int block_num; /* block number in current frame */
124 int block_pos; /* current position in frame */
125 uint8_t ms_stereo; /* true if mid/side stereo mode */
126 uint8_t channel_coded[MAX_CHANNELS]; /* true if channel is coded */
127 fixed32 exponents[MAX_CHANNELS][BLOCK_MAX_SIZE];
128 fixed32 max_exponent[MAX_CHANNELS];
129 int16_t coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE];
130 fixed32 coefs[MAX_CHANNELS][BLOCK_MAX_SIZE];
131 MDCTContext mdct_ctx[BLOCK_NB_SIZES];
132 fixed32 *windows[BLOCK_NB_SIZES];
133 FFTComplex mdct_tmp[BLOCK_MAX_SIZE]; /* temporary storage for imdct */
134 /* output buffer for one frame and the last for IMDCT windowing */
135 fixed32 frame_out[MAX_CHANNELS][BLOCK_MAX_SIZE * 2];
136 /* last frame info */
137 uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */
138 int last_bitoffset;
139 int last_superframe_len;
140 fixed32 noise_table[NOISE_TAB_SIZE];
141 int noise_index;
142 fixed32 noise_mult; /* XXX: suppress that and integrate it in the noise array */
143 /* lsp_to_curve tables */
144 fixed32 lsp_cos_table[BLOCK_MAX_SIZE];
145 fixed64 lsp_pow_e_table[256];
146 fixed64 lsp_pow_m_table1[(1 << LSP_POW_BITS)];
147 fixed64 lsp_pow_m_table2[(1 << LSP_POW_BITS)];
148
149#ifdef TRACE
150
151 int frame_count;
152#endif
153}
154WMADecodeContext;
155
156int wma_decode_init(WMADecodeContext* s, asf_waveformatex_t *wfx);
157int wma_decode_superframe(WMADecodeContext* s,
158 void *data, int *data_size,
159 uint8_t *buf, int buf_size);
160int wma_decode_end(WMADecodeContext *s);
161
162#endif