summaryrefslogtreecommitdiff
path: root/apps/codecs/libwmapro/wmaprodec.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libwmapro/wmaprodec.c')
-rw-r--r--apps/codecs/libwmapro/wmaprodec.c145
1 files changed, 119 insertions, 26 deletions
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