comparison wmadec.c @ 3113:ab01ee59324f libavcodec

- fix insufficient code length for exp_vlc - move vlc tweaking parameters to one place
author henry
date Sat, 11 Feb 2006 19:39:05 +0000
parents 072dbc669253
children babf844e1308
comparison
equal deleted inserted replaced
3112:31d15c4d86a0 3113:ab01ee59324f
55 #define NOISE_TAB_SIZE 8192 55 #define NOISE_TAB_SIZE 8192
56 56
57 #define LSP_POW_BITS 7 57 #define LSP_POW_BITS 7
58 58
59 #define VLCBITS 9 59 #define VLCBITS 9
60 #define VLCMAX ((22+VLCBITS-1)/VLCBITS)
61
62 #define EXPVLCBITS 8
63 #define EXPMAX ((19+EXPVLCBITS-1)/EXPVLCBITS)
64
65 #define HGAINVLCBITS 9
66 #define HGAINMAX ((13+HGAINVLCBITS-1)/HGAINVLCBITS)
60 67
61 typedef struct WMADecodeContext { 68 typedef struct WMADecodeContext {
62 GetBitContext gb; 69 GetBitContext gb;
63 int sample_rate; 70 int sample_rate;
64 int nb_channels; 71 int nb_channels;
183 const uint16_t *levels_table = vlc_table->levels; 190 const uint16_t *levels_table = vlc_table->levels;
184 uint16_t *run_table, *level_table; 191 uint16_t *run_table, *level_table;
185 const uint16_t *p; 192 const uint16_t *p;
186 int i, l, j, level; 193 int i, l, j, level;
187 194
188 init_vlc(vlc, 9, n, table_bits, 1, 1, table_codes, 4, 4, 0); 195 init_vlc(vlc, VLCBITS, n, table_bits, 1, 1, table_codes, 4, 4, 0);
189 196
190 run_table = av_malloc(n * sizeof(uint16_t)); 197 run_table = av_malloc(n * sizeof(uint16_t));
191 level_table = av_malloc(n * sizeof(uint16_t)); 198 level_table = av_malloc(n * sizeof(uint16_t));
192 p = levels_table; 199 p = levels_table;
193 i = 2; 200 i = 2;
492 seed = seed * 314159 + 1; 499 seed = seed * 314159 + 1;
493 s->noise_table[i] = (float)((int)seed) * norm; 500 s->noise_table[i] = (float)((int)seed) * norm;
494 } 501 }
495 } 502 }
496 #endif 503 #endif
497 init_vlc(&s->hgain_vlc, 9, sizeof(hgain_huffbits), 504 init_vlc(&s->hgain_vlc, HGAINVLCBITS, sizeof(hgain_huffbits),
498 hgain_huffbits, 1, 1, 505 hgain_huffbits, 1, 1,
499 hgain_huffcodes, 2, 2, 0); 506 hgain_huffcodes, 2, 2, 0);
500 } 507 }
501 508
502 if (s->use_exp_vlc) { 509 if (s->use_exp_vlc) {
503 init_vlc(&s->exp_vlc, 9, sizeof(scale_huffbits), 510 init_vlc(&s->exp_vlc, EXPVLCBITS, sizeof(scale_huffbits),
504 scale_huffbits, 1, 1, 511 scale_huffbits, 1, 1,
505 scale_huffcodes, 4, 4, 0); 512 scale_huffcodes, 4, 4, 0);
506 } else { 513 } else {
507 wma_lsp_to_curve_init(s, s->frame_len); 514 wma_lsp_to_curve_init(s, s->frame_len);
508 } 515 }
679 *q++ = v; 686 *q++ = v;
680 } while (--n); 687 } while (--n);
681 } 688 }
682 last_exp = 36; 689 last_exp = 36;
683 while (q < q_end) { 690 while (q < q_end) {
684 code = get_vlc2(&s->gb, s->exp_vlc.table, VLCBITS, 2); 691 code = get_vlc2(&s->gb, s->exp_vlc.table, EXPVLCBITS, EXPMAX);
685 if (code < 0) 692 if (code < 0)
686 return -1; 693 return -1;
687 /* NOTE: this offset is the same as MPEG4 AAC ! */ 694 /* NOTE: this offset is the same as MPEG4 AAC ! */
688 last_exp += code - 60; 695 last_exp += code - 60;
689 /* XXX: use a table */ 696 /* XXX: use a table */
820 for(i=0;i<n;i++) { 827 for(i=0;i<n;i++) {
821 if (s->high_band_coded[ch][i]) { 828 if (s->high_band_coded[ch][i]) {
822 if (val == (int)0x80000000) { 829 if (val == (int)0x80000000) {
823 val = get_bits(&s->gb, 7) - 19; 830 val = get_bits(&s->gb, 7) - 19;
824 } else { 831 } else {
825 code = get_vlc2(&s->gb, s->hgain_vlc.table, VLCBITS, 2); 832 code = get_vlc2(&s->gb, s->hgain_vlc.table, HGAINVLCBITS, HGAINMAX);
826 if (code < 0) 833 if (code < 0)
827 return -1; 834 return -1;
828 val += code - 18; 835 val += code - 18;
829 } 836 }
830 s->high_band_values[ch][i] = val; 837 s->high_band_values[ch][i] = val;
877 /* XXX: optimize */ 884 /* XXX: optimize */
878 ptr = &s->coefs1[ch][0]; 885 ptr = &s->coefs1[ch][0];
879 eptr = ptr + nb_coefs[ch]; 886 eptr = ptr + nb_coefs[ch];
880 memset(ptr, 0, s->block_len * sizeof(int16_t)); 887 memset(ptr, 0, s->block_len * sizeof(int16_t));
881 for(;;) { 888 for(;;) {
882 code = get_vlc2(&s->gb, coef_vlc->table, VLCBITS, 3); 889 code = get_vlc2(&s->gb, coef_vlc->table, VLCBITS, VLCMAX);
883 if (code < 0) 890 if (code < 0)
884 return -1; 891 return -1;
885 if (code == 1) { 892 if (code == 1) {
886 /* EOB */ 893 /* EOB */
887 break; 894 break;