Mercurial > audlegacy
comparison Plugins/Input/wma/libffwma/wmadec.c @ 218:0bea7509d6ba trunk
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
author | chainsaw |
---|---|
date | Mon, 21 Nov 2005 14:59:13 -0800 |
parents | 12004b385a96 |
children | 28b73b5595d1 |
comparison
equal
deleted
inserted
replaced
217:ac3fb5691ddc | 218:0bea7509d6ba |
---|---|
36 #define HIGH_BAND_MAX_SIZE 16 | 36 #define HIGH_BAND_MAX_SIZE 16 |
37 | 37 |
38 #define NB_LSP_COEFS 10 | 38 #define NB_LSP_COEFS 10 |
39 | 39 |
40 /* XXX: is it a suitable value ? */ | 40 /* XXX: is it a suitable value ? */ |
41 #define MAX_CODED_SUPERFRAME_SIZE 16384 | 41 #define MAX_CODED_SUPERFRAME_SIZE 4096 |
42 | 42 |
43 #define MAX_CHANNELS 2 | 43 #define MAX_CHANNELS 2 |
44 | 44 |
45 #define NOISE_TAB_SIZE 8192 | 45 #define NOISE_TAB_SIZE 8192 |
46 | 46 |
173 const uint16_t *p; | 173 const uint16_t *p; |
174 int i, l, j, level; | 174 int i, l, j, level; |
175 | 175 |
176 init_vlc(vlc, 9, n, table_bits, 1, 1, table_codes, 4, 4); | 176 init_vlc(vlc, 9, n, table_bits, 1, 1, table_codes, 4, 4); |
177 | 177 |
178 run_table = av_malloc(n * sizeof(uint16_t)); | 178 run_table = malloc(n * sizeof(uint16_t)); |
179 level_table = av_malloc(n * sizeof(uint16_t)); | 179 level_table = malloc(n * sizeof(uint16_t)); |
180 p = levels_table; | 180 p = levels_table; |
181 i = 2; | 181 i = 2; |
182 level = 1; | 182 level = 1; |
183 while (i < n) { | 183 while (i < n) { |
184 l = *p++; | 184 l = *p++; |
447 /* init MDCT windows : simple sinus window */ | 447 /* init MDCT windows : simple sinus window */ |
448 for(i = 0; i < s->nb_block_sizes; i++) { | 448 for(i = 0; i < s->nb_block_sizes; i++) { |
449 int n, j; | 449 int n, j; |
450 float alpha; | 450 float alpha; |
451 n = 1 << (s->frame_len_bits - i); | 451 n = 1 << (s->frame_len_bits - i); |
452 window = av_malloc(sizeof(float) * n); | 452 window = malloc(sizeof(float) * n); |
453 alpha = M_PI / (2.0 * n); | 453 alpha = M_PI / (2.0 * n); |
454 for(j=0;j<n;j++) { | 454 for(j=0;j<n;j++) { |
455 window[n - j - 1] = sin((j + 0.5) * alpha); | 455 window[n - j - 1] = sin((j + 0.5) * alpha); |
456 } | 456 } |
457 s->windows[i] = window; | 457 s->windows[i] = window; |
847 for(ch = 0; ch < s->nb_channels; ch++) { | 847 for(ch = 0; ch < s->nb_channels; ch++) { |
848 if (s->channel_coded[ch]) { | 848 if (s->channel_coded[ch]) { |
849 VLC *coef_vlc; | 849 VLC *coef_vlc; |
850 int level, run, sign, tindex; | 850 int level, run, sign, tindex; |
851 int16_t *ptr, *eptr; | 851 int16_t *ptr, *eptr; |
852 const uint16_t *level_table, *run_table; | 852 const int16_t *level_table, *run_table; |
853 | 853 |
854 /* special VLC tables are used for ms stereo because | 854 /* special VLC tables are used for ms stereo because |
855 there is potentially less energy there */ | 855 there is potentially less energy there */ |
856 tindex = (ch == 1 && s->ms_stereo); | 856 tindex = (ch == 1 && s->ms_stereo); |
857 coef_vlc = &s->coef_vlc[tindex]; | 857 coef_vlc = &s->coef_vlc[tindex]; |
1153 for(ch = 0; ch < s->nb_channels; ch++) { | 1153 for(ch = 0; ch < s->nb_channels; ch++) { |
1154 ptr = samples + ch; | 1154 ptr = samples + ch; |
1155 iptr = s->frame_out[ch]; | 1155 iptr = s->frame_out[ch]; |
1156 | 1156 |
1157 for(i=0;i<n;i++) { | 1157 for(i=0;i<n;i++) { |
1158 a = lrintf(*iptr++); | 1158 a = rintf(*iptr++); |
1159 if (a > 32767) | 1159 if (a > 32767) |
1160 a = 32767; | 1160 a = 32767; |
1161 else if (a < -32768) | 1161 else if (a < -32768) |
1162 a = -32768; | 1162 a = -32768; |
1163 *ptr = a; | 1163 *ptr = a; |
1270 return -1; | 1270 return -1; |
1271 } | 1271 } |
1272 | 1272 |
1273 static int wma_decode_end(AVCodecContext *avctx) | 1273 static int wma_decode_end(AVCodecContext *avctx) |
1274 { | 1274 { |
1275 WMADecodeContext *s = avctx->priv_data; | 1275 WMADecodeContext *s = avctx->priv_data; |
1276 int i; | 1276 int i; |
1277 | 1277 |
1278 for(i = 0; i < s->nb_block_sizes; i++) | 1278 for (i = 0; i < s->nb_block_sizes; i++) |
1279 ff_mdct_end(&s->mdct_ctx[i]); | 1279 ff_mdct_end(&s->mdct_ctx[i]); |
1280 for(i = 0; i < s->nb_block_sizes; i++) | 1280 |
1281 av_free(s->windows[i]); | 1281 for (i = 0; i < s->nb_block_sizes; i++) |
1282 | 1282 free(s->windows[i]); |
1283 if (s->use_exp_vlc) { | 1283 |
1284 free_vlc(&s->exp_vlc); | 1284 if (s->use_exp_vlc) { |
1285 } | 1285 free_vlc(&s->exp_vlc); |
1286 if (s->use_noise_coding) { | 1286 } |
1287 free_vlc(&s->hgain_vlc); | 1287 |
1288 } | 1288 if (s->use_noise_coding) { |
1289 for(i = 0;i < 2; i++) { | 1289 free_vlc(&s->hgain_vlc); |
1290 free_vlc(&s->coef_vlc[i]); | 1290 } |
1291 av_free(s->run_table[i]); | 1291 |
1292 av_free(s->level_table[i]); | 1292 for (i = 0; i < 2; i++) { |
1293 } | 1293 free_vlc(&s->coef_vlc[i]); |
1294 | 1294 free(s->run_table[i]); |
1295 return 0; | 1295 free(s->level_table[i]); |
1296 } | |
1297 | |
1298 return 0; | |
1296 } | 1299 } |
1297 | 1300 |
1298 AVCodec wmav1_decoder = | 1301 AVCodec wmav1_decoder = |
1299 { | 1302 { |
1300 "wmav1", | 1303 "wmav1", |
1301 CODEC_TYPE_AUDIO, | 1304 CODEC_TYPE_AUDIO, |
1302 CODEC_ID_WMAV1, | 1305 CODEC_ID_WMAV1, |
1303 sizeof(WMADecodeContext), | 1306 sizeof(WMADecodeContext), |
1304 wma_decode_init, | 1307 wma_decode_init, |
1305 NULL, | 1308 NULL, |
1306 wma_decode_end, | 1309 wma_decode_end, |
1307 wma_decode_superframe, | 1310 wma_decode_superframe, |
1308 }; | 1311 }; |
1309 | 1312 |
1310 AVCodec wmav2_decoder = | 1313 AVCodec wmav2_decoder = |
1311 { | 1314 { |
1312 "wmav2", | 1315 "wmav2", |
1313 CODEC_TYPE_AUDIO, | 1316 CODEC_TYPE_AUDIO, |
1314 CODEC_ID_WMAV2, | 1317 CODEC_ID_WMAV2, |
1315 sizeof(WMADecodeContext), | 1318 sizeof(WMADecodeContext), |
1316 wma_decode_init, | 1319 wma_decode_init, |
1317 NULL, | 1320 NULL, |
1318 wma_decode_end, | 1321 wma_decode_end, |
1319 wma_decode_superframe, | 1322 wma_decode_superframe, |
1320 }; | 1323 }; |