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
24 #include "bitstream.h" /* For GetBitContext */
27 //#include "dsputil.h" /* For MDCTContext */
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
61 int nb_block_sizes
; /* number of block sizes */
66 int version
; /* 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2) */
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 */
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
];
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 */
89 uint16_t *run_table
[2];
90 uint16_t *level_table
[2];
92 int frame_len
; /* frame length in samples */
93 int frame_len_bits
; /* frame_len = 1 << frame_len_bits */
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 fixed32 exponents
[MAX_CHANNELS
][BLOCK_MAX_SIZE
];
107 fixed32 max_exponent
[MAX_CHANNELS
];
108 int16_t coefs1
[MAX_CHANNELS
][BLOCK_MAX_SIZE
];
109 fixed32 (*coefs
)[MAX_CHANNELS
][BLOCK_MAX_SIZE
];
110 MDCTContext mdct_ctx
[BLOCK_NB_SIZES
];
111 fixed32
*windows
[BLOCK_NB_SIZES
];
112 /* output buffer for one frame and the last for IMDCT windowing */
113 fixed32 frame_out
[MAX_CHANNELS
][BLOCK_MAX_SIZE
* 2];
114 /* last frame info */
115 uint8_t last_superframe
[MAX_CODED_SUPERFRAME_SIZE
+ 4]; /* padding added */
117 int last_superframe_len
;
118 fixed32
*noise_table
;
120 fixed32 noise_mult
; /* XXX: suppress that and integrate it in the noise array */
121 /* lsp_to_curve tables */
122 fixed32 lsp_cos_table
[BLOCK_MAX_SIZE
];
123 fixed64 lsp_pow_e_table
[256];
124 fixed32 lsp_pow_m_table1
[(1 << LSP_POW_BITS
)];
125 fixed32 lsp_pow_m_table2
[(1 << LSP_POW_BITS
)];
127 /* State of current superframe decoding */
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
,
144 uint8_t *buf
, int buf_size
);