Mercurial > libavcodec.hg
comparison wmadec.c @ 1342:f574934c4219 libavcodec
uniformization (now it uses the same trace functions as h264, defined in common.h)
author | al3x |
---|---|
date | Fri, 04 Jul 2003 20:26:04 +0000 |
parents | e1fae3528935 |
children | 1fd083c620d6 |
comparison
equal
deleted
inserted
replaced
1341:6e5d4ec4f3ab | 1342:f574934c4219 |
---|---|
22 * WMA compatible decoder. | 22 * WMA compatible decoder. |
23 */ | 23 */ |
24 | 24 |
25 #include "avcodec.h" | 25 #include "avcodec.h" |
26 #include "dsputil.h" | 26 #include "dsputil.h" |
27 | |
28 //#define DEBUG_PARAMS | |
29 //#define DEBUG_TRACE | |
30 | 27 |
31 /* size of blocks */ | 28 /* size of blocks */ |
32 #define BLOCK_MIN_BITS 7 | 29 #define BLOCK_MIN_BITS 7 |
33 #define BLOCK_MAX_BITS 11 | 30 #define BLOCK_MAX_BITS 11 |
34 #define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS) | 31 #define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS) |
125 | 122 |
126 static void wma_lsp_to_curve_init(WMADecodeContext *s, int frame_len); | 123 static void wma_lsp_to_curve_init(WMADecodeContext *s, int frame_len); |
127 | 124 |
128 #include "wmadata.h" | 125 #include "wmadata.h" |
129 | 126 |
130 #ifdef DEBUG_TRACE | 127 #ifdef TRACE |
131 #include <stdarg.h> | 128 int frame_count = 0; |
132 int frame_count; | |
133 | |
134 static FILE *flog; | |
135 | |
136 void trace(const char *fmt, ...) | |
137 { | |
138 va_list ap; | |
139 | |
140 | |
141 if (!flog) { | |
142 flog = fopen("/tmp/out.log", "w"); | |
143 setlinebuf(flog); | |
144 } | |
145 | |
146 va_start(ap, fmt); | |
147 vfprintf(flog, fmt, ap); | |
148 va_end(ap); | |
149 } | |
150 | |
151 #define get_bits(s, n) get_bits_trace(s, n) | |
152 #define get_vlc(s, vlc) get_vlc_trace(s, vlc) | |
153 | |
154 unsigned int get_bits_trace(GetBitContext *s, int n) | |
155 { | |
156 unsigned int val; | |
157 val = (get_bits)(s, n); | |
158 trace("get_bits(%d) : 0x%x\n", n, val); | |
159 return val; | |
160 } | |
161 | |
162 static int get_vlc_trace(GetBitContext *s, VLC *vlc) | |
163 { | |
164 int code; | |
165 code = (get_vlc)(s, vlc); | |
166 trace("get_vlc() : %d\n", code); | |
167 return code; | |
168 } | |
169 | 129 |
170 static void dump_shorts(const char *name, const short *tab, int n) | 130 static void dump_shorts(const char *name, const short *tab, int n) |
171 { | 131 { |
172 int i; | 132 int i; |
173 | 133 |
174 trace("%s[%d]:\n", name, n); | 134 tprintf("%s[%d]:\n", name, n); |
175 for(i=0;i<n;i++) { | 135 for(i=0;i<n;i++) { |
176 if ((i & 7) == 0) | 136 if ((i & 7) == 0) |
177 trace("%4d: ", i); | 137 tprintf("%4d: ", i); |
178 trace(" %5d.0", tab[i]); | 138 tprintf(" %5d.0", tab[i]); |
179 if ((i & 7) == 7) | 139 if ((i & 7) == 7) |
180 trace("\n"); | 140 tprintf("\n"); |
181 } | 141 } |
182 } | 142 } |
183 | 143 |
184 static void dump_floats(const char *name, int prec, const float *tab, int n) | 144 static void dump_floats(const char *name, int prec, const float *tab, int n) |
185 { | 145 { |
186 int i; | 146 int i; |
187 | 147 |
188 trace("%s[%d]:\n", name, n); | 148 tprintf("%s[%d]:\n", name, n); |
189 for(i=0;i<n;i++) { | 149 for(i=0;i<n;i++) { |
190 if ((i & 7) == 0) | 150 if ((i & 7) == 0) |
191 trace("%4d: ", i); | 151 tprintf("%4d: ", i); |
192 trace(" %8.*f", prec, tab[i]); | 152 tprintf(" %8.*f", prec, tab[i]); |
193 if ((i & 7) == 7) | 153 if ((i & 7) == 7) |
194 trace("\n"); | 154 tprintf("\n"); |
195 } | 155 } |
196 if ((i & 7) != 0) | 156 if ((i & 7) != 0) |
197 trace("\n"); | 157 tprintf("\n"); |
198 } | 158 } |
199 | |
200 #else | |
201 | |
202 #define trace(fmt, args...) | |
203 | |
204 #endif | 159 #endif |
205 | 160 |
206 /* XXX: use same run/length optimization as mpeg decoders */ | 161 /* XXX: use same run/length optimization as mpeg decoders */ |
207 static void init_coef_vlc(VLC *vlc, | 162 static void init_coef_vlc(VLC *vlc, |
208 uint16_t **prun_table, uint16_t **plevel_table, | 163 uint16_t **prun_table, uint16_t **plevel_table, |
357 high_freq = high_freq * 0.6; | 312 high_freq = high_freq * 0.6; |
358 } else { | 313 } else { |
359 high_freq = high_freq * 0.5; | 314 high_freq = high_freq * 0.5; |
360 } | 315 } |
361 } | 316 } |
362 #ifdef DEBUG_PARAMS | 317 dprintf("flags1=0x%x flags2=0x%x\n", flags1, flags2); |
363 printf("flags1=0x%x flags2=0x%x\n", flags1, flags2); | 318 dprintf("version=%d channels=%d sample_rate=%d bitrate=%d block_align=%d\n", |
364 printf("version=%d channels=%d sample_rate=%d bitrate=%d block_align=%d\n", | |
365 s->version, s->nb_channels, s->sample_rate, s->bit_rate, | 319 s->version, s->nb_channels, s->sample_rate, s->bit_rate, |
366 s->block_align); | 320 s->block_align); |
367 printf("bps=%f bps1=%f high_freq=%f bitoffset=%d\n", | 321 dprintf("bps=%f bps1=%f high_freq=%f bitoffset=%d\n", |
368 bps, bps1, high_freq, s->byte_offset_bits); | 322 bps, bps1, high_freq, s->byte_offset_bits); |
369 printf("use_noise_coding=%d use_exp_vlc=%d nb_block_sizes=%d\n", | 323 dprintf("use_noise_coding=%d use_exp_vlc=%d nb_block_sizes=%d\n", |
370 s->use_noise_coding, s->use_exp_vlc, s->nb_block_sizes); | 324 s->use_noise_coding, s->use_exp_vlc, s->nb_block_sizes); |
371 #endif | |
372 | 325 |
373 /* compute the scale factor band sizes for each MDCT block size */ | 326 /* compute the scale factor band sizes for each MDCT block size */ |
374 { | 327 { |
375 int a, b, pos, lpos, k, block_len, i, j, n; | 328 int a, b, pos, lpos, k, block_len, i, j, n; |
376 const uint8_t *table; | 329 const uint8_t *table; |
456 if (end > start) | 409 if (end > start) |
457 s->exponent_high_bands[k][j++] = end - start; | 410 s->exponent_high_bands[k][j++] = end - start; |
458 } | 411 } |
459 s->exponent_high_sizes[k] = j; | 412 s->exponent_high_sizes[k] = j; |
460 #if 0 | 413 #if 0 |
461 trace("%5d: coefs_end=%d high_band_start=%d nb_high_bands=%d: ", | 414 tprintf("%5d: coefs_end=%d high_band_start=%d nb_high_bands=%d: ", |
462 s->frame_len >> k, | 415 s->frame_len >> k, |
463 s->coefs_end[k], | 416 s->coefs_end[k], |
464 s->high_band_start[k], | 417 s->high_band_start[k], |
465 s->exponent_high_sizes[k]); | 418 s->exponent_high_sizes[k]); |
466 for(j=0;j<s->exponent_high_sizes[k];j++) | 419 for(j=0;j<s->exponent_high_sizes[k];j++) |
467 trace(" %d", s->exponent_high_bands[k][j]); | 420 tprintf(" %d", s->exponent_high_bands[k][j]); |
468 trace("\n"); | 421 tprintf("\n"); |
469 #endif | 422 #endif |
470 } | 423 } |
471 } | 424 } |
472 | 425 |
473 #ifdef DEBUG_TRACE | 426 #ifdef TRACE |
474 { | 427 { |
475 int i, j; | 428 int i, j; |
476 for(i = 0; i < s->nb_block_sizes; i++) { | 429 for(i = 0; i < s->nb_block_sizes; i++) { |
477 trace("%5d: n=%2d:", | 430 tprintf("%5d: n=%2d:", |
478 s->frame_len >> i, | 431 s->frame_len >> i, |
479 s->exponent_sizes[i]); | 432 s->exponent_sizes[i]); |
480 for(j=0;j<s->exponent_sizes[i];j++) | 433 for(j=0;j<s->exponent_sizes[i];j++) |
481 trace(" %d", s->exponent_bands[i][j]); | 434 tprintf(" %d", s->exponent_bands[i][j]); |
482 trace("\n"); | 435 tprintf("\n"); |
483 } | 436 } |
484 } | 437 } |
485 #endif | 438 #endif |
486 | 439 |
487 /* init MDCT */ | 440 /* init MDCT */ |
509 if (s->use_exp_vlc) | 462 if (s->use_exp_vlc) |
510 s->noise_mult = 0.02; | 463 s->noise_mult = 0.02; |
511 else | 464 else |
512 s->noise_mult = 0.04; | 465 s->noise_mult = 0.04; |
513 | 466 |
514 #if defined(DEBUG_TRACE) | 467 #ifdef TRACE |
515 for(i=0;i<NOISE_TAB_SIZE;i++) | 468 for(i=0;i<NOISE_TAB_SIZE;i++) |
516 s->noise_table[i] = 1.0 * s->noise_mult; | 469 s->noise_table[i] = 1.0 * s->noise_mult; |
517 #else | 470 #else |
518 { | 471 { |
519 unsigned int seed; | 472 unsigned int seed; |
739 int coef_nb_bits, total_gain, parse_exponents; | 692 int coef_nb_bits, total_gain, parse_exponents; |
740 float window[BLOCK_MAX_SIZE * 2]; | 693 float window[BLOCK_MAX_SIZE * 2]; |
741 int nb_coefs[MAX_CHANNELS]; | 694 int nb_coefs[MAX_CHANNELS]; |
742 float mdct_norm; | 695 float mdct_norm; |
743 | 696 |
744 trace("***decode_block: %d:%d\n", frame_count - 1, s->block_num); | 697 tprintf("***decode_block: %d:%d\n", frame_count - 1, s->block_num); |
745 | 698 |
746 /* compute current block length */ | 699 /* compute current block length */ |
747 if (s->use_variable_block_len) { | 700 if (s->use_variable_block_len) { |
748 n = av_log2(s->nb_block_sizes - 1) + 1; | 701 n = av_log2(s->nb_block_sizes - 1) + 1; |
749 | 702 |
985 v = exp_ptr[i]; | 938 v = exp_ptr[i]; |
986 e2 += v * v; | 939 e2 += v * v; |
987 } | 940 } |
988 exp_power[j] = e2 / n; | 941 exp_power[j] = e2 / n; |
989 last_high_band = j; | 942 last_high_band = j; |
990 trace("%d: power=%f (%d)\n", j, exp_power[j], n); | 943 tprintf("%d: power=%f (%d)\n", j, exp_power[j], n); |
991 } | 944 } |
992 exp_ptr += n; | 945 exp_ptr += n; |
993 } | 946 } |
994 | 947 |
995 /* main freqs and high freqs */ | 948 /* main freqs and high freqs */ |
1043 *coefs++ = 0.0; | 996 *coefs++ = 0.0; |
1044 } | 997 } |
1045 } | 998 } |
1046 } | 999 } |
1047 | 1000 |
1048 #ifdef DEBUG_TRACE | 1001 #ifdef TRACE |
1049 for(ch = 0; ch < s->nb_channels; ch++) { | 1002 for(ch = 0; ch < s->nb_channels; ch++) { |
1050 if (s->channel_coded[ch]) { | 1003 if (s->channel_coded[ch]) { |
1051 dump_floats("exponents", 3, s->exponents[ch], s->block_len); | 1004 dump_floats("exponents", 3, s->exponents[ch], s->block_len); |
1052 dump_floats("coefs", 1, s->coefs[ch], s->block_len); | 1005 dump_floats("coefs", 1, s->coefs[ch], s->block_len); |
1053 } | 1006 } |
1060 | 1013 |
1061 /* nominal case for ms stereo: we do it before mdct */ | 1014 /* nominal case for ms stereo: we do it before mdct */ |
1062 /* no need to optimize this case because it should almost | 1015 /* no need to optimize this case because it should almost |
1063 never happen */ | 1016 never happen */ |
1064 if (!s->channel_coded[0]) { | 1017 if (!s->channel_coded[0]) { |
1065 #ifdef DEBUG_TRACE | 1018 tprintf("rare ms-stereo case happened\n"); |
1066 trace("rare ms-stereo case happened\n"); | |
1067 #endif | |
1068 memset(s->coefs[0], 0, sizeof(float) * s->block_len); | 1019 memset(s->coefs[0], 0, sizeof(float) * s->block_len); |
1069 s->channel_coded[0] = 1; | 1020 s->channel_coded[0] = 1; |
1070 } | 1021 } |
1071 | 1022 |
1072 for(i = 0; i < s->block_len; i++) { | 1023 for(i = 0; i < s->block_len; i++) { |
1174 { | 1125 { |
1175 int ret, i, n, a, ch, incr; | 1126 int ret, i, n, a, ch, incr; |
1176 int16_t *ptr; | 1127 int16_t *ptr; |
1177 float *iptr; | 1128 float *iptr; |
1178 | 1129 |
1179 trace("***decode_frame: %d size=%d\n", frame_count++, s->frame_len); | 1130 tprintf("***decode_frame: %d size=%d\n", frame_count++, s->frame_len); |
1180 | 1131 |
1181 /* read each block */ | 1132 /* read each block */ |
1182 s->block_num = 0; | 1133 s->block_num = 0; |
1183 s->block_pos = 0; | 1134 s->block_pos = 0; |
1184 for(;;) { | 1135 for(;;) { |
1211 /* XXX: suppress this */ | 1162 /* XXX: suppress this */ |
1212 memset(&s->frame_out[ch][s->frame_len], 0, | 1163 memset(&s->frame_out[ch][s->frame_len], 0, |
1213 s->frame_len * sizeof(float)); | 1164 s->frame_len * sizeof(float)); |
1214 } | 1165 } |
1215 | 1166 |
1216 #ifdef DEBUG_TRACE | 1167 #ifdef TRACE |
1217 dump_shorts("samples", samples, n * s->nb_channels); | 1168 dump_shorts("samples", samples, n * s->nb_channels); |
1218 #endif | 1169 #endif |
1219 return 0; | 1170 return 0; |
1220 } | 1171 } |
1221 | 1172 |
1226 WMADecodeContext *s = avctx->priv_data; | 1177 WMADecodeContext *s = avctx->priv_data; |
1227 int nb_frames, bit_offset, i, pos, len; | 1178 int nb_frames, bit_offset, i, pos, len; |
1228 uint8_t *q; | 1179 uint8_t *q; |
1229 int16_t *samples; | 1180 int16_t *samples; |
1230 | 1181 |
1231 trace("***decode_superframe:\n"); | 1182 tprintf("***decode_superframe:\n"); |
1232 | 1183 |
1233 samples = data; | 1184 samples = data; |
1234 | 1185 |
1235 init_get_bits(&s->gb, buf, buf_size*8); | 1186 init_get_bits(&s->gb, buf, buf_size*8); |
1236 | 1187 |