comparison aac.c @ 8413:6f40f7d77263 libavcodec

AAC: Fix AAC prediction when used in conjunction with the CPE Patch by Alex Converse (alex converse gmail com)
author superdump
date Sun, 21 Dec 2008 05:28:14 +0000
parents 2d48043ab521
children 3030aa991ed1
comparison
equal deleted inserted replaced
8412:2d48043ab521 8413:6f40f7d77263
751 for (i = 0; i < ics->max_sfb; i++, idx++) { 751 for (i = 0; i < ics->max_sfb; i++, idx++) {
752 const int cur_band_type = band_type[idx]; 752 const int cur_band_type = band_type[idx];
753 const int dim = cur_band_type >= FIRST_PAIR_BT ? 2 : 4; 753 const int dim = cur_band_type >= FIRST_PAIR_BT ? 2 : 4;
754 const int is_cb_unsigned = IS_CODEBOOK_UNSIGNED(cur_band_type); 754 const int is_cb_unsigned = IS_CODEBOOK_UNSIGNED(cur_band_type);
755 int group; 755 int group;
756 if (cur_band_type == ZERO_BT) { 756 if (cur_band_type == ZERO_BT || cur_band_type == INTENSITY_BT2 || cur_band_type == INTENSITY_BT) {
757 for (group = 0; group < ics->group_len[g]; group++) { 757 for (group = 0; group < ics->group_len[g]; group++) {
758 memset(coef + group * 128 + offsets[i], 0, (offsets[i+1] - offsets[i])*sizeof(float)); 758 memset(coef + group * 128 + offsets[i], 0, (offsets[i+1] - offsets[i])*sizeof(float));
759 } 759 }
760 }else if (cur_band_type == NOISE_BT) { 760 }else if (cur_band_type == NOISE_BT) {
761 for (group = 0; group < ics->group_len[g]; group++) { 761 for (group = 0; group < ics->group_len[g]; group++) {
769 scale = sf[idx] / sqrtf(band_energy); 769 scale = sf[idx] / sqrtf(band_energy);
770 for (k = offsets[i]; k < offsets[i+1]; k++) { 770 for (k = offsets[i]; k < offsets[i+1]; k++) {
771 coef[group*128+k] *= scale; 771 coef[group*128+k] *= scale;
772 } 772 }
773 } 773 }
774 }else if (cur_band_type != INTENSITY_BT2 && cur_band_type != INTENSITY_BT) { 774 }else {
775 for (group = 0; group < ics->group_len[g]; group++) { 775 for (group = 0; group < ics->group_len[g]; group++) {
776 for (k = offsets[i]; k < offsets[i+1]; k += dim) { 776 for (k = offsets[i]; k < offsets[i+1]; k += dim) {
777 const int index = get_vlc2(gb, vlc_spectral[cur_band_type - 1].table, 6, 3); 777 const int index = get_vlc2(gb, vlc_spectral[cur_band_type - 1].table, 6, 3);
778 const int coef_tmp_idx = (group << 7) + k; 778 const int coef_tmp_idx = (group << 7) + k;
779 const float *vq_ptr; 779 const float *vq_ptr;
909 */ 909 */
910 static void apply_prediction(AACContext * ac, SingleChannelElement * sce) { 910 static void apply_prediction(AACContext * ac, SingleChannelElement * sce) {
911 int sfb, k; 911 int sfb, k;
912 912
913 if (!sce->ics.predictor_initialized) { 913 if (!sce->ics.predictor_initialized) {
914 reset_all_predictors(sce->ics.predictor_state); 914 reset_all_predictors(sce->predictor_state);
915 sce->ics.predictor_initialized = 1; 915 sce->ics.predictor_initialized = 1;
916 } 916 }
917 917
918 if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) { 918 if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) {
919 for (sfb = 0; sfb < ff_aac_pred_sfb_max[ac->m4ac.sampling_index]; sfb++) { 919 for (sfb = 0; sfb < ff_aac_pred_sfb_max[ac->m4ac.sampling_index]; sfb++) {
920 for (k = sce->ics.swb_offset[sfb]; k < sce->ics.swb_offset[sfb + 1]; k++) { 920 for (k = sce->ics.swb_offset[sfb]; k < sce->ics.swb_offset[sfb + 1]; k++) {
921 predict(ac, &sce->ics.predictor_state[k], &sce->coeffs[k], 921 predict(ac, &sce->predictor_state[k], &sce->coeffs[k],
922 sce->ics.predictor_present && sce->ics.prediction_used[sfb]); 922 sce->ics.predictor_present && sce->ics.prediction_used[sfb]);
923 } 923 }
924 } 924 }
925 if (sce->ics.predictor_reset_group) 925 if (sce->ics.predictor_reset_group)
926 reset_predictor_group(sce->ics.predictor_state, sce->ics.predictor_reset_group); 926 reset_predictor_group(sce->predictor_state, sce->ics.predictor_reset_group);
927 } else 927 } else
928 reset_all_predictors(sce->ics.predictor_state); 928 reset_all_predictors(sce->predictor_state);
929 } 929 }
930 930
931 /** 931 /**
932 * Decode an individual_channel_stream payload; reference: table 4.44. 932 * Decode an individual_channel_stream payload; reference: table 4.44.
933 * 933 *
981 } 981 }
982 982
983 if (decode_spectrum_and_dequant(ac, out, gb, sce->sf, pulse_present, &pulse, ics, sce->band_type) < 0) 983 if (decode_spectrum_and_dequant(ac, out, gb, sce->sf, pulse_present, &pulse, ics, sce->band_type) < 0)
984 return -1; 984 return -1;
985 985
986 if(ac->m4ac.object_type == AOT_AAC_MAIN) 986 if(ac->m4ac.object_type == AOT_AAC_MAIN && !common_window)
987 apply_prediction(ac, sce); 987 apply_prediction(ac, sce);
988 988
989 return 0; 989 return 0;
990 } 990 }
991 991
1084 if ((ret = decode_ics(ac, &cpe->ch[0], gb, common_window, 0))) 1084 if ((ret = decode_ics(ac, &cpe->ch[0], gb, common_window, 0)))
1085 return ret; 1085 return ret;
1086 if ((ret = decode_ics(ac, &cpe->ch[1], gb, common_window, 0))) 1086 if ((ret = decode_ics(ac, &cpe->ch[1], gb, common_window, 0)))
1087 return ret; 1087 return ret;
1088 1088
1089 if (common_window && ms_present) 1089 if (common_window) {
1090 if (ms_present)
1090 apply_mid_side_stereo(cpe); 1091 apply_mid_side_stereo(cpe);
1092 if (ac->m4ac.object_type == AOT_AAC_MAIN) {
1093 apply_prediction(ac, &cpe->ch[0]);
1094 apply_prediction(ac, &cpe->ch[1]);
1095 }
1096 }
1091 1097
1092 apply_intensity_stereo(cpe, ms_present); 1098 apply_intensity_stereo(cpe, ms_present);
1093 return 0; 1099 return 0;
1094 } 1100 }
1095 1101