summaryrefslogtreecommitdiff
path: root/apps/codecs/libwma/wmadeci.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libwma/wmadeci.c')
-rw-r--r--apps/codecs/libwma/wmadeci.c211
1 files changed, 0 insertions, 211 deletions
diff --git a/apps/codecs/libwma/wmadeci.c b/apps/codecs/libwma/wmadeci.c
index dc45e64042..c266316cf9 100644
--- a/apps/codecs/libwma/wmadeci.c
+++ b/apps/codecs/libwma/wmadeci.c
@@ -297,217 +297,6 @@ int fft_calc_unscaled(FFTContext *s, FFTComplex *z)
297 return 0; 297 return 0;
298} 298}
299 299
300
301/* VLC decoding */
302
303#define GET_VLC(code, name, gb, table, bits, max_depth)\
304{\
305 int n, index, nb_bits;\
306\
307 index= SHOW_UBITS(name, gb, bits);\
308 code = table[index][0];\
309 n = table[index][1];\
310\
311 if(max_depth > 1 && n < 0){\
312 LAST_SKIP_BITS(name, gb, bits)\
313 UPDATE_CACHE(name, gb)\
314\
315 nb_bits = -n;\
316\
317 index= SHOW_UBITS(name, gb, nb_bits) + code;\
318 code = table[index][0];\
319 n = table[index][1];\
320 if(max_depth > 2 && n < 0){\
321 LAST_SKIP_BITS(name, gb, nb_bits)\
322 UPDATE_CACHE(name, gb)\
323\
324 nb_bits = -n;\
325\
326 index= SHOW_UBITS(name, gb, nb_bits) + code;\
327 code = table[index][0];\
328 n = table[index][1];\
329 }\
330 }\
331 SKIP_BITS(name, gb, n)\
332}
333
334
335//#define DEBUG_VLC
336
337#define GET_DATA(v, table, i, wrap, size) \
338{\
339 const uint8_t *ptr = (const uint8_t *)table + i * wrap;\
340 switch(size) {\
341 case 1:\
342 v = *(const uint8_t *)ptr;\
343 break;\
344 case 2:\
345 v = *(const uint16_t *)ptr;\
346 break;\
347 default:\
348 v = *(const uint32_t *)ptr;\
349 break;\
350 }\
351}
352
353// deprecated, dont use get_vlc for new code, use get_vlc2 instead or use GET_VLC directly
354static inline int get_vlc(GetBitContext *s, VLC *vlc)
355{
356 int code;
357 VLC_TYPE (*table)[2]= vlc->table;
358
359 OPEN_READER(re, s)
360 UPDATE_CACHE(re, s)
361
362 GET_VLC(code, re, s, table, vlc->bits, 3)
363
364 CLOSE_READER(re, s)
365 return code;
366}
367
368static int alloc_table(VLC *vlc, int size)
369{
370 int index;
371 index = vlc->table_size;
372 vlc->table_size += size;
373 if (vlc->table_size > vlc->table_allocated)
374 {
375 vlc->table_allocated += (1 << vlc->bits);
376 if (!vlc->table)
377 return -1;
378 }
379 return index;
380}
381
382static int build_table(VLC *vlc, int table_nb_bits,
383 int nb_codes,
384 const void *bits, int bits_wrap, int bits_size,
385 const void *codes, int codes_wrap, int codes_size,
386 uint32_t code_prefix, int n_prefix)
387{
388 int i, j, k, n, table_size, table_index, nb, n1, index;
389 uint32_t code;
390 VLC_TYPE (*table)[2];
391
392 table_size = 1 << table_nb_bits;
393 table_index = alloc_table(vlc, table_size);
394 if (table_index < 0)
395 return -1;
396 table = &vlc->table[table_index];
397
398 for(i=0;i<table_size;i++)
399 {
400 table[i][1] = 0; //bits
401 table[i][0] = -1; //codes
402 }
403
404 /* first pass: map codes and compute auxillary table sizes */
405 for(i=0;i<nb_codes;i++)
406 {
407 GET_DATA(n, bits, i, bits_wrap, bits_size);
408 GET_DATA(code, codes, i, codes_wrap, codes_size);
409 /* we accept tables with holes */
410 if (n <= 0)
411 continue;
412 /* if code matches the prefix, it is in the table */
413 n -= n_prefix;
414 if (n > 0 && (code >> n) == code_prefix)
415 {
416 if (n <= table_nb_bits)
417 {
418 /* no need to add another table */
419 j = (code << (table_nb_bits - n)) & (table_size - 1);
420 nb = 1 << (table_nb_bits - n);
421 for(k=0;k<nb;k++)
422 {
423 if (table[j][1] /*bits*/ != 0)
424 {
425 // PJJ exit(-1);
426 }
427 table[j][1] = n; //bits
428 table[j][0] = i; //code
429 j++;
430 }
431 }
432 else
433 {
434 n -= table_nb_bits;
435 j = (code >> n) & ((1 << table_nb_bits) - 1);
436 /* compute table size */
437 n1 = -table[j][1]; //bits
438 if (n > n1)
439 n1 = n;
440 table[j][1] = -n1; //bits
441 }
442 }
443 }
444
445 /* second pass : fill auxillary tables recursively */
446 for(i=0;i<table_size;i++)
447 {
448 n = table[i][1]; //bits
449 if (n < 0)
450 {
451 n = -n;
452 if (n > table_nb_bits)
453 {
454 n = table_nb_bits;
455 table[i][1] = -n; //bits
456 }
457 index = build_table(vlc, n, nb_codes,
458 bits, bits_wrap, bits_size,
459 codes, codes_wrap, codes_size,
460 (code_prefix << table_nb_bits) | i,
461 n_prefix + table_nb_bits);
462 if (index < 0)
463 return -1;
464 /* note: realloc has been done, so reload tables */
465 table = &vlc->table[table_index];
466 table[i][0] = index; //code
467 }
468 }
469 return table_index;
470}
471
472/* Build VLC decoding tables suitable for use with get_vlc().
473
474 'nb_bits' set thee decoding table size (2^nb_bits) entries. The
475 bigger it is, the faster is the decoding. But it should not be too
476 big to save memory and L1 cache. '9' is a good compromise.
477
478 'nb_codes' : number of vlcs codes
479
480 'bits' : table which gives the size (in bits) of each vlc code.
481
482 'codes' : table which gives the bit pattern of of each vlc code.
483
484 'xxx_wrap' : give the number of bytes between each entry of the
485 'bits' or 'codes' tables.
486
487 'xxx_size' : gives the number of bytes of each entry of the 'bits'
488 or 'codes' tables.
489
490 'wrap' and 'size' allows to use any memory configuration and types
491 (byte/word/long) to store the 'bits' and 'codes' tables.
492*/
493int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
494 const void *bits, int bits_wrap, int bits_size,
495 const void *codes, int codes_wrap, int codes_size)
496{
497 vlc->bits = nb_bits;
498 vlc->table_size = 0;
499
500 if (build_table(vlc, nb_bits, nb_codes,
501 bits, bits_wrap, bits_size,
502 codes, codes_wrap, codes_size,
503 0, 0) < 0)
504 {
505
506 return -1;
507 }
508 return 0;
509}
510
511/** 300/**
512 * init MDCT or IMDCT computation. 301 * init MDCT or IMDCT computation.
513 */ 302 */