summaryrefslogtreecommitdiff
path: root/apps/codecs/libwma/wmadeci.c
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2007-08-02 07:41:28 +0000
committerDave Chapman <dave@dchapman.com>2007-08-02 07:41:28 +0000
commit2ff816fab6df92904baf665c1493e8d1ffdece0f (patch)
tree99bcab150c6cfb41b777cb70ba1aa460529e65ac /apps/codecs/libwma/wmadeci.c
parent206e883e78fe6bb5d65b150b757d7a9af76f472e (diff)
downloadrockbox-2ff816fab6df92904baf665c1493e8d1ffdece0f.tar.gz
rockbox-2ff816fab6df92904baf665c1493e8d1ffdece0f.zip
Cosmetic changes - TAB and whitespace policing.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14135 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libwma/wmadeci.c')
-rw-r--r--apps/codecs/libwma/wmadeci.c125
1 files changed, 59 insertions, 66 deletions
diff --git a/apps/codecs/libwma/wmadeci.c b/apps/codecs/libwma/wmadeci.c
index 552f85183c..f14fbc8197 100644
--- a/apps/codecs/libwma/wmadeci.c
+++ b/apps/codecs/libwma/wmadeci.c
@@ -732,7 +732,7 @@ int wma_decode_init(WMADecodeContext* s, asf_waveformatex_t *wfx)
732 s->coefs_end[k] = (s->frame_len - ((s->frame_len * 9) / 100)) >> k; 732 s->coefs_end[k] = (s->frame_len - ((s->frame_len * 9) / 100)) >> k;
733 /* high freq computation */ 733 /* high freq computation */
734 734
735 fixed32 tmp1 = high_freq*2; /* high_freq is a fixed32!*/ 735 fixed32 tmp1 = high_freq*2; /* high_freq is a fixed32!*/
736 fixed32 tmp2=itofix32(s->sample_rate>>1); 736 fixed32 tmp2=itofix32(s->sample_rate>>1);
737 s->high_band_start[k] = fixtoi32( fixdiv32(tmp1, tmp2) * (block_len>>1) +0x8000); 737 s->high_band_start[k] = fixtoi32( fixdiv32(tmp1, tmp2) * (block_len>>1) +0x8000);
738 738
@@ -775,44 +775,44 @@ int wma_decode_init(WMADecodeContext* s, asf_waveformatex_t *wfx)
775 ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 1); 775 ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 1);
776 } 776 }
777 777
778 { 778 {
779 int i, n; 779 int i, n;
780 fixed32 c1, s1, s2; 780 fixed32 c1, s1, s2;
781 781
782 n=1<<10; 782 n=1<<10;
783 s2 = 1 ? 1 : -1; 783 s2 = 1 ? 1 : -1;
784 for(i=0;i<(n/2);++i) 784 for(i=0;i<(n/2);++i)
785 { 785 {
786 fixed32 ifix = itofix32(i); 786 fixed32 ifix = itofix32(i);
787 fixed32 nfix = itofix32(n); 787 fixed32 nfix = itofix32(n);
788 fixed32 res = fixdiv32(ifix,nfix); 788 fixed32 res = fixdiv32(ifix,nfix);
789 789
790 s1 = fsincos(res<<16, &c1); 790 s1 = fsincos(res<<16, &c1);
791 791
792 exptab0[i].re = c1; 792 exptab0[i].re = c1;
793 exptab0[i].im = s1*s2; 793 exptab0[i].im = s1*s2;
794 } 794 }
795 } 795 }
796 796
797 /* init the MDCT bit reverse table here rather then in fft_init */ 797 /* init the MDCT bit reverse table here rather then in fft_init */
798 798
799 for(i=0;i<1024;i++) /*hard coded to a 2048 bit rotation*/ 799 for(i=0;i<1024;i++) /*hard coded to a 2048 bit rotation*/
800 { /*smaller sizes can reuse the largest*/ 800 { /*smaller sizes can reuse the largest*/
801 m=0; 801 m=0;
802 for(j=0;j<10;j++) 802 for(j=0;j<10;j++)
803 { 803 {
804 m |= ((i >> j) & 1) << (10-j-1); 804 m |= ((i >> j) & 1) << (10-j-1);
805 } 805 }
806 806
807 revtab0[i]=m; 807 revtab0[i]=m;
808 } 808 }
809 809
810 /*ffmpeg uses malloc to only allocate as many window sizes as needed. However, we're really only interested in the worst case memory usage. 810 /*ffmpeg uses malloc to only allocate as many window sizes as needed. However, we're really only interested in the worst case memory usage.
811 * In the worst case you can have 5 window sizes, 128 doubling up 2048 811 * In the worst case you can have 5 window sizes, 128 doubling up 2048
812 * Smaller windows are handled differently. 812 * Smaller windows are handled differently.
813 * Since we don't have malloc, just statically allocate this 813 * Since we don't have malloc, just statically allocate this
814 */ 814 */
815 fixed32 *temp[5]; 815 fixed32 *temp[5];
816 temp[0] = stat0; 816 temp[0] = stat0;
817 temp[1] = stat1; 817 temp[1] = stat1;
818 temp[2] = stat2; 818 temp[2] = stat2;
@@ -836,7 +836,7 @@ int wma_decode_init(WMADecodeContext* s, asf_waveformatex_t *wfx)
836 for(j=0;j<n;++j) 836 for(j=0;j<n;++j)
837 { 837 {
838 fixed32 j2 = itofix32(j) + 0x8000; 838 fixed32 j2 = itofix32(j) + 0x8000;
839 window[j] = fsincos(fixmul32(j2,alpha)<<16, 0); //alpha between 0 and pi/2 839 window[j] = fsincos(fixmul32(j2,alpha)<<16, 0); //alpha between 0 and pi/2
840 840
841 } 841 }
842 //printf("created window\n"); 842 //printf("created window\n");
@@ -857,9 +857,9 @@ int wma_decode_init(WMADecodeContext* s, asf_waveformatex_t *wfx)
857 else 857 else
858 { 858 {
859 s->noise_mult = 0xa3d; 859 s->noise_mult = 0xa3d;
860 /*LSP values are simply 2x the EXP values*/ 860 /* LSP values are simply 2x the EXP values */
861 for (i=0;i<NOISE_TAB_SIZE;++i) 861 for (i=0;i<NOISE_TAB_SIZE;++i)
862 noisetable_exp[i] = noisetable_exp[i]<< 1; 862 noisetable_exp[i] = noisetable_exp[i]<< 1;
863 s->noise_table = noisetable_exp; 863 s->noise_table = noisetable_exp;
864 } 864 }
865#if 0 865#if 0
@@ -876,11 +876,11 @@ int wma_decode_init(WMADecodeContext* s, asf_waveformatex_t *wfx)
876 } 876 }
877#endif 877#endif
878 878
879 s->hgain_vlc.table = vlcbuf4; 879 s->hgain_vlc.table = vlcbuf4;
880 s->hgain_vlc.table_allocated = 540; 880 s->hgain_vlc.table_allocated = 540;
881 init_vlc(&s->hgain_vlc, 9, sizeof(hgain_huffbits), 881 init_vlc(&s->hgain_vlc, 9, sizeof(hgain_huffbits),
882 hgain_huffbits, 1, 1, 882 hgain_huffbits, 1, 1,
883 hgain_huffcodes, 2, 2, 0); 883 hgain_huffcodes, 2, 2, 0);
884 } 884 }
885 885
886 if (s->use_exp_vlc) 886 if (s->use_exp_vlc)
@@ -890,8 +890,8 @@ int wma_decode_init(WMADecodeContext* s, asf_waveformatex_t *wfx)
890 s->exp_vlc.table_allocated = 1536; 890 s->exp_vlc.table_allocated = 1536;
891 891
892 init_vlc(&s->exp_vlc, 9, sizeof(scale_huffbits), 892 init_vlc(&s->exp_vlc, 9, sizeof(scale_huffbits),
893 scale_huffbits, 1, 1, 893 scale_huffbits, 1, 1,
894 scale_huffcodes, 4, 4, 0); 894 scale_huffcodes, 4, 4, 0);
895 } 895 }
896 else 896 else
897 { 897 {
@@ -950,9 +950,9 @@ static inline fixed32 pow_m1_4(WMADecodeContext *s, fixed32 x)
950 a = s->lsp_pow_m_table1[m]; 950 a = s->lsp_pow_m_table1[m];
951 b = s->lsp_pow_m_table2[m]; 951 b = s->lsp_pow_m_table2[m];
952 952
953 /*lsp_pow_e_table contains 32.32 format */ 953 /* lsp_pow_e_table contains 32.32 format */
954 /*TODO: Since we're unlikely have value that cover the whole 954 /* TODO: Since we're unlikely have value that cover the whole
955 * IEEE754 range, we probably don't need to have all possible exponents*/ 955 * IEEE754 range, we probably don't need to have all possible exponents */
956 956
957 return (lsp_pow_e_table[e] * (a + fixmul32(b, ftofix32(t.f))) >>32); 957 return (lsp_pow_e_table[e] * (a + fixmul32(b, ftofix32(t.f))) >>32);
958} 958}
@@ -966,9 +966,9 @@ static void wma_lsp_to_curve_init(WMADecodeContext *s, int frame_len)
966 temp = fixdiv32(itofix32(1), itofix32(frame_len)); 966 temp = fixdiv32(itofix32(1), itofix32(frame_len));
967 for (i=0; i<frame_len; ++i) 967 for (i=0; i<frame_len; ++i)
968 { 968 {
969 /*TODO: can probably reuse the trig_init values here */ 969 /* TODO: can probably reuse the trig_init values here */
970 fsincos((temp*i)<<15, &temp2); 970 fsincos((temp*i)<<15, &temp2);
971 /*get 3 bits headroom + 1 bit from not doubleing the values*/ 971 /* get 3 bits headroom + 1 bit from not doubleing the values */
972 s->lsp_cos_table[i] = temp2>>3; 972 s->lsp_cos_table[i] = temp2>>3;
973 973
974 } 974 }
@@ -1003,9 +1003,9 @@ static void wma_lsp_to_curve(WMADecodeContext *s,
1003 val_max = 0; 1003 val_max = 0;
1004 for(i=0;i<n;++i) 1004 for(i=0;i<n;++i)
1005 { 1005 {
1006 /* shift by 2 now to reduce rounding error, 1006 /* shift by 2 now to reduce rounding error,
1007 * we can renormalize right before pow_m1_4 1007 * we can renormalize right before pow_m1_4
1008 */ 1008 */
1009 1009
1010 p = 0x8000<<5; 1010 p = 0x8000<<5;
1011 q = 0x8000<<5; 1011 q = 0x8000<<5;
@@ -1013,16 +1013,16 @@ static void wma_lsp_to_curve(WMADecodeContext *s,
1013 1013
1014 for (j=1;j<NB_LSP_COEFS;j+=2) 1014 for (j=1;j<NB_LSP_COEFS;j+=2)
1015 { 1015 {
1016 1016 /* w is 5.27 format, lsp is in 16.16, temp2 becomes 5.27 format */
1017 /*w is 5.27 format, lsp is in 16.16, temp2 becomes 5.27 format*/ 1017 temp2 = ((w - (lsp[j - 1]<<11)));
1018 temp2 = ((w - (lsp[j - 1]<<11)));
1019 temp = q; 1018 temp = q;
1020 /*q is 16.16 format, temp2 is 5.27, q becomes 16.16 */ 1019
1020 /* q is 16.16 format, temp2 is 5.27, q becomes 16.16 */
1021 q = fixmul32b(q, temp2 )<<4; 1021 q = fixmul32b(q, temp2 )<<4;
1022 p = fixmul32b(p, (w - (lsp[j]<<11)))<<4; 1022 p = fixmul32b(p, (w - (lsp[j]<<11)))<<4;
1023 } 1023 }
1024 1024
1025 /* 2 in 5.27 format is 0x10000000 */ 1025 /* 2 in 5.27 format is 0x10000000 */
1026 p = fixmul32(p, fixmul32b(p, (0x10000000 - w)))<<3; 1026 p = fixmul32(p, fixmul32b(p, (0x10000000 - w)))<<3;
1027 q = fixmul32(q, fixmul32b(q, (0x10000000 + w)))<<3; 1027 q = fixmul32(q, fixmul32b(q, (0x10000000 + w)))<<3;
1028 1028
@@ -1031,7 +1031,6 @@ static void wma_lsp_to_curve(WMADecodeContext *s,
1031 if (v > val_max) 1031 if (v > val_max)
1032 val_max = v; 1032 val_max = v;
1033 out[i] = v; 1033 out[i] = v;
1034
1035 } 1034 }
1036 1035
1037 *val_max_ptr = val_max; 1036 *val_max_ptr = val_max;
@@ -1157,9 +1156,6 @@ static int wma_decode_block(WMADecodeContext *s)
1157 } 1156 }
1158 v = get_bits(&s->gb, n); 1157 v = get_bits(&s->gb, n);
1159 1158
1160
1161
1162
1163 if (v >= s->nb_block_sizes) 1159 if (v >= s->nb_block_sizes)
1164 { 1160 {
1165 // rb->splash(HZ*4, "v was %d", v); //5, 7 1161 // rb->splash(HZ*4, "v was %d", v); //5, 7
@@ -1228,6 +1224,7 @@ static int wma_decode_block(WMADecodeContext *s)
1228 coef_nb_bits = 10; 1224 coef_nb_bits = 10;
1229 else 1225 else
1230 coef_nb_bits = 9; 1226 coef_nb_bits = 9;
1227
1231 /* compute number of coefficients */ 1228 /* compute number of coefficients */
1232 n = s->coefs_end[bsize] - s->coefs_start; 1229 n = s->coefs_end[bsize] - s->coefs_start;
1233 1230
@@ -1288,9 +1285,9 @@ static int wma_decode_block(WMADecodeContext *s)
1288 } 1285 }
1289 } 1286 }
1290 1287
1291 /* exponents can be reused in short blocks. */ 1288 /* exponents can be reused in short blocks. */
1292 if ((s->block_len_bits == s->frame_len_bits) || get_bits(&s->gb, 1)) { 1289 if ((s->block_len_bits == s->frame_len_bits) || get_bits(&s->gb, 1))
1293 1290 {
1294 for(ch = 0; ch < s->nb_channels; ++ch) 1291 for(ch = 0; ch < s->nb_channels; ++ch)
1295 { 1292 {
1296 if (s->channel_coded[ch]) 1293 if (s->channel_coded[ch])
@@ -1332,8 +1329,6 @@ static int wma_decode_block(WMADecodeContext *s)
1332 eptr = ptr + nb_coefs[ch]; 1329 eptr = ptr + nb_coefs[ch];
1333 memset(ptr, 0, s->block_len * sizeof(int16_t)); 1330 memset(ptr, 0, s->block_len * sizeof(int16_t));
1334 1331
1335
1336
1337 for(;;) 1332 for(;;)
1338 { 1333 {
1339 code = get_vlc2(&s->gb, coef_vlc->table, VLCBITS, VLCMAX); 1334 code = get_vlc2(&s->gb, coef_vlc->table, VLCBITS, VLCMAX);
@@ -1421,7 +1416,7 @@ static int wma_decode_block(WMADecodeContext *s)
1421 mult = fixmul64byfixed(mult, mdct_norm); //what the hell? This is actually fixed64*2^16! 1416 mult = fixmul64byfixed(mult, mdct_norm); //what the hell? This is actually fixed64*2^16!
1422 coefs = (*(s->coefs))[ch]; 1417 coefs = (*(s->coefs))[ch];
1423 1418
1424 n=0; 1419 n=0;
1425 1420
1426 if (s->use_noise_coding) 1421 if (s->use_noise_coding)
1427 { 1422 {
@@ -1451,7 +1446,7 @@ static int wma_decode_block(WMADecodeContext *s)
1451 e2 = 0; 1446 e2 = 0;
1452 for(i = 0;i < n; ++i) 1447 for(i = 0;i < n; ++i)
1453 { 1448 {
1454 /*v is noramlized later on so its fixed format is irrelevant*/ 1449 /*v is noramlized later on so its fixed format is irrelevant*/
1455 v = exp_ptr[i]>>4; 1450 v = exp_ptr[i]>>4;
1456 e2 += fixmul32(v, v)>>3; 1451 e2 += fixmul32(v, v)>>3;
1457 } 1452 }
@@ -1484,7 +1479,7 @@ static int wma_decode_block(WMADecodeContext *s)
1484 mult1 = mult1 * pow_table[s->high_band_values[ch][j]+20] >> PRECISION; 1479 mult1 = mult1 * pow_table[s->high_band_values[ch][j]+20] >> PRECISION;
1485 1480
1486 /*this step has a fairly high degree of error for some reason*/ 1481 /*this step has a fairly high degree of error for some reason*/
1487 mult1 = fixdiv64(mult1,fixmul32(s->max_exponent[ch],s->noise_mult)); 1482 mult1 = fixdiv64(mult1,fixmul32(s->max_exponent[ch],s->noise_mult));
1488 1483
1489 mult1 = mult1*mdct_norm>>PRECISION; 1484 mult1 = mult1*mdct_norm>>PRECISION;
1490 for(i = 0;i < n; ++i) 1485 for(i = 0;i < n; ++i)
@@ -1505,8 +1500,8 @@ static int wma_decode_block(WMADecodeContext *s)
1505 s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1); 1500 s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
1506 1501
1507 /*don't forget to renormalize the noise*/ 1502 /*don't forget to renormalize the noise*/
1508 temp1 = (((int32_t)*coefs1++)<<16) + (noise>>4); 1503 temp1 = (((int32_t)*coefs1++)<<16) + (noise>>4);
1509 temp2 = fixmul32(*exponents, mult>>17); 1504 temp2 = fixmul32(*exponents, mult>>17);
1510 *coefs++ = fixmul32(temp1, temp2); 1505 *coefs++ = fixmul32(temp1, temp2);
1511 ++exponents; 1506 ++exponents;
1512 } 1507 }
@@ -1662,9 +1657,7 @@ static int wma_decode_frame(WMADecodeContext *s, int16_t *samples)
1662 1657
1663 for (i=0;i<n;++i) 1658 for (i=0;i<n;++i)
1664 { 1659 {
1665 1660 a = fixtoi32(*iptr++)<<1; //ugly but good enough for now
1666 a = fixtoi32(*iptr++)<<1; //ugly but good enough for now
1667
1668 1661
1669 if (a > 32767) 1662 if (a > 32767)
1670 { 1663 {