summaryrefslogtreecommitdiff
path: root/apps/codecs/libwmapro
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libwmapro')
-rw-r--r--apps/codecs/libwmapro/wma.c55
-rw-r--r--apps/codecs/libwmapro/wma.h6
-rw-r--r--apps/codecs/libwmapro/wmapro_math.h15
-rw-r--r--apps/codecs/libwmapro/wmapro_mdct.c9
-rw-r--r--apps/codecs/libwmapro/wmaprodata.h49
-rw-r--r--apps/codecs/libwmapro/wmaprodec.c145
6 files changed, 243 insertions, 36 deletions
diff --git a/apps/codecs/libwmapro/wma.c b/apps/codecs/libwmapro/wma.c
index 4b36c84aad..b1b1268eea 100644
--- a/apps/codecs/libwmapro/wma.c
+++ b/apps/codecs/libwmapro/wma.c
@@ -523,3 +523,58 @@ int ff_wma_run_level_decode(AVCodecContext* avctx, GetBitContext* gb,
523 return 0; 523 return 0;
524} 524}
525 525
526int ff_wma_fix_run_level_decode(AVCodecContext* avctx, GetBitContext* gb,
527 VLC *vlc,
528 const int32_t *level_table, const uint16_t *run_table,
529 int version, int32_t *ptr, int offset,
530 int num_coefs, int block_len, int frame_len_bits,
531 int coef_nb_bits)
532{
533 int32_t code, level, sign;
534 const unsigned int coef_mask = block_len - 1;
535 for (; offset < num_coefs; offset++) {
536 code = get_vlc2(gb, vlc->table, VLCBITS, VLCMAX);
537 if (code > 1) {
538 /** normal code */
539 offset += run_table[code];
540 sign = !get_bits1(gb);
541 ptr[offset & coef_mask] = sign ? -level_table[code] : level_table[code];
542 ptr[offset & coef_mask] <<= 16;
543 } else if (code == 1) {
544 /** EOB */
545 break;
546 } else {
547 /** escape */
548 if (!version) {
549 level = get_bits(gb, coef_nb_bits);
550 /** NOTE: this is rather suboptimal. reading
551 block_len_bits would be better */
552 offset += get_bits(gb, frame_len_bits);
553 } else {
554 level = ff_wma_get_large_val(gb);
555 /** escape decode */
556 if (get_bits1(gb)) {
557 if (get_bits1(gb)) {
558 if (get_bits1(gb)) {
559 av_log(avctx,AV_LOG_ERROR,
560 "broken escape sequence\n");
561 return -1;
562 } else
563 offset += get_bits(gb, frame_len_bits) + 4;
564 } else
565 offset += get_bits(gb, 2) + 1;
566 }
567 }
568 sign = !get_bits1(gb);
569 ptr[offset & coef_mask] = sign ? -level : level;
570 ptr[offset & coef_mask] <<=16;
571 }
572 }
573 /** NOTE: EOB can be omitted */
574 if (offset > num_coefs) {
575 av_log(avctx, AV_LOG_ERROR, "overflow in spectral RLE, ignoring\n");
576 return -1;
577 }
578
579 return 0;
580}
diff --git a/apps/codecs/libwmapro/wma.h b/apps/codecs/libwmapro/wma.h
index 11274ad970..043b70c509 100644
--- a/apps/codecs/libwmapro/wma.h
+++ b/apps/codecs/libwmapro/wma.h
@@ -159,5 +159,11 @@ int ff_wma_run_level_decode(AVCodecContext* avctx, GetBitContext* gb,
159 int version, WMACoef *ptr, int offset, 159 int version, WMACoef *ptr, int offset,
160 int num_coefs, int block_len, int frame_len_bits, 160 int num_coefs, int block_len, int frame_len_bits,
161 int coef_nb_bits); 161 int coef_nb_bits);
162int ff_wma_fix_run_level_decode(AVCodecContext* avctx, GetBitContext* gb,
163 VLC *vlc,
164 const int32_t *level_table, const uint16_t *run_table,
165 int version, int32_t *ptr, int offset,
166 int num_coefs, int block_len, int frame_len_bits,
167 int coef_nb_bits);
162 168
163#endif /* AVCODEC_WMA_H */ 169#endif /* AVCODEC_WMA_H */
diff --git a/apps/codecs/libwmapro/wmapro_math.h b/apps/codecs/libwmapro/wmapro_math.h
index 83fbb40a66..b339d8616d 100644
--- a/apps/codecs/libwmapro/wmapro_math.h
+++ b/apps/codecs/libwmapro/wmapro_math.h
@@ -1,8 +1,13 @@
1#ifndef _WMAPRO_MATH_H_
2#define _WMAPRO_MATH_H_
3
1#include <inttypes.h> 4#include <inttypes.h>
2#include "types.h" 5#include "types.h"
3 6
4#define fixtof16(x) (float)((float)(x) / (float)(1 << 16)) 7#define fixtof16(x) (float)((float)(x) / (float)(1 << 16))
8#define fixtof31(x) (float)((float)(x) / (float)(1 << 31))
5#define ftofix16(x) ((int32_t)((x) * (float)(1 << 16) + ((x) < 0 ? -0.5:0.5))) 9#define ftofix16(x) ((int32_t)((x) * (float)(1 << 16) + ((x) < 0 ? -0.5:0.5)))
10#define ftofix31(x) ((int32_t)((x) * (float)(1 << 31) + ((x) < 0 ? -0.5:0.5)))
6 11
7static inline FIXED fixmulshift(FIXED x, FIXED y, int shamt) 12static inline FIXED fixmulshift(FIXED x, FIXED y, int shamt)
8{ 13{
@@ -36,11 +41,11 @@ static inline void vector_fixmul_window(FIXED *dst, const FIXED *src0,
36} 41}
37 42
38static inline void vector_fixmul_scalar(FIXED *dst, const FIXED *src, FIXED mul, 43static inline void vector_fixmul_scalar(FIXED *dst, const FIXED *src, FIXED mul,
39 int len) 44 int len, int shift)
40{ 45{
41 int i; 46 int i;
42 for(i=0; i<len; i++) { 47 for(i=0; i<len; i++)
43 dst[i] = fixmulshift(src[i],mul,32); 48 dst[i] = fixmulshift(src[i],mul,shift);
44 }
45
46} 49}
50
51#endif /* _WMAPRO_MATH_H_ */
diff --git a/apps/codecs/libwmapro/wmapro_mdct.c b/apps/codecs/libwmapro/wmapro_mdct.c
index 12cd8ce024..aaa95dccdf 100644
--- a/apps/codecs/libwmapro/wmapro_mdct.c
+++ b/apps/codecs/libwmapro/wmapro_mdct.c
@@ -5,10 +5,10 @@
5#include "../lib/fft.h" /* for FFT data structures */ 5#include "../lib/fft.h" /* for FFT data structures */
6#include "codeclib.h" 6#include "codeclib.h"
7#include "../lib/codeclib_misc.h" /* for XNPROD31 */ 7#include "../lib/codeclib_misc.h" /* for XNPROD31 */
8#include "wmapro_math.h"
8 9
9void imdct_half(unsigned int nbits, int32_t *output, const int32_t *input){ 10void imdct_half(unsigned int nbits, int32_t *output, const int32_t *input){
10 int k, n8, n4, n2, n, j; 11 int k, n8, n4, n2, n, j;
11 //const uint16_t *revtab = s->revtab;
12 const int32_t *in1, *in2; 12 const int32_t *in1, *in2;
13 FFTComplex *z = (FFTComplex *)output; 13 FFTComplex *z = (FFTComplex *)output;
14 14
@@ -23,10 +23,9 @@ void imdct_half(unsigned int nbits, int32_t *output, const int32_t *input){
23 const int revtab_shift = (14- nbits); 23 const int revtab_shift = (14- nbits);
24 in1 = input; 24 in1 = input;
25 in2 = input + n2 - 1; 25 in2 = input + n2 - 1;
26 int step = 2<<(12-nbits);
27 for(k = 0; k < n4; k++) { 26 for(k = 0; k < n4; k++) {
28 j=revtab[k]>>revtab_shift; 27 j=revtab[k]>>revtab_shift;
29 XNPROD31(*in2, *in1, T[1]<<16, T[0]<<16, &z[j].re, &z[j].im ); 28 XNPROD31(*in2<<2, *in1<<2, T[1]<<14, T[0]<<14, &z[j].re, &z[j].im );
30 in1 += 2; 29 in1 += 2;
31 in2 -= 2; 30 in2 -= 2;
32 T += 2; 31 T += 2;
@@ -39,8 +38,8 @@ void imdct_half(unsigned int nbits, int32_t *output, const int32_t *input){
39 const int32_t *V = T; 38 const int32_t *V = T;
40 for(k = 0; k < n8; k++) { 39 for(k = 0; k < n8; k++) {
41 int32_t r0, i0, r1, i1; 40 int32_t r0, i0, r1, i1;
42 XNPROD31(z[n8-k-1].im, z[n8-k-1].re, T[0]<<16, T[1]<<16, &r0, &i1 ); 41 XNPROD31(z[n8-k-1].im, z[n8-k-1].re, T[0]<<8, T[1]<<8, &r0, &i1 );
43 XNPROD31(z[n8+k ].im, z[n8+k ].re, V[0]<<16, V[1]<<16, &r1, &i0 ); 42 XNPROD31(z[n8+k ].im, z[n8+k ].re, V[0]<<8, V[1]<<8, &r1, &i0 );
44 z[n8-k-1].re = r0; 43 z[n8-k-1].re = r0;
45 z[n8-k-1].im = i0; 44 z[n8-k-1].im = i0;
46 z[n8+k ].re = r1; 45 z[n8+k ].re = r1;
diff --git a/apps/codecs/libwmapro/wmaprodata.h b/apps/codecs/libwmapro/wmaprodata.h
index a1d186e0c2..7fb784b39b 100644
--- a/apps/codecs/libwmapro/wmaprodata.h
+++ b/apps/codecs/libwmapro/wmaprodata.h
@@ -31,6 +31,15 @@
31#include <stddef.h> 31#include <stddef.h>
32#include <stdint.h> 32#include <stdint.h>
33 33
34const int32_t fixed_sin64[33] = {
35 0x00000000, 0xF9B82685, 0xF3742CA3, 0xED37EF92, 0xE70747C5, 0xE0E60686,
36 0xDAD7F3A3, 0xD4E0CB16, 0xCF043AB4, 0xC945DFED, 0xC3A94591, 0xBE31E19C,
37 0xB8E3131A, 0xB3C0200D, 0xAECC336D, 0xAA0A5B2F, 0xA57D8667, 0xA1288377,
38 0x9D0DFE55, 0x99307EE1, 0x9592675D, 0x9235F2ED, 0x8F1D343B, 0x8C4A1430,
39 0x89BE50C4, 0x877B7BED, 0x8582FAA6, 0x83D60413, 0x8275A0C1, 0x8162AA05,
40 0x809DC972, 0x80277873, 0x80000001,
41};
42
34/** 43/**
35 * @brief frequencies to divide the frequency spectrum into scale factor bands 44 * @brief frequencies to divide the frequency spectrum into scale factor bands
36 */ 45 */
@@ -375,6 +384,29 @@ static const float coef0_level[HUFF_COEF0_SIZE] = {
375 25, 26, 26, 27, 27, 28, 384 25, 26, 26, 27, 27, 28,
376}; 385};
377 386
387static const int32_t fixcoef0_level[HUFF_COEF0_SIZE] = {
388 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
389 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
390 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
391 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
392 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
393 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
394 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
395 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
396 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
397 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
398 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
399 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
400 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
401 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
402 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
403 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5,
404 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11,
405 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18,
406 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25,
407 25, 26, 26, 27, 27, 28,
408};
409
378 410
379static const uint16_t coef1_run[HUFF_COEF1_SIZE] = { 411static const uint16_t coef1_run[HUFF_COEF1_SIZE] = {
380 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 412 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
@@ -409,6 +441,23 @@ static const float coef1_level[HUFF_COEF1_SIZE] = {
409 37, 38, 38, 39, 39, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 45, 45, 46, 441 37, 38, 38, 39, 39, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 45, 45, 46,
410 46, 47, 47, 48, 48, 49, 49, 50, 51, 52, 442 46, 47, 47, 48, 48, 49, 49, 50, 51, 52,
411}; 443};
444
445static const int32_t fixcoef1_level[HUFF_COEF1_SIZE] = {
446 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
447 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
448 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
449 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
450 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
451 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2,
452 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
453 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4,
454 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9, 10,
455 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19,
456 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28,
457 28, 29, 29, 30, 30, 31, 31, 32, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37,
458 37, 38, 38, 39, 39, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 45, 45, 46,
459 46, 47, 47, 48, 48, 49, 49, 50, 51, 52,
460};
412/** @} */ 461/** @} */
413 462
414 463
diff --git a/apps/codecs/libwmapro/wmaprodec.c b/apps/codecs/libwmapro/wmaprodec.c
index 5c72032fce..4e89b5a47b 100644
--- a/apps/codecs/libwmapro/wmaprodec.c
+++ b/apps/codecs/libwmapro/wmaprodec.c
@@ -168,6 +168,8 @@ typedef struct {
168 int8_t transform_band[MAX_BANDS]; ///< controls if the transform is enabled for a certain band 168 int8_t transform_band[MAX_BANDS]; ///< controls if the transform is enabled for a certain band
169 float decorrelation_matrix[WMAPRO_MAX_CHANNELS*WMAPRO_MAX_CHANNELS]; 169 float decorrelation_matrix[WMAPRO_MAX_CHANNELS*WMAPRO_MAX_CHANNELS];
170 float* channel_data[WMAPRO_MAX_CHANNELS]; ///< transformation coefficients 170 float* channel_data[WMAPRO_MAX_CHANNELS]; ///< transformation coefficients
171 FIXED fixdecorrelation_matrix[WMAPRO_MAX_CHANNELS*WMAPRO_MAX_CHANNELS];
172 FIXED* fixchannel_data[WMAPRO_MAX_CHANNELS]; ///< transformation coefficients
171} WMAProChannelGrp; 173} WMAProChannelGrp;
172 174
173/** 175/**
@@ -629,9 +631,15 @@ static void decode_decorrelation_matrix(WMAProDecodeCtx *s,
629 for (i = 0; i < chgroup->num_channels * (chgroup->num_channels - 1) >> 1; i++) 631 for (i = 0; i < chgroup->num_channels * (chgroup->num_channels - 1) >> 1; i++)
630 rotation_offset[i] = get_bits(&s->gb, 6); 632 rotation_offset[i] = get_bits(&s->gb, 6);
631 633
632 for (i = 0; i < chgroup->num_channels; i++) 634 for (i = 0; i < chgroup->num_channels; i++) {
633 chgroup->decorrelation_matrix[chgroup->num_channels * i + i] = 635 chgroup->decorrelation_matrix[chgroup->num_channels * i + i] =
634 get_bits1(&s->gb) ? 1.0 : -1.0; 636 get_bits1(&s->gb) ? 1.0 : -1.0;
637
638 if(chgroup->decorrelation_matrix[chgroup->num_channels * i + i] > 0)
639 chgroup->fixdecorrelation_matrix[chgroup->num_channels * i + i] = 0x10000;
640 else
641 chgroup->fixdecorrelation_matrix[chgroup->num_channels * i + i] = -0x10000;
642 }
635 643
636 for (i = 1; i < chgroup->num_channels; i++) { 644 for (i = 1; i < chgroup->num_channels; i++) {
637 int x; 645 int x;
@@ -640,22 +648,35 @@ static void decode_decorrelation_matrix(WMAProDecodeCtx *s,
640 for (y = 0; y < i + 1; y++) { 648 for (y = 0; y < i + 1; y++) {
641 float v1 = chgroup->decorrelation_matrix[x * chgroup->num_channels + y]; 649 float v1 = chgroup->decorrelation_matrix[x * chgroup->num_channels + y];
642 float v2 = chgroup->decorrelation_matrix[i * chgroup->num_channels + y]; 650 float v2 = chgroup->decorrelation_matrix[i * chgroup->num_channels + y];
651 FIXED f1 = chgroup->fixdecorrelation_matrix[x * chgroup->num_channels + y];
652 FIXED f2 = chgroup->fixdecorrelation_matrix[i * chgroup->num_channels + y];
643 int n = rotation_offset[offset + x]; 653 int n = rotation_offset[offset + x];
644 float sinv; 654 float sinv;
645 float cosv; 655 float cosv;
656 FIXED fixsinv;
657 FIXED fixcosv;
646 658
647 if (n < 32) { 659 if (n < 32) {
648 sinv = sin64[n]; 660 sinv = sin64[n];
649 cosv = sin64[32 - n]; 661 cosv = sin64[32 - n];
662 fixsinv = fixed_sin64[n];
663 fixcosv = fixed_sin64[32-n];
650 } else { 664 } else {
651 sinv = sin64[64 - n]; 665 sinv = sin64[64 - n];
652 cosv = -sin64[n - 32]; 666 cosv = -sin64[n - 32];
667 fixsinv = fixed_sin64[64-n];
668 fixcosv = -fixed_sin64[n-32];
653 } 669 }
654 670
655 chgroup->decorrelation_matrix[y + x * chgroup->num_channels] = 671 chgroup->decorrelation_matrix[y + x * chgroup->num_channels] =
656 (v1 * sinv) - (v2 * cosv); 672 (v1 * sinv) - (v2 * cosv);
657 chgroup->decorrelation_matrix[y + i * chgroup->num_channels] = 673 chgroup->decorrelation_matrix[y + i * chgroup->num_channels] =
658 (v1 * cosv) + (v2 * sinv); 674 (v1 * cosv) + (v2 * sinv);
675 chgroup->fixdecorrelation_matrix[y + x * chgroup->num_channels] =
676 fixmulshift(f1, fixsinv, 31) - fixmulshift(f2, fixcosv, 31);
677 chgroup->fixdecorrelation_matrix[y + i * chgroup->num_channels] =
678 fixmulshift(f1, fixcosv, 31) + fixmulshift(f2, fixsinv, 31);
679
659 } 680 }
660 } 681 }
661 offset += i; 682 offset += i;
@@ -690,6 +711,7 @@ static int decode_channel_transform(WMAProDecodeCtx* s)
690 s->num_chgroups < s->channels_for_cur_subframe; s->num_chgroups++) { 711 s->num_chgroups < s->channels_for_cur_subframe; s->num_chgroups++) {
691 WMAProChannelGrp* chgroup = &s->chgroup[s->num_chgroups]; 712 WMAProChannelGrp* chgroup = &s->chgroup[s->num_chgroups];
692 float** channel_data = chgroup->channel_data; 713 float** channel_data = chgroup->channel_data;
714 FIXED** fixchdata = chgroup->fixchannel_data;
693 chgroup->num_channels = 0; 715 chgroup->num_channels = 0;
694 chgroup->transform = 0; 716 chgroup->transform = 0;
695 717
@@ -702,14 +724,17 @@ static int decode_channel_transform(WMAProDecodeCtx* s)
702 ++chgroup->num_channels; 724 ++chgroup->num_channels;
703 s->channel[channel_idx].grouped = 1; 725 s->channel[channel_idx].grouped = 1;
704 *channel_data++ = s->channel[channel_idx].coeffs; 726 *channel_data++ = s->channel[channel_idx].coeffs;
727 *fixchdata++ = s->channel[channel_idx].fixcoeffs;
705 } 728 }
706 } 729 }
707 } else { 730 } else {
708 chgroup->num_channels = remaining_channels; 731 chgroup->num_channels = remaining_channels;
709 for (i = 0; i < s->channels_for_cur_subframe; i++) { 732 for (i = 0; i < s->channels_for_cur_subframe; i++) {
710 int channel_idx = s->channel_indexes_for_cur_subframe[i]; 733 int channel_idx = s->channel_indexes_for_cur_subframe[i];
711 if (!s->channel[channel_idx].grouped) 734 if (!s->channel[channel_idx].grouped) {
712 *channel_data++ = s->channel[channel_idx].coeffs; 735 *channel_data++ = s->channel[channel_idx].coeffs;
736 *fixchdata++ = s->channel[channel_idx].fixcoeffs;
737 }
713 s->channel[channel_idx].grouped = 1; 738 s->channel[channel_idx].grouped = 1;
714 } 739 }
715 } 740 }
@@ -728,12 +753,22 @@ static int decode_channel_transform(WMAProDecodeCtx* s)
728 chgroup->decorrelation_matrix[1] = -1.0; 753 chgroup->decorrelation_matrix[1] = -1.0;
729 chgroup->decorrelation_matrix[2] = 1.0; 754 chgroup->decorrelation_matrix[2] = 1.0;
730 chgroup->decorrelation_matrix[3] = 1.0; 755 chgroup->decorrelation_matrix[3] = 1.0;
756
757 chgroup->fixdecorrelation_matrix[0] = 0x10000;
758 chgroup->fixdecorrelation_matrix[1] = -0x10000;
759 chgroup->fixdecorrelation_matrix[2] = 0x10000;
760 chgroup->fixdecorrelation_matrix[3] = 0x10000;
731 } else { 761 } else {
732 /** cos(pi/4) */ 762 /** cos(pi/4) */
733 chgroup->decorrelation_matrix[0] = 0.70703125; 763 chgroup->decorrelation_matrix[0] = 0.70703125;
734 chgroup->decorrelation_matrix[1] = -0.70703125; 764 chgroup->decorrelation_matrix[1] = -0.70703125;
735 chgroup->decorrelation_matrix[2] = 0.70703125; 765 chgroup->decorrelation_matrix[2] = 0.70703125;
736 chgroup->decorrelation_matrix[3] = 0.70703125; 766 chgroup->decorrelation_matrix[3] = 0.70703125;
767
768 chgroup->fixdecorrelation_matrix[0] = 0xB500;
769 chgroup->fixdecorrelation_matrix[1] = -0xB500;
770 chgroup->fixdecorrelation_matrix[2] = 0xB500;
771 chgroup->fixdecorrelation_matrix[3] = 0xB500;
737 } 772 }
738 } 773 }
739 } else if (chgroup->num_channels > 2) { 774 } else if (chgroup->num_channels > 2) {
@@ -781,7 +816,7 @@ static int decode_channel_transform(WMAProDecodeCtx* s)
781 *@return 0 on success, < 0 in case of bitstream errors 816 *@return 0 on success, < 0 in case of bitstream errors
782 */ 817 */
783static int decode_coeffs(WMAProDecodeCtx *s, int c) 818static int decode_coeffs(WMAProDecodeCtx *s, int c)
784{ 819{
785 /* Integers 0..15 as single-precision floats. The table saves a 820 /* Integers 0..15 as single-precision floats. The table saves a
786 costly int to float conversion, and storing the values as 821 costly int to float conversion, and storing the values as
787 integers allows fast sign-flipping. */ 822 integers allows fast sign-flipping. */
@@ -799,6 +834,7 @@ static int decode_coeffs(WMAProDecodeCtx *s, int c)
799 int num_zeros = 0; 834 int num_zeros = 0;
800 const uint16_t* run; 835 const uint16_t* run;
801 const float* level; 836 const float* level;
837 const FIXED* fixlevel;
802 838
803 dprintf(s->avctx, "decode coefficients for channel %i\n", c); 839 dprintf(s->avctx, "decode coefficients for channel %i\n", c);
804 840
@@ -808,15 +844,18 @@ static int decode_coeffs(WMAProDecodeCtx *s, int c)
808 if (vlctable) { 844 if (vlctable) {
809 run = coef1_run; 845 run = coef1_run;
810 level = coef1_level; 846 level = coef1_level;
847 fixlevel = fixcoef1_level;
811 } else { 848 } else {
812 run = coef0_run; 849 run = coef0_run;
813 level = coef0_level; 850 level = coef0_level;
851 fixlevel = fixcoef0_level;
814 } 852 }
815 853
816 /** decode vector coefficients (consumes up to 167 bits per iteration for 854 /** decode vector coefficients (consumes up to 167 bits per iteration for
817 4 vector coded large values) */ 855 4 vector coded large values) */
818 while (!rl_mode && cur_coeff + 3 < s->subframe_len) { 856 while (!rl_mode && cur_coeff + 3 < s->subframe_len) {
819 int vals[4]; 857 int vals[4];
858 int32_t fixvals[4];
820 int i; 859 int i;
821 unsigned int idx; 860 unsigned int idx;
822 861
@@ -835,9 +874,13 @@ static int decode_coeffs(WMAProDecodeCtx *s, int c)
835 v1 += ff_wma_get_large_val(&s->gb); 874 v1 += ff_wma_get_large_val(&s->gb);
836 ((float*)vals)[i ] = v0; 875 ((float*)vals)[i ] = v0;
837 ((float*)vals)[i+1] = v1; 876 ((float*)vals)[i+1] = v1;
877 fixvals[i] = v0;
878 fixvals[i+1] = v1;
838 } else { 879 } else {
839 vals[i] = fval_tab[symbol_to_vec2[idx] >> 4 ]; 880 vals[i] = fval_tab[symbol_to_vec2[idx] >> 4 ];
840 vals[i+1] = fval_tab[symbol_to_vec2[idx] & 0xF]; 881 vals[i+1] = fval_tab[symbol_to_vec2[idx] & 0xF];
882 fixvals[i] = symbol_to_vec2[idx] >> 4;
883 fixvals[i+1] = symbol_to_vec2[idx] & 0xF;
841 } 884 }
842 } 885 }
843 } else { 886 } else {
@@ -845,6 +888,11 @@ static int decode_coeffs(WMAProDecodeCtx *s, int c)
845 vals[1] = fval_tab[(symbol_to_vec4[idx] >> 8) & 0xF]; 888 vals[1] = fval_tab[(symbol_to_vec4[idx] >> 8) & 0xF];
846 vals[2] = fval_tab[(symbol_to_vec4[idx] >> 4) & 0xF]; 889 vals[2] = fval_tab[(symbol_to_vec4[idx] >> 4) & 0xF];
847 vals[3] = fval_tab[ symbol_to_vec4[idx] & 0xF]; 890 vals[3] = fval_tab[ symbol_to_vec4[idx] & 0xF];
891
892 fixvals[0] = symbol_to_vec4[idx] >> 12;
893 fixvals[1] = (symbol_to_vec4[idx] >> 8) & 0xF;
894 fixvals[2] = (symbol_to_vec4[idx] >> 4) & 0xF;
895 fixvals[3] = symbol_to_vec4[idx] & 0xF;
848 } 896 }
849 897
850 /** decode sign */ 898 /** decode sign */
@@ -852,9 +900,14 @@ static int decode_coeffs(WMAProDecodeCtx *s, int c)
852 if (vals[i]) { 900 if (vals[i]) {
853 int sign = get_bits1(&s->gb) - 1; 901 int sign = get_bits1(&s->gb) - 1;
854 *(uint32_t*)&ci->coeffs[cur_coeff] = vals[i] ^ sign<<31; 902 *(uint32_t*)&ci->coeffs[cur_coeff] = vals[i] ^ sign<<31;
903 ci->fixcoeffs[cur_coeff] = (sign == -1)? -fixvals[i]<<16 : fixvals[i]<<16;
904 if(ftofix16(ci->coeffs[cur_coeff]) != ci->fixcoeffs[cur_coeff]) {
905 printf("coeff = %f, fixcoeff = %f\n", ci->coeffs[cur_coeff], fixtof16(ci->fixcoeffs[cur_coeff]));getchar();
906 }
855 num_zeros = 0; 907 num_zeros = 0;
856 } else { 908 } else {
857 ci->coeffs[cur_coeff] = 0; 909 ci->coeffs[cur_coeff] = 0;
910 ci->fixcoeffs[cur_coeff] = 0;
858 /** switch to run level mode when subframe_len / 128 zeros 911 /** switch to run level mode when subframe_len / 128 zeros
859 were found in a row */ 912 were found in a row */
860 rl_mode |= (++num_zeros > s->subframe_len >> 8); 913 rl_mode |= (++num_zeros > s->subframe_len >> 8);
@@ -867,13 +920,23 @@ static int decode_coeffs(WMAProDecodeCtx *s, int c)
867 if (rl_mode) { 920 if (rl_mode) {
868 memset(&ci->coeffs[cur_coeff], 0, 921 memset(&ci->coeffs[cur_coeff], 0,
869 sizeof(*ci->coeffs) * (s->subframe_len - cur_coeff)); 922 sizeof(*ci->coeffs) * (s->subframe_len - cur_coeff));
870 if (ff_wma_run_level_decode(s->avctx, &s->gb, vlc, 923 memset(&ci->fixcoeffs[cur_coeff], 0,
924 sizeof(*ci->fixcoeffs) * (s->subframe_len - cur_coeff));
925
926int indx = s->gb.index;
927 if (ff_wma_run_level_decode(s->avctx, &s->gb, vlc,
871 level, run, 1, ci->coeffs, 928 level, run, 1, ci->coeffs,
872 cur_coeff, s->subframe_len, 929 cur_coeff, s->subframe_len,
873 s->subframe_len, s->esc_len, 0)) 930 s->subframe_len, s->esc_len, 0))
874 return AVERROR_INVALIDDATA; 931 return AVERROR_INVALIDDATA;
875 } 932s->gb.index = indx;
933 if (ff_wma_fix_run_level_decode(s->avctx, &s->gb, vlc,
934 fixlevel, run, 1, ci->fixcoeffs,
935 cur_coeff, s->subframe_len,
936 s->subframe_len, s->esc_len, 0))
937 return AVERROR_INVALIDDATA;
876 938
939 }
877 return 0; 940 return 0;
878} 941}
879 942
@@ -954,6 +1017,7 @@ static int decode_scale_factors(WMAProDecodeCtx* s)
954 s->channel[c].scale_factors[i] += (val ^ sign) - sign; 1017 s->channel[c].scale_factors[i] += (val ^ sign) - sign;
955 } 1018 }
956 } 1019 }
1020
957 /** swap buffers */ 1021 /** swap buffers */
958 s->channel[c].scale_factor_idx = !s->channel[c].scale_factor_idx; 1022 s->channel[c].scale_factor_idx = !s->channel[c].scale_factor_idx;
959 s->channel[c].table_idx = s->table_idx; 1023 s->channel[c].table_idx = s->table_idx;
@@ -985,6 +1049,9 @@ static void inverse_channel_transform(WMAProDecodeCtx *s)
985 const int num_channels = s->chgroup[i].num_channels; 1049 const int num_channels = s->chgroup[i].num_channels;
986 float** ch_data = s->chgroup[i].channel_data; 1050 float** ch_data = s->chgroup[i].channel_data;
987 float** ch_end = ch_data + num_channels; 1051 float** ch_end = ch_data + num_channels;
1052 FIXED fixdata[WMAPRO_MAX_CHANNELS];
1053 FIXED** fixchdata = s->chgroup[i].fixchannel_data;
1054 FIXED** fixchend = fixchdata + num_channels;
988 const int8_t* tb = s->chgroup[i].transform_band; 1055 const int8_t* tb = s->chgroup[i].transform_band;
989 int16_t* sfb; 1056 int16_t* sfb;
990 1057
@@ -999,20 +1066,34 @@ static void inverse_channel_transform(WMAProDecodeCtx *s)
999 const float* data_end = data + num_channels; 1066 const float* data_end = data + num_channels;
1000 float* data_ptr = data; 1067 float* data_ptr = data;
1001 float** ch; 1068 float** ch;
1002 1069 const FIXED* fixmat = s->chgroup[i].fixdecorrelation_matrix;
1003 for (ch = ch_data; ch < ch_end; ch++) 1070 const FIXED* fixdata_end = fixdata + num_channels;
1071 FIXED* fixdata_ptr = fixdata;
1072 FIXED** fixch;
1073
1074 for (ch = ch_data, fixch = fixchdata; ch < ch_end && fixch < fixchend; ch++, fixch++) {
1004 *data_ptr++ = (*ch)[y]; 1075 *data_ptr++ = (*ch)[y];
1076 *fixdata_ptr++ = (*fixch)[y];
1077 }
1005 1078
1006 for (ch = ch_data; ch < ch_end; ch++) { 1079 for (ch = ch_data, fixch = fixchdata; ch < ch_end && fixch < fixchend; ch++, fixch++) {
1007 float sum = 0; 1080 float sum = 0;
1081 FIXED fixsum = 0;
1008 data_ptr = data; 1082 data_ptr = data;
1083 fixdata_ptr = fixdata;
1084
1009 while (data_ptr < data_end) 1085 while (data_ptr < data_end)
1010 sum += *data_ptr++ * *mat++; 1086 sum += *data_ptr++ * *mat++;
1087
1088 while (fixdata_ptr < fixdata_end)
1089 fixsum += fixmulshift(*fixdata_ptr++, *fixmat++, 16);
1011 1090
1012 (*ch)[y] = sum; 1091 (*ch)[y] = sum;
1092 (*fixch)[y] = fixsum;
1013 } 1093 }
1014 } 1094 }
1015 } else if (s->num_channels == 2) { 1095 } else if (s->num_channels == 2) {
1096
1016 int len = FFMIN(sfb[1], s->subframe_len) - sfb[0]; 1097 int len = FFMIN(sfb[1], s->subframe_len) - sfb[0];
1017 s->dsp.vector_fmul_scalar(ch_data[0] + sfb[0], 1098 s->dsp.vector_fmul_scalar(ch_data[0] + sfb[0],
1018 ch_data[0] + sfb[0], 1099 ch_data[0] + sfb[0],
@@ -1020,6 +1101,13 @@ static void inverse_channel_transform(WMAProDecodeCtx *s)
1020 s->dsp.vector_fmul_scalar(ch_data[1] + sfb[0], 1101 s->dsp.vector_fmul_scalar(ch_data[1] + sfb[0],
1021 ch_data[1] + sfb[0], 1102 ch_data[1] + sfb[0],
1022 181.0 / 128, len); 1103 181.0 / 128, len);
1104 vector_fixmul_scalar(fixchdata[0] + sfb[0],
1105 fixchdata[0] + sfb[0],
1106 0x00016A00, len, 16);
1107 vector_fixmul_scalar(fixchdata[1] + sfb[0],
1108 fixchdata[1] + sfb[0],
1109 0x00016A00, len,16);
1110
1023 } 1111 }
1024 } 1112 }
1025 } 1113 }
@@ -1048,7 +1136,7 @@ static void wmapro_window(WMAProDecodeCtx *s)
1048 xstart += (winlen - s->subframe_len) >> 1; 1136 xstart += (winlen - s->subframe_len) >> 1;
1049 winlen = s->subframe_len; 1137 winlen = s->subframe_len;
1050 } 1138 }
1051 1139
1052 window = sine_windows[av_log2(winlen) - BLOCK_MIN_BITS]; 1140 window = sine_windows[av_log2(winlen) - BLOCK_MIN_BITS];
1053 win2 = s->windows[av_log2(winlen) - BLOCK_MIN_BITS]; 1141 win2 = s->windows[av_log2(winlen) - BLOCK_MIN_BITS];
1054 1142
@@ -1060,6 +1148,7 @@ static void wmapro_window(WMAProDecodeCtx *s)
1060 window, 0, winlen); 1148 window, 0, winlen);
1061 1149
1062 s->channel[c].prev_block_len = s->subframe_len; 1150 s->channel[c].prev_block_len = s->subframe_len;
1151
1063 } 1152 }
1064} 1153}
1065 1154
@@ -1165,11 +1254,9 @@ static int decode_subframe(WMAProDecodeCtx *s)
1165 return AVERROR_INVALIDDATA; 1254 return AVERROR_INVALIDDATA;
1166 } 1255 }
1167 1256
1168
1169 if (decode_channel_transform(s) < 0) 1257 if (decode_channel_transform(s) < 0)
1170 return AVERROR_INVALIDDATA; 1258 return AVERROR_INVALIDDATA;
1171 1259
1172
1173 for (i = 0; i < s->channels_for_cur_subframe; i++) { 1260 for (i = 0; i < s->channels_for_cur_subframe; i++) {
1174 int c = s->channel_indexes_for_cur_subframe[i]; 1261 int c = s->channel_indexes_for_cur_subframe[i];
1175 if ((s->channel[c].transmit_coefs = get_bits1(&s->gb))) 1262 if ((s->channel[c].transmit_coefs = get_bits1(&s->gb)))
@@ -1217,7 +1304,7 @@ static int decode_subframe(WMAProDecodeCtx *s)
1217 } 1304 }
1218 } 1305 }
1219 } 1306 }
1220 1307
1221 /** decode scale factors */ 1308 /** decode scale factors */
1222 if (decode_scale_factors(s) < 0) 1309 if (decode_scale_factors(s) < 0)
1223 return AVERROR_INVALIDDATA; 1310 return AVERROR_INVALIDDATA;
@@ -1232,9 +1319,12 @@ static int decode_subframe(WMAProDecodeCtx *s)
1232 if (s->channel[c].transmit_coefs && 1319 if (s->channel[c].transmit_coefs &&
1233 get_bits_count(&s->gb) < s->num_saved_bits) { 1320 get_bits_count(&s->gb) < s->num_saved_bits) {
1234 decode_coeffs(s, c); 1321 decode_coeffs(s, c);
1235 } else 1322 } else {
1236 memset(s->channel[c].coeffs, 0, 1323 memset(s->channel[c].coeffs, 0,
1237 sizeof(*s->channel[c].coeffs) * subframe_len); 1324 sizeof(*s->channel[c].coeffs) * subframe_len);
1325 memset(s->channel[c].fixcoeffs, 0,
1326 sizeof(*s->channel[c].fixcoeffs) * subframe_len);
1327 }
1238 } 1328 }
1239 1329
1240 dprintf(s->avctx, "BITSTREAM: subframe length was %i\n", 1330 dprintf(s->avctx, "BITSTREAM: subframe length was %i\n",
@@ -1268,22 +1358,17 @@ static int decode_subframe(WMAProDecodeCtx *s)
1268 } 1358 }
1269 const FIXED fixquant = QUANT(exp); 1359 const FIXED fixquant = QUANT(exp);
1270 int start = s->cur_sfb_offsets[b]; 1360 int start = s->cur_sfb_offsets[b];
1271 1361
1272 int j;
1273 for(j = 0; j < WMAPRO_BLOCK_MAX_SIZE + WMAPRO_BLOCK_MAX_SIZE/2; j++)
1274 s->channel[c].fixout[j] = ftofix16(s->channel[c].out[j]);
1275
1276 s->dsp.vector_fmul_scalar(s->tmp + start, 1362 s->dsp.vector_fmul_scalar(s->tmp + start,
1277 s->channel[c].coeffs + start, 1363 s->channel[c].coeffs + start,
1278 quant, end - start); 1364 quant, end - start);
1279 vector_fixmul_scalar(s->fixtmp+start, 1365 vector_fixmul_scalar(s->fixtmp+start,
1280 s->channel[c].fixcoeffs + start, 1366 s->channel[c].fixcoeffs + start,
1281 fixquant, end-start); 1367 fixquant, end-start, 24);
1368
1282 1369
1283 } 1370 }
1284 1371
1285 int j;
1286
1287 /** apply imdct (ff_imdct_half == DCTIV with reverse) */ 1372 /** apply imdct (ff_imdct_half == DCTIV with reverse) */
1288 fff_imdct_half(&s->mdct_ctx[av_log2(subframe_len) - BLOCK_MIN_BITS], 1373 fff_imdct_half(&s->mdct_ctx[av_log2(subframe_len) - BLOCK_MIN_BITS],
1289 s->channel[c].coeffs, s->tmp); 1374 s->channel[c].coeffs, s->tmp);
@@ -1296,7 +1381,6 @@ static int decode_subframe(WMAProDecodeCtx *s)
1296 /** window and overlapp-add */ 1381 /** window and overlapp-add */
1297 wmapro_window(s); 1382 wmapro_window(s);
1298 1383
1299
1300 /** handled one subframe */ 1384 /** handled one subframe */
1301 for (i = 0; i < s->channels_for_cur_subframe; i++) { 1385 for (i = 0; i < s->channels_for_cur_subframe; i++) {
1302 int c = s->channel_indexes_for_cur_subframe[i]; 1386 int c = s->channel_indexes_for_cur_subframe[i];
@@ -1415,12 +1499,18 @@ static int decode_frame(WMAProDecodeCtx *s)
1415 memcpy(&s->channel[i].out[0], 1499 memcpy(&s->channel[i].out[0],
1416 &s->channel[i].out[s->samples_per_frame], 1500 &s->channel[i].out[s->samples_per_frame],
1417 s->samples_per_frame * sizeof(*s->channel[i].out) >> 1); 1501 s->samples_per_frame * sizeof(*s->channel[i].out) >> 1);
1502
1503 memcpy(&s->channel[i].fixout[0],
1504 &s->channel[i].fixout[s->samples_per_frame],
1505 s->samples_per_frame * sizeof(*s->channel[i].fixout) >> 1);
1418 } 1506 }
1419 1507
1420 if (s->skip_frame) { 1508 if (s->skip_frame) {
1421 s->skip_frame = 0; 1509 s->skip_frame = 0;
1422 } else 1510 } else {
1423 s->samples += s->num_channels * s->samples_per_frame; 1511 s->samples += s->num_channels * s->samples_per_frame;
1512 s->samplesf += s->num_channels * s->samples_per_frame;
1513 }
1424 1514
1425 if (len != (get_bits_count(gb) - s->frame_offset) + 2) { 1515 if (len != (get_bits_count(gb) - s->frame_offset) + 2) {
1426 /** FIXME: not sure if this is always an error */ 1516 /** FIXME: not sure if this is always an error */
@@ -1522,7 +1612,7 @@ int decode_packet(AVCodecContext *avctx,
1522 int packet_sequence_number; 1612 int packet_sequence_number;
1523 1613
1524 s->samples = data; 1614 s->samples = data;
1525 s->samples_end = (float*)((int8_t*)data + *data_size); 1615 s->samples_end = (FIXED*)((int8_t*)data + *data_size);
1526 *data_size = 0; 1616 *data_size = 0;
1527 1617
1528 if (s->packet_done || s->packet_loss) { 1618 if (s->packet_done || s->packet_loss) {
@@ -1608,9 +1698,12 @@ static void flush(AVCodecContext *avctx)
1608 int i; 1698 int i;
1609 /** reset output buffer as a part of it is used during the windowing of a 1699 /** reset output buffer as a part of it is used during the windowing of a
1610 new frame */ 1700 new frame */
1611 for (i = 0; i < s->num_channels; i++) 1701 for (i = 0; i < s->num_channels; i++) {
1612 memset(s->channel[i].out, 0, s->samples_per_frame * 1702 memset(s->channel[i].out, 0, s->samples_per_frame *
1613 sizeof(*s->channel[i].out)); 1703 sizeof(*s->channel[i].out));
1704 memset(s->channel[i].out, 0, s->samples_per_frame *
1705 sizeof(*s->channel[i].fixout));
1706 }
1614 s->packet_loss = 1; 1707 s->packet_loss = 1;
1615} 1708}
1616 1709