diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/codecs/libwma/wmadeci.c | 141 |
1 files changed, 24 insertions, 117 deletions
diff --git a/apps/codecs/libwma/wmadeci.c b/apps/codecs/libwma/wmadeci.c index 17a96b5e65..7eab26863c 100644 --- a/apps/codecs/libwma/wmadeci.c +++ b/apps/codecs/libwma/wmadeci.c | |||
@@ -117,14 +117,14 @@ FFTComplex *exparray[5]; //these are the fft | |||
117 | 117 | ||
118 | uint16_t *revarray[5]; | 118 | uint16_t *revarray[5]; |
119 | 119 | ||
120 | FFTComplex exptab0[512] IBSS_ATTR;//, exptab1[256], exptab2[128], exptab3[64], exptab4[32]; //folded these in! | 120 | FFTComplex exptab0[512] IBSS_ATTR; |
121 | uint16_t revtab0[1024];//, revtab1[512], revtab2[256], revtab3[128], revtab4[64]; | 121 | uint16_t revtab0[1024]; |
122 | 122 | ||
123 | uint16_t *runtabarray[2], *levtabarray[2]; //these are VLC lookup tables | 123 | uint16_t *runtabarray[2], *levtabarray[2]; //these are VLC lookup tables |
124 | 124 | ||
125 | uint16_t runtab0[1336], runtab1[1336], levtab0[1336], levtab1[1336]; //these could be made smaller since only one can be 1336 | 125 | uint16_t runtab0[1336], runtab1[1336], levtab0[1336], levtab1[1336]; //these could be made smaller since only one can be 1336 |
126 | 126 | ||
127 | FFTComplex mdct_tmp[BLOCK_MAX_SIZE] IBSS_ATTR; /* temporary storage for imdct */ | 127 | FFTComplex mdct_tmp[BLOCK_MAX_SIZE] IBSS_ATTR; /* temporary storage for imdct */ |
128 | 128 | ||
129 | //may also be too large by ~ 1KB each? | 129 | //may also be too large by ~ 1KB each? |
130 | static VLC_TYPE vlcbuf1[6144][2]; | 130 | static VLC_TYPE vlcbuf1[6144][2]; |
@@ -148,17 +148,7 @@ int fft_inits(FFTContext *s, int nbits, int inverse) | |||
148 | 148 | ||
149 | s->nbits = nbits; | 149 | s->nbits = nbits; |
150 | n = 1 << nbits; | 150 | n = 1 << nbits; |
151 | //s->exptab = exparray[10-nbits]; //not needed | ||
152 | 151 | ||
153 | //s->exptab = av_malloc((n >> 1) * sizeof(FFTComplex)); | ||
154 | //if (!s->exptab) | ||
155 | // goto fail; | ||
156 | |||
157 | //s->revtab = revarray[10-nbits]; | ||
158 | |||
159 | //s->revtab = av_malloc(n * sizeof(uint16_t)); | ||
160 | //if (!s->revtab) | ||
161 | // goto fail; | ||
162 | s->inverse = inverse; | 152 | s->inverse = inverse; |
163 | 153 | ||
164 | s2 = inverse ? 1 : -1; | 154 | s2 = inverse ? 1 : -1; |
@@ -196,26 +186,7 @@ int fft_inits(FFTContext *s, int nbits, int inverse) | |||
196 | // s->fft_calc = fft_calc; | 186 | // s->fft_calc = fft_calc; |
197 | s->exptab1 = NULL; | 187 | s->exptab1 = NULL; |
198 | 188 | ||
199 | |||
200 | /* compute bit reverse table */ | ||
201 | /* | ||
202 | for(i=0;i<n;i++) | ||
203 | { | ||
204 | m=0; | ||
205 | for(j=0;j<nbits;j++) | ||
206 | { | ||
207 | m |= ((i >> j) & 1) << (nbits-j-1); | ||
208 | |||
209 | } | ||
210 | |||
211 | s->revtab[i]=m; | ||
212 | } */ | ||
213 | return 0; | 189 | return 0; |
214 | //fail: | ||
215 | // av_freep(&s->revtab); | ||
216 | // av_freep(&s->exptab); | ||
217 | // av_freep(&s->exptab1); | ||
218 | return -1; | ||
219 | } | 190 | } |
220 | 191 | ||
221 | /* butter fly op */ | 192 | /* butter fly op */ |
@@ -324,15 +295,7 @@ int fft_calc_unscaled(FFTContext *s, FFTComplex *z) | |||
324 | return 0; | 295 | return 0; |
325 | } | 296 | } |
326 | 297 | ||
327 | /* | 298 | |
328 | //needless since we're statically allocated | ||
329 | void fft_end(FFTContext *s) | ||
330 | { | ||
331 | // av_freep(&s->revtab); | ||
332 | // av_freep(&s->exptab); | ||
333 | // av_freep(&s->exptab1); | ||
334 | } | ||
335 | */ | ||
336 | /* VLC decoding */ | 299 | /* VLC decoding */ |
337 | 300 | ||
338 | #define GET_VLC(code, name, gb, table, bits, max_depth)\ | 301 | #define GET_VLC(code, name, gb, table, bits, max_depth)\ |
@@ -407,10 +370,7 @@ static int alloc_table(VLC *vlc, int size) | |||
407 | vlc->table_size += size; | 370 | vlc->table_size += size; |
408 | if (vlc->table_size > vlc->table_allocated) | 371 | if (vlc->table_size > vlc->table_allocated) |
409 | { | 372 | { |
410 | // rb->splash(HZ*10, "OH CRAP, TRIED TO REALLOC A STATIC VLC TABLE!"); | ||
411 | vlc->table_allocated += (1 << vlc->bits); | 373 | vlc->table_allocated += (1 << vlc->bits); |
412 | // vlc->table = av_realloc(vlc->table, | ||
413 | // sizeof(VLC_TYPE) * 2 * vlc->table_allocated); | ||
414 | if (!vlc->table) | 374 | if (!vlc->table) |
415 | return -1; | 375 | return -1; |
416 | } | 376 | } |
@@ -533,8 +493,6 @@ int init_vlc(VLC *vlc, int nb_bits, int nb_codes, | |||
533 | const void *codes, int codes_wrap, int codes_size) | 493 | const void *codes, int codes_wrap, int codes_size) |
534 | { | 494 | { |
535 | vlc->bits = nb_bits; | 495 | vlc->bits = nb_bits; |
536 | // vlc->table = NULL; | ||
537 | // vlc->table_allocated = 0; | ||
538 | vlc->table_size = 0; | 496 | vlc->table_size = 0; |
539 | 497 | ||
540 | if (build_table(vlc, nb_bits, nb_codes, | 498 | if (build_table(vlc, nb_bits, nb_codes, |
@@ -542,11 +500,9 @@ int init_vlc(VLC *vlc, int nb_bits, int nb_codes, | |||
542 | codes, codes_wrap, codes_size, | 500 | codes, codes_wrap, codes_size, |
543 | 0, 0) < 0) | 501 | 0, 0) < 0) |
544 | { | 502 | { |
545 | // av_free(vlc->table); | 503 | |
546 | return -1; | 504 | return -1; |
547 | } | 505 | } |
548 | //dump_table("Tab 1",vlc->table[0],vlc->table_size); | ||
549 | //dump_table("Tab 2",vlc->table[1],vlc->table_size); | ||
550 | return 0; | 506 | return 0; |
551 | } | 507 | } |
552 | 508 | ||
@@ -566,13 +522,6 @@ int ff_mdct_init(MDCTContext *s, int nbits, int inverse) | |||
566 | n4 = n >> 2; | 522 | n4 = n >> 2; |
567 | s->tcos = tcosarray[12-nbits]; | 523 | s->tcos = tcosarray[12-nbits]; |
568 | s->tsin = tsinarray[12-nbits]; | 524 | s->tsin = tsinarray[12-nbits]; |
569 | //s->tcos = av_malloc(n4 * sizeof(fixed32)); //this allocates between 1024 and 64 elements | ||
570 | //if (!s->tcos) | ||
571 | // goto fail; | ||
572 | //s->tsin = av_malloc(n4 * sizeof(fixed32)); | ||
573 | //if (!s->tsin) | ||
574 | // goto fail; | ||
575 | // | ||
576 | for(i=0;i<n4;i++) | 525 | for(i=0;i<n4;i++) |
577 | { | 526 | { |
578 | //fixed32 pi2 = fixmul32(0x20000, M_PI_F); | 527 | //fixed32 pi2 = fixmul32(0x20000, M_PI_F); |
@@ -672,14 +621,6 @@ void ff_imdct_calc(MDCTContext *s, | |||
672 | 621 | ||
673 | } | 622 | } |
674 | 623 | ||
675 | void ff_mdct_end(MDCTContext *s) | ||
676 | { | ||
677 | (void)s; | ||
678 | |||
679 | // av_freep(&s->tcos); | ||
680 | // av_freep(&s->tsin); | ||
681 | // fft_end(&s->fft); | ||
682 | } | ||
683 | 624 | ||
684 | /* | 625 | /* |
685 | * Helper functions for wma_window. | 626 | * Helper functions for wma_window. |
@@ -1073,11 +1014,11 @@ int wma_decode_init(WMADecodeContext* s, asf_waveformatex_t *wfx) | |||
1073 | tcosarray[0] = tcos0; tcosarray[1] = tcos1; tcosarray[2] = tcos2; tcosarray[3] = tcos3;tcosarray[4] = tcos4; | 1014 | tcosarray[0] = tcos0; tcosarray[1] = tcos1; tcosarray[2] = tcos2; tcosarray[3] = tcos3;tcosarray[4] = tcos4; |
1074 | tsinarray[0] = tsin0; tsinarray[1] = tsin1; tsinarray[2] = tsin2; tsinarray[3] = tsin3;tsinarray[4] = tsin4; | 1015 | tsinarray[0] = tsin0; tsinarray[1] = tsin1; tsinarray[2] = tsin2; tsinarray[3] = tsin3;tsinarray[4] = tsin4; |
1075 | 1016 | ||
1076 | /*these are folded up now*/ | 1017 | /*these are folded up now*/ |
1077 | exparray[0] = exptab0; //exparray[1] = exptab1; exparray[2] = exptab2; exparray[3] = exptab3; exparray[4] = exptab4; | 1018 | exparray[0] = exptab0; //exparray[1] = exptab1; exparray[2] = exptab2; exparray[3] = exptab3; exparray[4] = exptab4; |
1078 | revarray[0]=revtab0; //revarray[1]=revtab1; revarray[2]=revtab2; revarray[3]=revtab3; revarray[4]=revtab4; | 1019 | revarray[0]=revtab0; //revarray[1]=revtab1; revarray[2]=revtab2; revarray[3]=revtab3; revarray[4]=revtab4; |
1079 | 1020 | ||
1080 | s->mdct_tmp = mdct_tmp; /* temporary storage for imdct */ | 1021 | s->mdct_tmp = mdct_tmp; /* temporary storage for imdct */ |
1081 | for(i = 0; i < s->nb_block_sizes; ++i) | 1022 | for(i = 0; i < s->nb_block_sizes; ++i) |
1082 | { | 1023 | { |
1083 | ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 1); | 1024 | ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 1); |
@@ -1085,15 +1026,15 @@ int wma_decode_init(WMADecodeContext* s, asf_waveformatex_t *wfx) | |||
1085 | 1026 | ||
1086 | /* init the MDCT bit reverse table here rather then in fft_init */ | 1027 | /* init the MDCT bit reverse table here rather then in fft_init */ |
1087 | 1028 | ||
1088 | for(i=0;i<1024;i++) /*hard coded to a 2048 bit rotation*/ | 1029 | for(i=0;i<1024;i++) /*hard coded to a 2048 bit rotation*/ |
1089 | { /*smaller sizes can reuse the largest*/ | 1030 | { /*smaller sizes can reuse the largest*/ |
1090 | m=0; | 1031 | m=0; |
1091 | for(j=0;j<10;j++) | 1032 | for(j=0;j<10;j++) |
1092 | { | 1033 | { |
1093 | m |= ((i >> j) & 1) << (10-j-1); | 1034 | m |= ((i >> j) & 1) << (10-j-1); |
1094 | } | 1035 | } |
1095 | 1036 | ||
1096 | revtab0[i]=m; | 1037 | revtab0[i]=m; |
1097 | } | 1038 | } |
1098 | 1039 | ||
1099 | /*ffmpeg uses malloc to only allocate as many window sizes as needed. However, we're really only interested in the worst case memory usage. | 1040 | /*ffmpeg uses malloc to only allocate as many window sizes as needed. However, we're really only interested in the worst case memory usage. |
@@ -1121,7 +1062,7 @@ int wma_decode_init(WMADecodeContext* s, asf_waveformatex_t *wfx) | |||
1121 | //alpha = fixdiv32(M_PI_F, n2); //PI / (2x Window length) == PI<<(s->frame_len_bits - i+1) | 1062 | //alpha = fixdiv32(M_PI_F, n2); //PI / (2x Window length) == PI<<(s->frame_len_bits - i+1) |
1122 | 1063 | ||
1123 | //alpha = M_PI_F>>(s->frame_len_bits - i+1); | 1064 | //alpha = M_PI_F>>(s->frame_len_bits - i+1); |
1124 | alpha = (1<<15)>>(s->frame_len_bits - i+1); /* this calculates 0.5/(2*n) */ | 1065 | alpha = (1<<15)>>(s->frame_len_bits - i+1); /* this calculates 0.5/(2*n) */ |
1125 | for(j=0;j<n;++j) | 1066 | for(j=0;j<n;++j) |
1126 | { | 1067 | { |
1127 | fixed32 j2 = itofix32(j) + 0x8000; | 1068 | fixed32 j2 = itofix32(j) + 0x8000; |
@@ -1375,7 +1316,6 @@ static int wma_decode_block(WMADecodeContext *s) | |||
1375 | { | 1316 | { |
1376 | int n, v, a, ch, code, bsize; | 1317 | int n, v, a, ch, code, bsize; |
1377 | int coef_nb_bits, total_gain; | 1318 | int coef_nb_bits, total_gain; |
1378 | //static fixed32 window[BLOCK_MAX_SIZE * 2]; //crap can't do this locally on the device! its big as the whole stack | ||
1379 | int nb_coefs[MAX_CHANNELS]; | 1319 | int nb_coefs[MAX_CHANNELS]; |
1380 | fixed32 mdct_norm; | 1320 | fixed32 mdct_norm; |
1381 | 1321 | ||
@@ -1409,8 +1349,7 @@ static int wma_decode_block(WMADecodeContext *s) | |||
1409 | } | 1349 | } |
1410 | v = get_bits(&s->gb, n); | 1350 | v = get_bits(&s->gb, n); |
1411 | 1351 | ||
1412 | //rb->fdprintf(filehandle,"v %d \n prev_block_len_bits %d\n block_len_bits %d\n", v, s->prev_block_len_bits, s->block_len_bits); | 1352 | |
1413 | //rb->close(filehandle); | ||
1414 | 1353 | ||
1415 | LOGF("v was %d", v); | 1354 | LOGF("v was %d", v); |
1416 | if (v >= s->nb_block_sizes) | 1355 | if (v >= s->nb_block_sizes) |
@@ -1779,10 +1718,10 @@ static int wma_decode_block(WMADecodeContext *s) | |||
1779 | 1718 | ||
1780 | for(i = 0;i < n; ++i) | 1719 | for(i = 0;i < n; ++i) |
1781 | { | 1720 | { |
1782 | /* | 1721 | /* |
1783 | * Previously the IMDCT was run in 17.15 precision to avoid overflow. However rare files could | 1722 | * Previously the IMDCT was run in 17.15 precision to avoid overflow. However rare files could |
1784 | * overflow here as well, so switch to 17.15 now. As a bonus, this saves us a shift later on. | 1723 | * overflow here as well, so switch to 17.15 now. As a bonus, this saves us a shift later on. |
1785 | */ | 1724 | */ |
1786 | 1725 | ||
1787 | 1726 | ||
1788 | atemp = (fixed32)(coefs1[i]*mult>>17); | 1727 | atemp = (fixed32)(coefs1[i]*mult>>17); |
@@ -1844,7 +1783,7 @@ static int wma_decode_block(WMADecodeContext *s) | |||
1844 | /* add in the frame */ | 1783 | /* add in the frame */ |
1845 | index = (s->frame_len / 2) + s->block_pos - n4; | 1784 | index = (s->frame_len / 2) + s->block_pos - n4; |
1846 | 1785 | ||
1847 | wma_window(s, output, &s->frame_out[ch][index]); | 1786 | wma_window(s, output, &s->frame_out[ch][index]); |
1848 | 1787 | ||
1849 | 1788 | ||
1850 | 1789 | ||
@@ -1935,9 +1874,9 @@ static int wma_decode_frame(WMADecodeContext *s, int16_t *samples) | |||
1935 | } | 1874 | } |
1936 | 1875 | ||
1937 | int wma_decode_superframe(WMADecodeContext* s, | 1876 | int wma_decode_superframe(WMADecodeContext* s, |
1938 | void *data, /*output*/ | 1877 | void *data, /*output*/ |
1939 | int *data_size, | 1878 | int *data_size, |
1940 | uint8_t *buf, /*input*/ | 1879 | uint8_t *buf, /*input*/ |
1941 | int buf_size) | 1880 | int buf_size) |
1942 | { | 1881 | { |
1943 | //WMADecodeContext *s = avctx->priv_data; | 1882 | //WMADecodeContext *s = avctx->priv_data; |
@@ -2040,36 +1979,4 @@ fail: | |||
2040 | return -1; | 1979 | return -1; |
2041 | } | 1980 | } |
2042 | 1981 | ||
2043 | /*void free_vlc(VLC *vlc) | ||
2044 | { | ||
2045 | //av_free(vlc->table); | ||
2046 | } | ||
2047 | */ | ||
2048 | int wma_decode_end(WMADecodeContext *s) | ||
2049 | { | ||
2050 | (void)s; | ||
2051 | /* WMADecodeContext *s = avctx->priv_data; | ||
2052 | int i; | ||
2053 | |||
2054 | for(i = 0; i < s->nb_block_sizes; ++i) | ||
2055 | ff_mdct_end(&s->mdct_ctx[i]); | ||
2056 | // for(i = 0; i < s->nb_block_sizes; ++i) //now statically allocated | ||
2057 | // av_free(s->windows[i]); | ||
2058 | 1982 | ||
2059 | if (s->use_exp_vlc) | ||
2060 | { | ||
2061 | free_vlc(&s->exp_vlc); | ||
2062 | } | ||
2063 | if (s->use_noise_coding) | ||
2064 | { | ||
2065 | free_vlc(&s->hgain_vlc); | ||
2066 | } | ||
2067 | for(i = 0;i < 2; ++i) | ||
2068 | { | ||
2069 | // free_vlc(&s->coef_vlc[i]); | ||
2070 | // av_free(s->run_table[i]); | ||
2071 | // av_free(s->level_table[i]); | ||
2072 | } | ||
2073 | */ | ||
2074 | return 0; | ||
2075 | } | ||