pass only one arg to wma_init().
[paraslash.git] / wmadec_filter.c
1 /*
2 * WMA compatible decoder
3 *
4 * Extracted 2009 from the mplayer source code 2009-02-10.
5 *
6 * Copyright (c) 2002 The FFmpeg Project
7 *
8 * Licensed under the GNU Lesser General Public License.
9 * For licencing details see COPYING.LIB.
10 */
11
12 /** \file wmadec_filter.c paraslash's WMA decoder. */
13
14 /*
15 * This decoder handles Microsoft Windows Media Audio data version 2.
16 */
17
18 #define _XOPEN_SOURCE 600
19
20 #include <sys/time.h>
21 #include <inttypes.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <math.h>
25 #include <string.h>
26 #include <regex.h>
27
28 #include "para.h"
29 #include "error.h"
30 #include "list.h"
31 #include "ggo.h"
32 #include "string.h"
33 #include "sched.h"
34 #include "filter.h"
35 #include "bitstream.h"
36 #include "imdct.h"
37 #include "wma.h"
38 #include "wmadata.h"
39
40
41 /* size of blocks */
42 #define BLOCK_MIN_BITS 7
43 #define BLOCK_MAX_BITS 11
44 #define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS)
45
46 #define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1)
47
48 /* XXX: find exact max size */
49 #define HIGH_BAND_MAX_SIZE 16
50
51 /* XXX: is it a suitable value ? */
52 #define MAX_CODED_SUPERFRAME_SIZE 16384
53
54 #define MAX_CHANNELS 2
55
56 #define NOISE_TAB_SIZE 8192
57
58 #define LSP_POW_BITS 7
59
60 struct private_wmadec_data {
61 struct asf_header_info ahi;
62 struct getbit_context gb;
63 int use_bit_reservoir;
64 int use_variable_block_len;
65 int use_exp_vlc; ///< exponent coding: 0 = lsp, 1 = vlc + delta
66 int use_noise_coding; ///< true if perceptual noise is added
67 int byte_offset_bits;
68 struct vlc exp_vlc;
69 int exponent_sizes[BLOCK_NB_SIZES];
70 uint16_t exponent_bands[BLOCK_NB_SIZES][25];
71 int high_band_start[BLOCK_NB_SIZES]; ///< index of first coef in high band
72 int coefs_start; ///< first coded coef
73 int coefs_end[BLOCK_NB_SIZES]; ///< max number of coded coefficients
74 int exponent_high_sizes[BLOCK_NB_SIZES];
75 int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE];
76 struct vlc hgain_vlc;
77
78 /* coded values in high bands */
79 int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
80 int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
81
82 /* there are two possible tables for spectral coefficients */
83 struct vlc coef_vlc[2];
84 uint16_t *run_table[2];
85 uint16_t *level_table[2];
86 uint16_t *int_table[2];
87 const struct coef_vlc_table *coef_vlcs[2];
88 /* frame info */
89 int frame_len; ///< frame length in samples
90 int frame_len_bits; ///< frame_len = 1 << frame_len_bits
91 int nb_block_sizes; ///< number of block sizes
92 /* block info */
93 int reset_block_lengths;
94 int block_len_bits; ///< log2 of current block length
95 int next_block_len_bits; ///< log2 of next block length
96 int prev_block_len_bits; ///< log2 of prev block length
97 int block_len; ///< block length in samples
98 int block_pos; ///< current position in frame
99 uint8_t ms_stereo; ///< true if mid/side stereo mode
100 uint8_t channel_coded[MAX_CHANNELS]; ///< true if channel is coded
101 int exponents_bsize[MAX_CHANNELS]; ///< log2 ratio frame/exp. length
102 float exponents[MAX_CHANNELS][BLOCK_MAX_SIZE];
103 float max_exponent[MAX_CHANNELS];
104 int16_t coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE];
105 float coefs[MAX_CHANNELS][BLOCK_MAX_SIZE];
106 float output[BLOCK_MAX_SIZE * 2];
107 struct mdct_context *mdct_ctx[BLOCK_NB_SIZES];
108 float *windows[BLOCK_NB_SIZES];
109 /* output buffer for one frame and the last for IMDCT windowing */
110 float frame_out[MAX_CHANNELS][BLOCK_MAX_SIZE * 2];
111 /* last frame info */
112 uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */
113 int last_bitoffset;
114 int last_superframe_len;
115 float noise_table[NOISE_TAB_SIZE];
116 int noise_index;
117 float noise_mult; /* XXX: suppress that and integrate it in the noise array */
118 /* lsp_to_curve tables */
119 float lsp_cos_table[BLOCK_MAX_SIZE];
120 float lsp_pow_e_table[256];
121 float lsp_pow_m_table1[(1 << LSP_POW_BITS)];
122 float lsp_pow_m_table2[(1 << LSP_POW_BITS)];
123 };
124
125 #define EXPVLCBITS 8
126 #define EXPMAX ((19 + EXPVLCBITS - 1) / EXPVLCBITS)
127
128 #define HGAINVLCBITS 9
129 #define HGAINMAX ((13 + HGAINVLCBITS - 1) / HGAINVLCBITS)
130
131 #define VLCBITS 9
132 #define VLCMAX ((22 + VLCBITS - 1) / VLCBITS)
133
134 DECLARE_ALIGNED(16, float, ff_sine_128[128]);
135 DECLARE_ALIGNED(16, float, ff_sine_256[256]);
136 DECLARE_ALIGNED(16, float, ff_sine_512[512]);
137 DECLARE_ALIGNED(16, float, ff_sine_1024[1024]);
138 DECLARE_ALIGNED(16, float, ff_sine_2048[2048]);
139 DECLARE_ALIGNED(16, float, ff_sine_4096[4096]);
140
141 static float *ff_sine_windows[6] = {
142 ff_sine_128, ff_sine_256, ff_sine_512, ff_sine_1024,
143 ff_sine_2048, ff_sine_4096
144 };
145
146 /* Generate a sine window. */
147 static void sine_window_init(float *window, int n)
148 {
149 int i;
150
151 for (i = 0; i < n; i++)
152 window[i] = sinf((i + 0.5) * (M_PI / (2.0 * n)));
153 }
154
155 static void wmadec_cleanup(struct private_wmadec_data *pwd)
156 {
157 int i;
158
159 for (i = 0; i < pwd->nb_block_sizes; i++)
160 imdct_end(pwd->mdct_ctx[i]);
161 if (pwd->use_exp_vlc)
162 free_vlc(&pwd->exp_vlc);
163 if (pwd->use_noise_coding)
164 free_vlc(&pwd->hgain_vlc);
165 for (i = 0; i < 2; i++) {
166 free_vlc(&pwd->coef_vlc[i]);
167 free(pwd->run_table[i]);
168 free(pwd->level_table[i]);
169 free(pwd->int_table[i]);
170 }
171 }
172
173 /* XXX: use same run/length optimization as mpeg decoders */
174 //FIXME maybe split decode / encode or pass flag
175 static void init_coef_vlc(struct vlc *vlc, uint16_t **prun_table,
176 uint16_t **plevel_table, uint16_t **pint_table,
177 const struct coef_vlc_table *vlc_table)
178 {
179 int n = vlc_table->n;
180 const uint8_t *table_bits = vlc_table->huffbits;
181 const uint32_t *table_codes = vlc_table->huffcodes;
182 const uint16_t *levels_table = vlc_table->levels;
183 uint16_t *run_table, *level_table, *int_table;
184 int i, l, j, k, level;
185
186 init_vlc(vlc, VLCBITS, n, table_bits, 1, 1, table_codes, 4, 4);
187
188 run_table = para_malloc(n * sizeof(uint16_t));
189 level_table = para_malloc(n * sizeof(uint16_t));
190 int_table = para_malloc(n * sizeof(uint16_t));
191 i = 2;
192 level = 1;
193 k = 0;
194 while (i < n) {
195 int_table[k] = i;
196 l = levels_table[k++];
197 for (j = 0; j < l; j++) {
198 run_table[i] = j;
199 level_table[i] = level;
200 i++;
201 }
202 level++;
203 }
204 *prun_table = run_table;
205 *plevel_table = level_table;
206 *pint_table = int_table;
207 }
208
209 /* compute the scale factor band sizes for each MDCT block size */
210 static void compute_scale_factor_band_sizes(struct private_wmadec_data *pwd,
211 float high_freq)
212 {
213 struct asf_header_info *ahi = &pwd->ahi;
214 int a, b, pos, lpos, k, block_len, i, j, n;
215 const uint8_t *table;
216
217 pwd->coefs_start = 0;
218 for (k = 0; k < pwd->nb_block_sizes; k++) {
219 block_len = pwd->frame_len >> k;
220
221 table = NULL;
222 a = pwd->frame_len_bits - BLOCK_MIN_BITS - k;
223 if (a < 3) {
224 if (ahi->sample_rate >= 44100)
225 table = exponent_band_44100[a];
226 else if (ahi->sample_rate >= 32000)
227 table = exponent_band_32000[a];
228 else if (ahi->sample_rate >= 22050)
229 table = exponent_band_22050[a];
230 }
231 if (table) {
232 n = *table++;
233 for (i = 0; i < n; i++)
234 pwd->exponent_bands[k][i] = table[i];
235 pwd->exponent_sizes[k] = n;
236 } else {
237 j = 0;
238 lpos = 0;
239 for (i = 0; i < 25; i++) {
240 a = wma_critical_freqs[i];
241 b = ahi->sample_rate;
242 pos = ((block_len * 2 * a) + (b << 1)) / (4 * b);
243 pos <<= 2;
244 if (pos > block_len)
245 pos = block_len;
246 if (pos > lpos)
247 pwd->exponent_bands[k][j++] = pos - lpos;
248 if (pos >= block_len)
249 break;
250 lpos = pos;
251 }
252 pwd->exponent_sizes[k] = j;
253 }
254
255 /* max number of coefs */
256 pwd->coefs_end[k] = (pwd->frame_len - ((pwd->frame_len * 9) / 100)) >> k;
257 /* high freq computation */
258 pwd->high_band_start[k] = (int) ((block_len * 2 * high_freq)
259 / ahi->sample_rate + 0.5);
260 n = pwd->exponent_sizes[k];
261 j = 0;
262 pos = 0;
263 for (i = 0; i < n; i++) {
264 int start, end;
265 start = pos;
266 pos += pwd->exponent_bands[k][i];
267 end = pos;
268 if (start < pwd->high_band_start[k])
269 start = pwd->high_band_start[k];
270 if (end > pwd->coefs_end[k])
271 end = pwd->coefs_end[k];
272 if (end > start)
273 pwd->exponent_high_bands[k][j++] = end - start;
274 }
275 pwd->exponent_high_sizes[k] = j;
276 }
277 }
278
279 static int wma_init(struct private_wmadec_data *pwd)
280 {
281 int i;
282 float bps1, high_freq;
283 volatile float bps;
284 int sample_rate1;
285 int coef_vlc_table;
286 struct asf_header_info *ahi = &pwd->ahi;
287 int flags2 = ahi->flags2;
288
289 if (ahi->sample_rate <= 0 || ahi->sample_rate > 50000
290 || ahi->channels <= 0 || ahi->channels > 8
291 || ahi->bit_rate <= 0)
292 return -E_WMA_BAD_PARAMS;
293
294 /* compute MDCT block size */
295 if (ahi->sample_rate <= 16000) {
296 pwd->frame_len_bits = 9;
297 } else if (ahi->sample_rate <= 22050) {
298 pwd->frame_len_bits = 10;
299 } else {
300 pwd->frame_len_bits = 11;
301 }
302 pwd->frame_len = 1 << pwd->frame_len_bits;
303 if (pwd->use_variable_block_len) {
304 int nb_max, nb;
305 nb = ((flags2 >> 3) & 3) + 1;
306 if ((ahi->bit_rate / ahi->channels) >= 32000)
307 nb += 2;
308 nb_max = pwd->frame_len_bits - BLOCK_MIN_BITS;
309 if (nb > nb_max)
310 nb = nb_max;
311 pwd->nb_block_sizes = nb + 1;
312 } else
313 pwd->nb_block_sizes = 1;
314
315 /* init rate dependent parameters */
316 pwd->use_noise_coding = 1;
317 high_freq = ahi->sample_rate * 0.5;
318
319 /* wma2 rates are normalized */
320 sample_rate1 = ahi->sample_rate;
321 if (sample_rate1 >= 44100)
322 sample_rate1 = 44100;
323 else if (sample_rate1 >= 22050)
324 sample_rate1 = 22050;
325 else if (sample_rate1 >= 16000)
326 sample_rate1 = 16000;
327 else if (sample_rate1 >= 11025)
328 sample_rate1 = 11025;
329 else if (sample_rate1 >= 8000)
330 sample_rate1 = 8000;
331
332 bps = (float) ahi->bit_rate / (float) (ahi->channels * ahi->sample_rate);
333 pwd->byte_offset_bits = wma_log2((int) (bps * pwd->frame_len / 8.0 + 0.5)) + 2;
334 /*
335 * Compute high frequency value and choose if noise coding should be
336 * activated.
337 */
338 bps1 = bps;
339 if (ahi->channels == 2)
340 bps1 = bps * 1.6;
341 if (sample_rate1 == 44100) {
342 if (bps1 >= 0.61)
343 pwd->use_noise_coding = 0;
344 else
345 high_freq = high_freq * 0.4;
346 } else if (sample_rate1 == 22050) {
347 if (bps1 >= 1.16)
348 pwd->use_noise_coding = 0;
349 else if (bps1 >= 0.72)
350 high_freq = high_freq * 0.7;
351 else
352 high_freq = high_freq * 0.6;
353 } else if (sample_rate1 == 16000) {
354 if (bps > 0.5)
355 high_freq = high_freq * 0.5;
356 else
357 high_freq = high_freq * 0.3;
358 } else if (sample_rate1 == 11025) {
359 high_freq = high_freq * 0.7;
360 } else if (sample_rate1 == 8000) {
361 if (bps <= 0.625) {
362 high_freq = high_freq * 0.5;
363 } else if (bps > 0.75) {
364 pwd->use_noise_coding = 0;
365 } else {
366 high_freq = high_freq * 0.65;
367 }
368 } else {
369 if (bps >= 0.8) {
370 high_freq = high_freq * 0.75;
371 } else if (bps >= 0.6) {
372 high_freq = high_freq * 0.6;
373 } else {
374 high_freq = high_freq * 0.5;
375 }
376 }
377 PARA_INFO_LOG("channels=%d sample_rate=%d "
378 "bitrate=%d block_align=%d\n",
379 ahi->channels, ahi->sample_rate,
380 ahi->bit_rate, ahi->block_align);
381 PARA_INFO_LOG("frame_len=%d, bps=%f bps1=%f "
382 "high_freq=%f bitoffset=%d\n",
383 pwd->frame_len, bps, bps1,
384 high_freq, pwd->byte_offset_bits);
385 PARA_INFO_LOG("use_noise_coding=%d use_exp_vlc=%d nb_block_sizes=%d\n",
386 pwd->use_noise_coding, pwd->use_exp_vlc, pwd->nb_block_sizes);
387
388 compute_scale_factor_band_sizes(pwd, high_freq);
389 /* init MDCT windows : simple sinus window */
390 for (i = 0; i < pwd->nb_block_sizes; i++) {
391 int n;
392 n = 1 << (pwd->frame_len_bits - i);
393 sine_window_init(ff_sine_windows[pwd->frame_len_bits - i - 7], n);
394 pwd->windows[i] = ff_sine_windows[pwd->frame_len_bits - i - 7];
395 }
396
397 pwd->reset_block_lengths = 1;
398
399 if (pwd->use_noise_coding) {
400 /* init the noise generator */
401 if (pwd->use_exp_vlc)
402 pwd->noise_mult = 0.02;
403 else
404 pwd->noise_mult = 0.04;
405
406 {
407 unsigned int seed;
408 float norm;
409 seed = 1;
410 norm = (1.0 / (float) (1LL << 31)) * sqrt(3) * pwd->noise_mult;
411 for (i = 0; i < NOISE_TAB_SIZE; i++) {
412 seed = seed * 314159 + 1;
413 pwd->noise_table[i] = (float) ((int) seed) * norm;
414 }
415 }
416 }
417
418 /* choose the VLC tables for the coefficients */
419 coef_vlc_table = 2;
420 if (ahi->sample_rate >= 32000) {
421 if (bps1 < 0.72)
422 coef_vlc_table = 0;
423 else if (bps1 < 1.16)
424 coef_vlc_table = 1;
425 }
426 pwd->coef_vlcs[0] = &coef_vlcs[coef_vlc_table * 2];
427 pwd->coef_vlcs[1] = &coef_vlcs[coef_vlc_table * 2 + 1];
428 init_coef_vlc(&pwd->coef_vlc[0], &pwd->run_table[0], &pwd->level_table[0],
429 &pwd->int_table[0], pwd->coef_vlcs[0]);
430 init_coef_vlc(&pwd->coef_vlc[1], &pwd->run_table[1], &pwd->level_table[1],
431 &pwd->int_table[1], pwd->coef_vlcs[1]);
432 return 0;
433 }
434
435 static void wma_lsp_to_curve_init(struct private_wmadec_data *pwd, int frame_len)
436 {
437 float wdel, a, b;
438 int i, e, m;
439
440 wdel = M_PI / frame_len;
441 for (i = 0; i < frame_len; i++)
442 pwd->lsp_cos_table[i] = 2.0f * cos(wdel * i);
443
444 /* tables for x^-0.25 computation */
445 for (i = 0; i < 256; i++) {
446 e = i - 126;
447 pwd->lsp_pow_e_table[i] = pow(2.0, e * -0.25);
448 }
449
450 /* These two tables are needed to avoid two operations in pow_m1_4. */
451 b = 1.0;
452 for (i = (1 << LSP_POW_BITS) - 1; i >= 0; i--) {
453 m = (1 << LSP_POW_BITS) + i;
454 a = (float) m *(0.5 / (1 << LSP_POW_BITS));
455 a = pow(a, -0.25);
456 pwd->lsp_pow_m_table1[i] = 2 * a - b;
457 pwd->lsp_pow_m_table2[i] = b - a;
458 b = a;
459 }
460 }
461
462 static int wma_decode_init(char *initial_buf, int len, struct private_wmadec_data **result)
463 {
464 struct private_wmadec_data *pwd;
465 int ret, i;
466
467 PARA_NOTICE_LOG("initial buf: %d bytes\n", len);
468 pwd = para_calloc(sizeof(*pwd));
469 ret = read_asf_header(initial_buf, len, &pwd->ahi);
470 if (ret <= 0) {
471 free(pwd);
472 return ret;
473 }
474
475 pwd->use_exp_vlc = pwd->ahi.flags2 & 0x0001;
476 pwd->use_bit_reservoir = pwd->ahi.flags2 & 0x0002;
477 pwd->use_variable_block_len = pwd->ahi.flags2 & 0x0004;
478
479 ret = wma_init(pwd);
480 if (ret < 0)
481 return ret;
482 /* init MDCT */
483 for (i = 0; i < pwd->nb_block_sizes; i++) {
484 ret = imdct_init(pwd->frame_len_bits - i + 1, &pwd->mdct_ctx[i]);
485 if (ret < 0)
486 return ret;
487 }
488 if (pwd->use_noise_coding) {
489 PARA_INFO_LOG("using noise coding\n");
490 init_vlc(&pwd->hgain_vlc, HGAINVLCBITS,
491 sizeof(ff_wma_hgain_huffbits), ff_wma_hgain_huffbits,
492 1, 1, ff_wma_hgain_huffcodes, 2, 2);
493 }
494
495 if (pwd->use_exp_vlc) {
496 PARA_INFO_LOG("using exp_vlc\n");
497 init_vlc(&pwd->exp_vlc, EXPVLCBITS,
498 sizeof(ff_wma_scale_huffbits), ff_wma_scale_huffbits,
499 1, 1, ff_wma_scale_huffcodes, 4, 4);
500 } else {
501 PARA_INFO_LOG("using curve\n");
502 wma_lsp_to_curve_init(pwd, pwd->frame_len);
503 }
504 *result = pwd;
505 return pwd->ahi.header_len;
506 }
507
508 /**
509 * compute x^-0.25 with an exponent and mantissa table. We use linear
510 * interpolation to reduce the mantissa table size at a small speed
511 * expense (linear interpolation approximately doubles the number of
512 * bits of precision).
513 */
514 static inline float pow_m1_4(struct private_wmadec_data *pwd, float x)
515 {
516 union {
517 float f;
518 unsigned int v;
519 } u, t;
520 unsigned int e, m;
521 float a, b;
522
523 u.f = x;
524 e = u.v >> 23;
525 m = (u.v >> (23 - LSP_POW_BITS)) & ((1 << LSP_POW_BITS) - 1);
526 /* build interpolation scale: 1 <= t < 2. */
527 t.v = ((u.v << LSP_POW_BITS) & ((1 << 23) - 1)) | (127 << 23);
528 a = pwd->lsp_pow_m_table1[m];
529 b = pwd->lsp_pow_m_table2[m];
530 return pwd->lsp_pow_e_table[e] * (a + b * t.f);
531 }
532
533 static void wma_lsp_to_curve(struct private_wmadec_data *pwd,
534 float *out, float *val_max_ptr, int n, float *lsp)
535 {
536 int i, j;
537 float p, q, w, v, val_max;
538
539 val_max = 0;
540 for (i = 0; i < n; i++) {
541 p = 0.5f;
542 q = 0.5f;
543 w = pwd->lsp_cos_table[i];
544 for (j = 1; j < NB_LSP_COEFS; j += 2) {
545 q *= w - lsp[j - 1];
546 p *= w - lsp[j];
547 }
548 p *= p * (2.0f - w);
549 q *= q * (2.0f + w);
550 v = p + q;
551 v = pow_m1_4(pwd, v);
552 if (v > val_max)
553 val_max = v;
554 out[i] = v;
555 }
556 *val_max_ptr = val_max;
557 }
558
559 /* Decode exponents coded with LSP coefficients (same idea as Vorbis). */
560 static void decode_exp_lsp(struct private_wmadec_data *pwd, int ch)
561 {
562 float lsp_coefs[NB_LSP_COEFS];
563 int val, i;
564
565 for (i = 0; i < NB_LSP_COEFS; i++) {
566 if (i == 0 || i >= 8)
567 val = get_bits(&pwd->gb, 3);
568 else
569 val = get_bits(&pwd->gb, 4);
570 lsp_coefs[i] = ff_wma_lsp_codebook[i][val];
571 }
572
573 wma_lsp_to_curve(pwd, pwd->exponents[ch], &pwd->max_exponent[ch],
574 pwd->block_len, lsp_coefs);
575 }
576
577 /*
578 * Parse a vlc code, faster then get_vlc().
579 *
580 * \param bits The number of bits which will be read at once, must be
581 * identical to nb_bits in init_vlc()
582 *
583 * \param max_depth The number of times bits bits must be read to completely
584 * read the longest vlc code = (max_vlc_length + bits - 1) / bits.
585 */
586 static int get_vlc2(struct getbit_context *s, VLC_TYPE(*table)[2],
587 int bits, int max_depth)
588 {
589 int code;
590
591 OPEN_READER(re, s)
592 UPDATE_CACHE(re, s)
593 GET_VLC(code, re, s, table, bits, max_depth)
594 CLOSE_READER(re, s)
595 return code;
596 }
597
598 /* Decode exponents coded with VLC codes. */
599 static int decode_exp_vlc(struct private_wmadec_data *pwd, int ch)
600 {
601 int last_exp, n, code;
602 const uint16_t *ptr, *band_ptr;
603 float v, *q, max_scale, *q_end;
604
605 band_ptr = pwd->exponent_bands[pwd->frame_len_bits - pwd->block_len_bits];
606 ptr = band_ptr;
607 q = pwd->exponents[ch];
608 q_end = q + pwd->block_len;
609 max_scale = 0;
610 last_exp = 36;
611
612 while (q < q_end) {
613 code = get_vlc2(&pwd->gb, pwd->exp_vlc.table, EXPVLCBITS, EXPMAX);
614 if (code < 0)
615 return -1;
616 /* NOTE: this offset is the same as MPEG4 AAC ! */
617 last_exp += code - 60;
618 /* XXX: use a table */
619 v = pow(10, last_exp * (1.0 / 16.0));
620 if (v > max_scale)
621 max_scale = v;
622 n = *ptr++;
623 do {
624 *q++ = v;
625 } while (--n);
626 }
627 pwd->max_exponent[ch] = max_scale;
628 return 0;
629 }
630
631 /* compute src0 * src1 + src2 */
632 static inline void vector_mult_add(float *dst, const float *src0, const float *src1,
633 const float *src2, int len)
634 {
635 int i;
636
637 for (i = 0; i < len; i++)
638 dst[i] = src0[i] * src1[i] + src2[i];
639 }
640
641 static inline void vector_mult_reverse(float *dst, const float *src0,
642 const float *src1, int len)
643 {
644 int i;
645
646 src1 += len - 1;
647 for (i = 0; i < len; i++)
648 dst[i] = src0[i] * src1[-i];
649 }
650
651 /**
652 * Apply MDCT window and add into output.
653 *
654 * We ensure that when the windows overlap their squared sum
655 * is always 1 (MDCT reconstruction rule).
656 */
657 static void wma_window(struct private_wmadec_data *pwd, float *out)
658 {
659 float *in = pwd->output;
660 int block_len, bsize, n;
661
662 /* left part */
663 if (pwd->block_len_bits <= pwd->prev_block_len_bits) {
664 block_len = pwd->block_len;
665 bsize = pwd->frame_len_bits - pwd->block_len_bits;
666 vector_mult_add(out, in, pwd->windows[bsize], out, block_len);
667 } else {
668 block_len = 1 << pwd->prev_block_len_bits;
669 n = (pwd->block_len - block_len) / 2;
670 bsize = pwd->frame_len_bits - pwd->prev_block_len_bits;
671 vector_mult_add(out + n, in + n, pwd->windows[bsize], out + n,
672 block_len);
673 memcpy(out + n + block_len, in + n + block_len,
674 n * sizeof(float));
675 }
676 out += pwd->block_len;
677 in += pwd->block_len;
678 /* right part */
679 if (pwd->block_len_bits <= pwd->next_block_len_bits) {
680 block_len = pwd->block_len;
681 bsize = pwd->frame_len_bits - pwd->block_len_bits;
682 vector_mult_reverse(out, in, pwd->windows[bsize], block_len);
683 } else {
684 block_len = 1 << pwd->next_block_len_bits;
685 n = (pwd->block_len - block_len) / 2;
686 bsize = pwd->frame_len_bits - pwd->next_block_len_bits;
687 memcpy(out, in, n * sizeof(float));
688 vector_mult_reverse(out + n, in + n, pwd->windows[bsize],
689 block_len);
690 memset(out + n + block_len, 0, n * sizeof(float));
691 }
692 }
693
694 static int wma_total_gain_to_bits(int total_gain)
695 {
696 if (total_gain < 15)
697 return 13;
698 else if (total_gain < 32)
699 return 12;
700 else if (total_gain < 40)
701 return 11;
702 else if (total_gain < 45)
703 return 10;
704 else
705 return 9;
706 }
707
708 /**
709 * @return 0 if OK. 1 if last block of frame. return -1 if
710 * unrecorrable error.
711 */
712 static int wma_decode_block(struct private_wmadec_data *pwd)
713 {
714 int n, v, ch, code, bsize;
715 int coef_nb_bits, total_gain;
716 int nb_coefs[MAX_CHANNELS];
717 float mdct_norm;
718
719 /* compute current block length */
720 if (pwd->use_variable_block_len) {
721 n = wma_log2(pwd->nb_block_sizes - 1) + 1;
722
723 if (pwd->reset_block_lengths) {
724 pwd->reset_block_lengths = 0;
725 v = get_bits(&pwd->gb, n);
726 if (v >= pwd->nb_block_sizes)
727 return -1;
728 pwd->prev_block_len_bits = pwd->frame_len_bits - v;
729 v = get_bits(&pwd->gb, n);
730 if (v >= pwd->nb_block_sizes)
731 return -1;
732 pwd->block_len_bits = pwd->frame_len_bits - v;
733 } else {
734 /* update block lengths */
735 pwd->prev_block_len_bits = pwd->block_len_bits;
736 pwd->block_len_bits = pwd->next_block_len_bits;
737 }
738 v = get_bits(&pwd->gb, n);
739 if (v >= pwd->nb_block_sizes)
740 return -1;
741 pwd->next_block_len_bits = pwd->frame_len_bits - v;
742 } else {
743 /* fixed block len */
744 pwd->next_block_len_bits = pwd->frame_len_bits;
745 pwd->prev_block_len_bits = pwd->frame_len_bits;
746 pwd->block_len_bits = pwd->frame_len_bits;
747 }
748
749 /* now check if the block length is coherent with the frame length */
750 pwd->block_len = 1 << pwd->block_len_bits;
751 if ((pwd->block_pos + pwd->block_len) > pwd->frame_len)
752 return -E_INCOHERENT_BLOCK_LEN;
753
754 if (pwd->ahi.channels == 2)
755 pwd->ms_stereo = get_bits1(&pwd->gb);
756 v = 0;
757 for (ch = 0; ch < pwd->ahi.channels; ch++) {
758 int a = get_bits1(&pwd->gb);
759 pwd->channel_coded[ch] = a;
760 v |= a;
761 }
762
763 bsize = pwd->frame_len_bits - pwd->block_len_bits;
764
765 /* if no channel coded, no need to go further */
766 /* XXX: fix potential framing problems */
767 if (!v)
768 goto next;
769
770 /* read total gain and extract corresponding number of bits for
771 coef escape coding */
772 total_gain = 1;
773 for (;;) {
774 int a = get_bits(&pwd->gb, 7);
775 total_gain += a;
776 if (a != 127)
777 break;
778 }
779
780 coef_nb_bits = wma_total_gain_to_bits(total_gain);
781
782 /* compute number of coefficients */
783 n = pwd->coefs_end[bsize] - pwd->coefs_start;
784 for (ch = 0; ch < pwd->ahi.channels; ch++)
785 nb_coefs[ch] = n;
786
787 /* complex coding */
788 if (pwd->use_noise_coding) {
789 for (ch = 0; ch < pwd->ahi.channels; ch++) {
790 if (pwd->channel_coded[ch]) {
791 int i, m, a;
792 m = pwd->exponent_high_sizes[bsize];
793 for (i = 0; i < m; i++) {
794 a = get_bits1(&pwd->gb);
795 pwd->high_band_coded[ch][i] = a;
796 /* if noise coding, the coefficients are not transmitted */
797 if (a)
798 nb_coefs[ch] -=
799 pwd->
800 exponent_high_bands[bsize]
801 [i];
802 }
803 }
804 }
805 for (ch = 0; ch < pwd->ahi.channels; ch++) {
806 if (pwd->channel_coded[ch]) {
807 int i, val;
808
809 n = pwd->exponent_high_sizes[bsize];
810 val = (int) 0x80000000;
811 for (i = 0; i < n; i++) {
812 if (pwd->high_band_coded[ch][i]) {
813 if (val == (int) 0x80000000) {
814 val =
815 get_bits(&pwd->gb,
816 7) - 19;
817 } else {
818 code =
819 get_vlc2(&pwd->gb,
820 pwd->
821 hgain_vlc.
822 table,
823 HGAINVLCBITS,
824 HGAINMAX);
825 if (code < 0)
826 return -1;
827 val += code - 18;
828 }
829 pwd->high_band_values[ch][i] =
830 val;
831 }
832 }
833 }
834 }
835 }
836
837 /* exponents can be reused in short blocks. */
838 if ((pwd->block_len_bits == pwd->frame_len_bits) || get_bits1(&pwd->gb)) {
839 for (ch = 0; ch < pwd->ahi.channels; ch++) {
840 if (pwd->channel_coded[ch]) {
841 if (pwd->use_exp_vlc) {
842 if (decode_exp_vlc(pwd, ch) < 0)
843 return -1;
844 } else {
845 decode_exp_lsp(pwd, ch);
846 }
847 pwd->exponents_bsize[ch] = bsize;
848 }
849 }
850 }
851
852 /* parse spectral coefficients : just RLE encoding */
853 for (ch = 0; ch < pwd->ahi.channels; ch++) {
854 if (pwd->channel_coded[ch]) {
855 struct vlc *coef_vlc;
856 int level, run, sign, tindex;
857 int16_t *ptr, *eptr;
858 const uint16_t *level_table, *run_table;
859
860 /* special VLC tables are used for ms stereo because
861 there is potentially less energy there */
862 tindex = (ch == 1 && pwd->ms_stereo);
863 coef_vlc = &pwd->coef_vlc[tindex];
864 run_table = pwd->run_table[tindex];
865 level_table = pwd->level_table[tindex];
866 /* XXX: optimize */
867 ptr = &pwd->coefs1[ch][0];
868 eptr = ptr + nb_coefs[ch];
869 memset(ptr, 0, pwd->block_len * sizeof(int16_t));
870 for (;;) {
871 code =
872 get_vlc2(&pwd->gb, coef_vlc->table, VLCBITS,
873 VLCMAX);
874 if (code < 0)
875 return -1;
876 if (code == 1) {
877 /* EOB */
878 break;
879 } else if (code == 0) {
880 /* escape */
881 level = get_bits(&pwd->gb, coef_nb_bits);
882 /* NOTE: this is rather suboptimal. reading
883 block_len_bits would be better */
884 run =
885 get_bits(&pwd->gb, pwd->frame_len_bits);
886 } else {
887 /* normal code */
888 run = run_table[code];
889 level = level_table[code];
890 }
891 sign = get_bits1(&pwd->gb);
892 if (!sign)
893 level = -level;
894 ptr += run;
895 if (ptr >= eptr) {
896 PARA_ERROR_LOG("overflow in spectral RLE, ignoring\n");
897 break;
898 }
899 *ptr++ = level;
900 /* NOTE: EOB can be omitted */
901 if (ptr >= eptr)
902 break;
903 }
904 }
905 }
906
907 /* normalize */
908 {
909 int n4 = pwd->block_len / 2;
910 mdct_norm = 1.0 / (float) n4;
911 }
912
913 /* finally compute the MDCT coefficients */
914 for (ch = 0; ch < pwd->ahi.channels; ch++) {
915 if (pwd->channel_coded[ch]) {
916 int16_t *coefs1;
917 float *coefs, *exponents, mult, mult1, noise;
918 int i, j, n1, last_high_band, esize;
919 float exp_power[HIGH_BAND_MAX_SIZE];
920
921 coefs1 = pwd->coefs1[ch];
922 exponents = pwd->exponents[ch];
923 esize = pwd->exponents_bsize[ch];
924 mult = pow(10, total_gain * 0.05) / pwd->max_exponent[ch];
925 mult *= mdct_norm;
926 coefs = pwd->coefs[ch];
927 if (pwd->use_noise_coding) {
928 mult1 = mult;
929 /* very low freqs : noise */
930 for (i = 0; i < pwd->coefs_start; i++) {
931 *coefs++ =
932 pwd->noise_table[pwd->noise_index] *
933 exponents[i << bsize >> esize] *
934 mult1;
935 pwd->noise_index =
936 (pwd->noise_index +
937 1) & (NOISE_TAB_SIZE - 1);
938 }
939
940 n1 = pwd->exponent_high_sizes[bsize];
941
942 /* compute power of high bands */
943 exponents = pwd->exponents[ch] +
944 (pwd->high_band_start[bsize] << bsize);
945 last_high_band = 0; /* avoid warning */
946 for (j = 0; j < n1; j++) {
947 n = pwd->exponent_high_bands[pwd->
948 frame_len_bits
949 -
950 pwd->
951 block_len_bits]
952 [j];
953 if (pwd->high_band_coded[ch][j]) {
954 float e2, val;
955 e2 = 0;
956 for (i = 0; i < n; i++) {
957 val = exponents[i << bsize
958 >> esize];
959 e2 += val * val;
960 }
961 exp_power[j] = e2 / n;
962 last_high_band = j;
963 }
964 exponents += n << bsize;
965 }
966
967 /* main freqs and high freqs */
968 exponents =
969 pwd->exponents[ch] +
970 (pwd->coefs_start << bsize);
971 for (j = -1; j < n1; j++) {
972 if (j < 0) {
973 n = pwd->high_band_start[bsize] -
974 pwd->coefs_start;
975 } else {
976 n = pwd->exponent_high_bands[pwd->
977 frame_len_bits
978 -
979 pwd->
980 block_len_bits]
981 [j];
982 }
983 if (j >= 0 && pwd->high_band_coded[ch][j]) {
984 /* use noise with specified power */
985 mult1 =
986 sqrt(exp_power[j] /
987 exp_power
988 [last_high_band]);
989 /* XXX: use a table */
990 mult1 =
991 mult1 * pow(10,
992 pwd->
993 high_band_values
994 [ch][j] * 0.05);
995 mult1 =
996 mult1 /
997 (pwd->max_exponent[ch] *
998 pwd->noise_mult);
999 mult1 *= mdct_norm;
1000 for (i = 0; i < n; i++) {
1001 noise =
1002 pwd->noise_table[pwd->
1003 noise_index];
1004 pwd->noise_index =
1005 (pwd->noise_index +
1006 1) &
1007 (NOISE_TAB_SIZE -
1008 1);
1009 *coefs++ =
1010 noise *
1011 exponents[i << bsize
1012 >> esize]
1013 * mult1;
1014 }
1015 exponents += n << bsize;
1016 } else {
1017 /* coded values + small noise */
1018 for (i = 0; i < n; i++) {
1019 noise =
1020 pwd->noise_table[pwd->
1021 noise_index];
1022 pwd->noise_index =
1023 (pwd->noise_index +
1024 1) &
1025 (NOISE_TAB_SIZE -
1026 1);
1027 *coefs++ =
1028 ((*coefs1++) +
1029 noise) *
1030 exponents[i << bsize
1031 >> esize]
1032 * mult;
1033 }
1034 exponents += n << bsize;
1035 }
1036 }
1037
1038 /* very high freqs : noise */
1039 n = pwd->block_len - pwd->coefs_end[bsize];
1040 mult1 =
1041 mult * exponents[((-1 << bsize)) >> esize];
1042 for (i = 0; i < n; i++) {
1043 *coefs++ =
1044 pwd->noise_table[pwd->noise_index] *
1045 mult1;
1046 pwd->noise_index =
1047 (pwd->noise_index +
1048 1) & (NOISE_TAB_SIZE - 1);
1049 }
1050 } else {
1051 /* XXX: optimize more */
1052 for (i = 0; i < pwd->coefs_start; i++)
1053 *coefs++ = 0.0;
1054 n = nb_coefs[ch];
1055 for (i = 0; i < n; i++) {
1056 *coefs++ =
1057 coefs1[i] *
1058 exponents[i << bsize >> esize] *
1059 mult;
1060 }
1061 n = pwd->block_len - pwd->coefs_end[bsize];
1062 for (i = 0; i < n; i++)
1063 *coefs++ = 0.0;
1064 }
1065 }
1066 }
1067
1068 if (pwd->ms_stereo && pwd->channel_coded[1]) {
1069 float a, b;
1070 int i;
1071
1072 /*
1073 * Nominal case for ms stereo: we do it before mdct.
1074 *
1075 * No need to optimize this case because it should almost never
1076 * happen.
1077 */
1078 if (!pwd->channel_coded[0]) {
1079 PARA_NOTICE_LOG("rare ms-stereo\n");
1080 memset(pwd->coefs[0], 0, sizeof(float) * pwd->block_len);
1081 pwd->channel_coded[0] = 1;
1082 }
1083 for (i = 0; i < pwd->block_len; i++) {
1084 a = pwd->coefs[0][i];
1085 b = pwd->coefs[1][i];
1086 pwd->coefs[0][i] = a + b;
1087 pwd->coefs[1][i] = a - b;
1088 }
1089 }
1090
1091 next:
1092 for (ch = 0; ch < pwd->ahi.channels; ch++) {
1093 int n4, index;
1094
1095 n = pwd->block_len;
1096 n4 = pwd->block_len / 2;
1097 if (pwd->channel_coded[ch])
1098 imdct(pwd->mdct_ctx[bsize], pwd->output, pwd->coefs[ch]);
1099 else if (!(pwd->ms_stereo && ch == 1))
1100 memset(pwd->output, 0, sizeof(pwd->output));
1101
1102 /* multiply by the window and add in the frame */
1103 index = (pwd->frame_len / 2) + pwd->block_pos - n4;
1104 wma_window(pwd, &pwd->frame_out[ch][index]);
1105 }
1106
1107 /* update block number */
1108 pwd->block_pos += pwd->block_len;
1109 if (pwd->block_pos >= pwd->frame_len)
1110 return 1;
1111 else
1112 return 0;
1113 }
1114
1115 /*
1116 * Clip a signed integer value into the -32768,32767 range.
1117 *
1118 * \param a The value to clip.
1119 *
1120 * \return The clipped value.
1121 */
1122 static inline int16_t av_clip_int16(int a)
1123 {
1124 if ((a + 32768) & ~65535)
1125 return (a >> 31) ^ 32767;
1126 else
1127 return a;
1128 }
1129
1130 /* Decode a frame of frame_len samples. */
1131 static int wma_decode_frame(struct private_wmadec_data *pwd, int16_t *samples)
1132 {
1133 int ret, i, n, ch, incr;
1134 int16_t *ptr;
1135 float *iptr;
1136
1137 /* read each block */
1138 pwd->block_pos = 0;
1139 for (;;) {
1140 ret = wma_decode_block(pwd);
1141 if (ret < 0)
1142 return -1;
1143 if (ret)
1144 break;
1145 }
1146
1147 /* convert frame to integer */
1148 n = pwd->frame_len;
1149 incr = pwd->ahi.channels;
1150 for (ch = 0; ch < pwd->ahi.channels; ch++) {
1151 ptr = samples + ch;
1152 iptr = pwd->frame_out[ch];
1153
1154 for (i = 0; i < n; i++) {
1155 *ptr = av_clip_int16(lrintf(*iptr++));
1156 ptr += incr;
1157 }
1158 /* prepare for next block */
1159 memmove(&pwd->frame_out[ch][0], &pwd->frame_out[ch][pwd->frame_len],
1160 pwd->frame_len * sizeof(float));
1161 }
1162 return 0;
1163 }
1164
1165 static int wma_decode_superframe(struct private_wmadec_data *pwd, void *data,
1166 int *data_size, const uint8_t *buf, int buf_size)
1167 {
1168 int ret, nb_frames, bit_offset, i, pos, len;
1169 uint8_t *q;
1170 int16_t *samples;
1171 static int frame_count;
1172
1173 if (buf_size == 0) {
1174 pwd->last_superframe_len = 0;
1175 return 0;
1176 }
1177 if (buf_size < pwd->ahi.block_align)
1178 return 0;
1179 buf_size = pwd->ahi.block_align;
1180 samples = data;
1181 init_get_bits(&pwd->gb, buf, buf_size * 8);
1182 if (pwd->use_bit_reservoir) {
1183 /* read super frame header */
1184 skip_bits(&pwd->gb, 4); /* super frame index */
1185 nb_frames = get_bits(&pwd->gb, 4) - 1;
1186 // PARA_DEBUG_LOG("have %d frames\n", nb_frames);
1187 ret = -E_WMA_OUTPUT_SPACE;
1188 if ((nb_frames + 1) * pwd->ahi.channels * pwd->frame_len
1189 * sizeof(int16_t) > *data_size)
1190 goto fail;
1191
1192 bit_offset = get_bits(&pwd->gb, pwd->byte_offset_bits + 3);
1193
1194 if (pwd->last_superframe_len > 0) {
1195 /* add bit_offset bits to last frame */
1196 ret = -E_WMA_BAD_SUPERFRAME;
1197 if ((pwd->last_superframe_len + ((bit_offset + 7) >> 3)) >
1198 MAX_CODED_SUPERFRAME_SIZE)
1199 goto fail;
1200 q = pwd->last_superframe + pwd->last_superframe_len;
1201 len = bit_offset;
1202 while (len > 7) {
1203 *q++ = get_bits(&pwd->gb, 8);
1204 len -= 8;
1205 }
1206 if (len > 0)
1207 *q++ = get_bits(&pwd->gb, len) << (8 - len);
1208
1209 /* XXX: bit_offset bits into last frame */
1210 init_get_bits(&pwd->gb, pwd->last_superframe,
1211 MAX_CODED_SUPERFRAME_SIZE * 8);
1212 /* skip unused bits */
1213 if (pwd->last_bitoffset > 0)
1214 skip_bits(&pwd->gb, pwd->last_bitoffset);
1215 /*
1216 * This frame is stored in the last superframe and in
1217 * the current one.
1218 */
1219 ret = -E_WMA_DECODE;
1220 if (wma_decode_frame(pwd, samples) < 0)
1221 goto fail;
1222 frame_count++;
1223 samples += pwd->ahi.channels * pwd->frame_len;
1224 }
1225
1226 /* read each frame starting from bit_offset */
1227 pos = bit_offset + 4 + 4 + pwd->byte_offset_bits + 3;
1228 init_get_bits(&pwd->gb, buf + (pos >> 3),
1229 (MAX_CODED_SUPERFRAME_SIZE - (pos >> 3)) * 8);
1230 len = pos & 7;
1231 if (len > 0)
1232 skip_bits(&pwd->gb, len);
1233
1234 pwd->reset_block_lengths = 1;
1235 for (i = 0; i < nb_frames; i++) {
1236 ret = -E_WMA_DECODE;
1237 if (wma_decode_frame(pwd, samples) < 0)
1238 goto fail;
1239 frame_count++;
1240 samples += pwd->ahi.channels * pwd->frame_len;
1241 }
1242
1243 /* we copy the end of the frame in the last frame buffer */
1244 pos = get_bits_count(&pwd->gb) +
1245 ((bit_offset + 4 + 4 + pwd->byte_offset_bits + 3) & ~7);
1246 pwd->last_bitoffset = pos & 7;
1247 pos >>= 3;
1248 len = buf_size - pos;
1249 ret = -E_WMA_BAD_SUPERFRAME;
1250 if (len > MAX_CODED_SUPERFRAME_SIZE || len < 0)
1251 goto fail;
1252 pwd->last_superframe_len = len;
1253 memcpy(pwd->last_superframe, buf + pos, len);
1254 } else {
1255 PARA_DEBUG_LOG("not using bit reservoir\n");
1256 ret = -E_WMA_OUTPUT_SPACE;
1257 if (pwd->ahi.channels * pwd->frame_len * sizeof(int16_t) > *data_size)
1258 goto fail;
1259 /* single frame decode */
1260 ret = -E_WMA_DECODE;
1261 if (wma_decode_frame(pwd, samples) < 0)
1262 goto fail;
1263 frame_count++;
1264 samples += pwd->ahi.channels * pwd->frame_len;
1265 }
1266 PARA_DEBUG_LOG("frame_count: %d frame_len: %d, block_len: %d, "
1267 "outbytes: %d, eaten: %d\n",
1268 frame_count, pwd->frame_len, pwd->block_len,
1269 (int8_t *) samples - (int8_t *) data, pwd->ahi.block_align);
1270 *data_size = (int8_t *)samples - (int8_t *)data;
1271 return pwd->ahi.block_align;
1272 fail:
1273 /* reset the bit reservoir on errors */
1274 pwd->last_superframe_len = 0;
1275 return ret;
1276 }
1277
1278 static ssize_t wmadec_convert(char *inbuffer, size_t len,
1279 struct filter_node *fn)
1280 {
1281 int ret, out_size = fn->bufsize - fn->loaded;
1282 struct private_wmadec_data *pwd = fn->private_data;
1283
1284 if (out_size < 128 * 1024)
1285 return 0;
1286 if (!pwd) {
1287 ret = wma_decode_init(inbuffer, len, &pwd);
1288 if (ret <= 0)
1289 return ret;
1290 fn->private_data = pwd;
1291 fn->fc->channels = pwd->ahi.channels;
1292 fn->fc->samplerate = pwd->ahi.sample_rate;
1293 return pwd->ahi.header_len;
1294 }
1295 /* skip 31 bytes */
1296 if (len <= WMA_FRAME_SKIP + pwd->ahi.block_align)
1297 return 0;
1298 ret = wma_decode_superframe(pwd, fn->buf + fn->loaded,
1299 &out_size, (uint8_t *)inbuffer + WMA_FRAME_SKIP,
1300 len - WMA_FRAME_SKIP);
1301 if (ret < 0)
1302 return ret;
1303 fn->loaded += out_size;
1304 return ret + WMA_FRAME_SKIP;
1305 }
1306
1307 static void wmadec_close(struct filter_node *fn)
1308 {
1309 struct private_wmadec_data *pwd = fn->private_data;
1310
1311 if (!pwd)
1312 return;
1313 wmadec_cleanup(pwd);
1314 free(fn->buf);
1315 fn->buf = NULL;
1316 free(fn->private_data);
1317 fn->private_data = NULL;
1318 }
1319
1320 static void wmadec_open(struct filter_node *fn)
1321 {
1322 fn->bufsize = 1024 * 1024;
1323 fn->buf = para_malloc(fn->bufsize);
1324 fn->private_data = NULL;
1325 fn->loaded = 0;
1326 }
1327
1328 /**
1329 * The init function of the wma decoder.
1330 *
1331 * \param f Its fields are filled in by the function.
1332 */
1333 void wmadec_filter_init(struct filter *f)
1334 {
1335 f->open = wmadec_open;
1336 f->close = wmadec_close;
1337 f->convert = wmadec_convert;
1338 }