Mercurial > libavcodec.hg
comparison dca.c @ 11912:6db8c8adf407 libavcodec
Support DTS-ES extension (XCh) in dca: Cosmetic cleanup
Patch by Nick Brereton, nick at nbrereton dot net
author | mstorsjo |
---|---|
date | Tue, 22 Jun 2010 08:35:44 +0000 |
parents | 180c6aca1f6e |
children | c2a1bb63bd30 |
comparison
equal
deleted
inserted
replaced
11911:180c6aca1f6e | 11912:6db8c8adf407 |
---|---|
339 init_vlc(&dca_tmode.vlc[i], tmode_vlc_bits[i], 4, | 339 init_vlc(&dca_tmode.vlc[i], tmode_vlc_bits[i], 4, |
340 tmode_bits[i], 1, 1, | 340 tmode_bits[i], 1, 1, |
341 tmode_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC); | 341 tmode_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC); |
342 } | 342 } |
343 | 343 |
344 for(i = 0; i < 10; i++) | 344 for (i = 0; i < 10; i++) |
345 for(j = 0; j < 7; j++){ | 345 for (j = 0; j < 7; j++){ |
346 if(!bitalloc_codes[i][j]) break; | 346 if (!bitalloc_codes[i][j]) break; |
347 dca_smpl_bitalloc[i+1].offset = bitalloc_offsets[i]; | 347 dca_smpl_bitalloc[i+1].offset = bitalloc_offsets[i]; |
348 dca_smpl_bitalloc[i+1].wrap = 1 + (j > 4); | 348 dca_smpl_bitalloc[i+1].wrap = 1 + (j > 4); |
349 dca_smpl_bitalloc[i+1].vlc[j].table = &dca_table[dca_vlc_offs[c]]; | 349 dca_smpl_bitalloc[i+1].vlc[j].table = &dca_table[dca_vlc_offs[c]]; |
350 dca_smpl_bitalloc[i+1].vlc[j].table_allocated = dca_vlc_offs[c + 1] - dca_vlc_offs[c]; | 350 dca_smpl_bitalloc[i+1].vlc[j].table_allocated = dca_vlc_offs[c + 1] - dca_vlc_offs[c]; |
351 init_vlc(&dca_smpl_bitalloc[i+1].vlc[j], bitalloc_maxbits[i][j], | 351 init_vlc(&dca_smpl_bitalloc[i+1].vlc[j], bitalloc_maxbits[i][j], |
489 s->surround_sum = get_bits(&s->gb, 1); | 489 s->surround_sum = get_bits(&s->gb, 1); |
490 s->dialog_norm = get_bits(&s->gb, 4); | 490 s->dialog_norm = get_bits(&s->gb, 4); |
491 | 491 |
492 /* FIXME: channels mixing levels */ | 492 /* FIXME: channels mixing levels */ |
493 s->output = s->amode; | 493 s->output = s->amode; |
494 if(s->lfe) s->output |= DCA_LFE; | 494 if (s->lfe) s->output |= DCA_LFE; |
495 | 495 |
496 #ifdef TRACE | 496 #ifdef TRACE |
497 av_log(s->avctx, AV_LOG_DEBUG, "frame type: %i\n", s->frame_type); | 497 av_log(s->avctx, AV_LOG_DEBUG, "frame type: %i\n", s->frame_type); |
498 av_log(s->avctx, AV_LOG_DEBUG, "samples deficit: %i\n", s->samples_deficit); | 498 av_log(s->avctx, AV_LOG_DEBUG, "samples deficit: %i\n", s->samples_deficit); |
499 av_log(s->avctx, AV_LOG_DEBUG, "crc present: %i\n", s->crc_present); | 499 av_log(s->avctx, AV_LOG_DEBUG, "crc present: %i\n", s->crc_present); |
541 static inline int get_scale(GetBitContext *gb, int level, int value) | 541 static inline int get_scale(GetBitContext *gb, int level, int value) |
542 { | 542 { |
543 if (level < 5) { | 543 if (level < 5) { |
544 /* huffman encoded */ | 544 /* huffman encoded */ |
545 value += get_bitalloc(gb, &dca_scalefactor, level); | 545 value += get_bitalloc(gb, &dca_scalefactor, level); |
546 } else if(level < 8) | 546 } else if (level < 8) |
547 value = get_bits(gb, level + 1); | 547 value = get_bits(gb, level + 1); |
548 return value; | 548 return value; |
549 } | 549 } |
550 | 550 |
551 static int dca_subframe_header(DCAContext * s, int base_channel, int block_index) | 551 static int dca_subframe_header(DCAContext * s, int base_channel, int block_index) |
670 } | 670 } |
671 } | 671 } |
672 | 672 |
673 /* Stereo downmix coefficients */ | 673 /* Stereo downmix coefficients */ |
674 if (!base_channel && s->prim_channels > 2) { | 674 if (!base_channel && s->prim_channels > 2) { |
675 if(s->downmix) { | 675 if (s->downmix) { |
676 for (j = base_channel; j < s->prim_channels; j++) { | 676 for (j = base_channel; j < s->prim_channels; j++) { |
677 s->downmix_coef[j][0] = get_bits(&s->gb, 7); | 677 s->downmix_coef[j][0] = get_bits(&s->gb, 7); |
678 s->downmix_coef[j][1] = get_bits(&s->gb, 7); | 678 s->downmix_coef[j][1] = get_bits(&s->gb, 7); |
679 } | 679 } |
680 } else { | 680 } else { |
886 t = samples[i]; \ | 886 t = samples[i]; \ |
887 samples[i] = t * coef[0][0] + samples[i+256] * coef[1][0] + samples[i+512] * coef[2][0]; \ | 887 samples[i] = t * coef[0][0] + samples[i+256] * coef[1][0] + samples[i+512] * coef[2][0]; \ |
888 samples[i+256] = t * coef[0][1] + samples[i+256] * coef[1][1] + samples[i+512] * coef[2][1]; | 888 samples[i+256] = t * coef[0][1] + samples[i+256] * coef[1][1] + samples[i+512] * coef[2][1]; |
889 | 889 |
890 #define DOWNMIX_TO_STEREO(op1, op2) \ | 890 #define DOWNMIX_TO_STEREO(op1, op2) \ |
891 for(i = 0; i < 256; i++){ \ | 891 for (i = 0; i < 256; i++){ \ |
892 op1 \ | 892 op1 \ |
893 op2 \ | 893 op2 \ |
894 } | 894 } |
895 | 895 |
896 static void dca_downmix(float *samples, int srcfmt, | 896 static void dca_downmix(float *samples, int srcfmt, |
898 { | 898 { |
899 int i; | 899 int i; |
900 float t; | 900 float t; |
901 float coef[DCA_PRIM_CHANNELS_MAX][2]; | 901 float coef[DCA_PRIM_CHANNELS_MAX][2]; |
902 | 902 |
903 for(i=0; i<DCA_PRIM_CHANNELS_MAX; i++) { | 903 for (i=0; i<DCA_PRIM_CHANNELS_MAX; i++) { |
904 coef[i][0] = dca_downmix_coeffs[downmix_coef[i][0]]; | 904 coef[i][0] = dca_downmix_coeffs[downmix_coef[i][0]]; |
905 coef[i][1] = dca_downmix_coeffs[downmix_coef[i][1]]; | 905 coef[i][1] = dca_downmix_coeffs[downmix_coef[i][1]]; |
906 } | 906 } |
907 | 907 |
908 switch (srcfmt) { | 908 switch (srcfmt) { |
998 int sel = s->quant_index_huffman[k][abits]; | 998 int sel = s->quant_index_huffman[k][abits]; |
999 | 999 |
1000 /* | 1000 /* |
1001 * Extract bits from the bit stream | 1001 * Extract bits from the bit stream |
1002 */ | 1002 */ |
1003 if(!abits){ | 1003 if (!abits){ |
1004 memset(subband_samples[k][l], 0, 8 * sizeof(subband_samples[0][0][0])); | 1004 memset(subband_samples[k][l], 0, 8 * sizeof(subband_samples[0][0][0])); |
1005 } else { | 1005 } else { |
1006 /* Deal with transients */ | 1006 /* Deal with transients */ |
1007 int sfi = s->transition_mode[k][l] && subsubframe >= s->transition_mode[k][l]; | 1007 int sfi = s->transition_mode[k][l] && subsubframe >= s->transition_mode[k][l]; |
1008 float rscale = quant_step_size * s->scale_factor[k][l][sfi] * s->scalefactor_adj[k][sel]; | 1008 float rscale = quant_step_size * s->scale_factor[k][l][sfi] * s->scalefactor_adj[k][sel]; |
1009 | 1009 |
1010 if(abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].table){ | 1010 if (abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].table){ |
1011 if(abits <= 7){ | 1011 if (abits <= 7){ |
1012 /* Block code */ | 1012 /* Block code */ |
1013 int block_code1, block_code2, size, levels; | 1013 int block_code1, block_code2, size, levels; |
1014 | 1014 |
1015 size = abits_sizes[abits-1]; | 1015 size = abits_sizes[abits-1]; |
1016 levels = abits_levels[abits-1]; | 1016 levels = abits_levels[abits-1]; |
1137 * Unpack optional information | 1137 * Unpack optional information |
1138 */ | 1138 */ |
1139 | 1139 |
1140 /* presumably optional information only appears in the core? */ | 1140 /* presumably optional information only appears in the core? */ |
1141 if (!base_channel) { | 1141 if (!base_channel) { |
1142 if (s->timestamp) | 1142 if (s->timestamp) |
1143 get_bits(&s->gb, 32); | 1143 get_bits(&s->gb, 32); |
1144 | 1144 |
1145 if (s->aux_data) | 1145 if (s->aux_data) |
1146 aux_data_count = get_bits(&s->gb, 6); | 1146 aux_data_count = get_bits(&s->gb, 6); |
1147 | 1147 |
1148 for (i = 0; i < aux_data_count; i++) | 1148 for (i = 0; i < aux_data_count; i++) |
1149 get_bits(&s->gb, 8); | 1149 get_bits(&s->gb, 8); |
1150 | 1150 |
1151 if (s->crc_present && (s->downmix || s->dynrange)) | 1151 if (s->crc_present && (s->downmix || s->dynrange)) |
1152 get_bits(&s->gb, 16); | 1152 get_bits(&s->gb, 16); |
1153 } | 1153 } |
1154 | 1154 |
1155 return 0; | 1155 return 0; |
1156 } | 1156 } |
1157 | 1157 |
1215 int i, tmp; | 1215 int i, tmp; |
1216 const uint16_t *ssrc = (const uint16_t *) src; | 1216 const uint16_t *ssrc = (const uint16_t *) src; |
1217 uint16_t *sdst = (uint16_t *) dst; | 1217 uint16_t *sdst = (uint16_t *) dst; |
1218 PutBitContext pb; | 1218 PutBitContext pb; |
1219 | 1219 |
1220 if((unsigned)src_size > (unsigned)max_size) { | 1220 if ((unsigned)src_size > (unsigned)max_size) { |
1221 // av_log(NULL, AV_LOG_ERROR, "Input frame size larger then DCA_MAX_FRAME_SIZE!\n"); | 1221 // av_log(NULL, AV_LOG_ERROR, "Input frame size larger then DCA_MAX_FRAME_SIZE!\n"); |
1222 // return -1; | 1222 // return -1; |
1223 src_size = max_size; | 1223 src_size = max_size; |
1224 } | 1224 } |
1225 | 1225 |
1355 | 1355 |
1356 if (s->prim_channels > 0 && | 1356 if (s->prim_channels > 0 && |
1357 s->channel_order_tab[s->prim_channels - 1] < 0) | 1357 s->channel_order_tab[s->prim_channels - 1] < 0) |
1358 return -1; | 1358 return -1; |
1359 | 1359 |
1360 if(avctx->request_channels == 2 && s->prim_channels > 2) { | 1360 if (avctx->request_channels == 2 && s->prim_channels > 2) { |
1361 channels = 2; | 1361 channels = 2; |
1362 s->output = DCA_STEREO; | 1362 s->output = DCA_STEREO; |
1363 avctx->channel_layout = CH_LAYOUT_STEREO; | 1363 avctx->channel_layout = CH_LAYOUT_STEREO; |
1364 } | 1364 } |
1365 } else { | 1365 } else { |
1374 and only set avctx->channels when the crc is ok. Right now the decoder could | 1374 and only set avctx->channels when the crc is ok. Right now the decoder could |
1375 set the channels based on a broken first frame.*/ | 1375 set the channels based on a broken first frame.*/ |
1376 if (!avctx->channels) | 1376 if (!avctx->channels) |
1377 avctx->channels = channels; | 1377 avctx->channels = channels; |
1378 | 1378 |
1379 if(*data_size < (s->sample_blocks / 8) * 256 * sizeof(int16_t) * channels) | 1379 if (*data_size < (s->sample_blocks / 8) * 256 * sizeof(int16_t) * channels) |
1380 return -1; | 1380 return -1; |
1381 *data_size = 256 / 8 * s->sample_blocks * sizeof(int16_t) * channels; | 1381 *data_size = 256 / 8 * s->sample_blocks * sizeof(int16_t) * channels; |
1382 | 1382 |
1383 /* filter to get final output */ | 1383 /* filter to get final output */ |
1384 for (i = 0; i < (s->sample_blocks / 8); i++) { | 1384 for (i = 0; i < (s->sample_blocks / 8); i++) { |
1419 | 1419 |
1420 for (i = 0; i < DCA_PRIM_CHANNELS_MAX+1; i++) | 1420 for (i = 0; i < DCA_PRIM_CHANNELS_MAX+1; i++) |
1421 s->samples_chanptr[i] = s->samples + i * 256; | 1421 s->samples_chanptr[i] = s->samples + i * 256; |
1422 avctx->sample_fmt = SAMPLE_FMT_S16; | 1422 avctx->sample_fmt = SAMPLE_FMT_S16; |
1423 | 1423 |
1424 if(s->dsp.float_to_int16_interleave == ff_float_to_int16_interleave_c) { | 1424 if (s->dsp.float_to_int16_interleave == ff_float_to_int16_interleave_c) { |
1425 s->add_bias = 385.0f; | 1425 s->add_bias = 385.0f; |
1426 s->scale_bias = 1.0 / 32768.0; | 1426 s->scale_bias = 1.0 / 32768.0; |
1427 } else { | 1427 } else { |
1428 s->add_bias = 0.0f; | 1428 s->add_bias = 0.0f; |
1429 s->scale_bias = 1.0; | 1429 s->scale_bias = 1.0; |