Mercurial > libavcodec.hg
comparison aac.c @ 8004:8fd8f23be794 libavcodec
Corrections to channel coupling code to attain conformance for appropriate
streams.
Slightly reworked from a patch by Alex Converse (alex converse gmail com)
author | superdump |
---|---|
date | Mon, 06 Oct 2008 16:12:30 +0000 |
parents | 13ee9bb85721 |
children | c7c1e85d14bc |
comparison
equal
deleted
inserted
replaced
8003:777ecd2f8cbe | 8004:8fd8f23be794 |
---|---|
965 if (coup->type[c] == TYPE_CPE) { | 965 if (coup->type[c] == TYPE_CPE) { |
966 coup->ch_select[c] = get_bits(gb, 2); | 966 coup->ch_select[c] = get_bits(gb, 2); |
967 if (coup->ch_select[c] == 3) | 967 if (coup->ch_select[c] == 3) |
968 num_gain++; | 968 num_gain++; |
969 } else | 969 } else |
970 coup->ch_select[c] = 1; | 970 coup->ch_select[c] = 2; |
971 } | 971 } |
972 coup->coupling_point += get_bits1(gb); | 972 coup->coupling_point += get_bits1(gb); |
973 | 973 |
974 if (coup->coupling_point == 2) { | 974 if (coup->coupling_point == 2) { |
975 av_log(ac->avccontext, AV_LOG_ERROR, | 975 av_log(ac->avccontext, AV_LOG_ERROR, |
990 int gain = 0; | 990 int gain = 0; |
991 float gain_cache = 1.; | 991 float gain_cache = 1.; |
992 if (c) { | 992 if (c) { |
993 cge = coup->coupling_point == AFTER_IMDCT ? 1 : get_bits1(gb); | 993 cge = coup->coupling_point == AFTER_IMDCT ? 1 : get_bits1(gb); |
994 gain = cge ? get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60: 0; | 994 gain = cge ? get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60: 0; |
995 gain_cache = pow(scale, gain); | 995 gain_cache = pow(scale, -gain); |
996 } | 996 } |
997 for (g = 0; g < sce->ics.num_window_groups; g++) { | 997 for (g = 0; g < sce->ics.num_window_groups; g++) { |
998 for (sfb = 0; sfb < sce->ics.max_sfb; sfb++, idx++) { | 998 for (sfb = 0; sfb < sce->ics.max_sfb; sfb++, idx++) { |
999 if (sce->band_type[idx] != ZERO_BT) { | 999 if (sce->band_type[idx] != ZERO_BT) { |
1000 if (!cge) { | 1000 if (!cge) { |
1001 int t = get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; | 1001 int t = get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; |
1002 if (t) { | 1002 if (t) { |
1003 int s = 1; | 1003 int s = 1; |
1004 t = gain += t; | |
1004 if (sign) { | 1005 if (sign) { |
1005 s -= 2 * (t & 0x1); | 1006 s -= 2 * (t & 0x1); |
1006 t >>= 1; | 1007 t >>= 1; |
1007 } | 1008 } |
1008 gain += t; | 1009 gain_cache = pow(scale, -t) * s; |
1009 gain_cache = pow(scale, gain) * s; | |
1010 } | 1010 } |
1011 } | 1011 } |
1012 coup->gain[c][idx] = gain_cache; | 1012 coup->gain[c][idx] = gain_cache; |
1013 } | 1013 } |
1014 } | 1014 } |
1290 * | 1290 * |
1291 * @param index index into coupling gain array | 1291 * @param index index into coupling gain array |
1292 * @param apply_coupling_method pointer to (in)dependent coupling function | 1292 * @param apply_coupling_method pointer to (in)dependent coupling function |
1293 */ | 1293 */ |
1294 static void apply_channel_coupling(AACContext * ac, ChannelElement * cc, | 1294 static void apply_channel_coupling(AACContext * ac, ChannelElement * cc, |
1295 enum RawDataBlockType type, int elem_id, enum CouplingPoint coupling_point, | |
1295 void (*apply_coupling_method)(AACContext * ac, SingleChannelElement * sce, ChannelElement * cc, int index)) | 1296 void (*apply_coupling_method)(AACContext * ac, SingleChannelElement * sce, ChannelElement * cc, int index)) |
1296 { | 1297 { |
1297 int c; | 1298 int i, c; |
1298 int index = 0; | 1299 |
1299 ChannelCoupling * coup = &cc->coup; | 1300 for (i = 0; i < MAX_ELEM_ID; i++) { |
1300 for (c = 0; c <= coup->num_coupled; c++) { | 1301 ChannelElement *cce = ac->che[TYPE_CCE][i]; |
1301 if (ac->che[coup->type[c]][coup->id_select[c]]) { | 1302 int index = 0; |
1302 if (coup->ch_select[c] != 2) { | 1303 |
1303 apply_coupling_method(ac, &ac->che[coup->type[c]][coup->id_select[c]]->ch[0], cc, index); | 1304 if (cce && cce->coup.coupling_point == coupling_point) { |
1304 if (coup->ch_select[c] != 0) | 1305 ChannelCoupling * coup = &cce->coup; |
1305 index++; | 1306 |
1306 } | 1307 for (c = 0; c <= coup->num_coupled; c++) { |
1307 if (coup->ch_select[c] != 1) | 1308 if (coup->type[c] == type && coup->id_select[c] == elem_id) { |
1308 apply_coupling_method(ac, &ac->che[coup->type[c]][coup->id_select[c]]->ch[1], cc, index++); | 1309 if (coup->ch_select[c] != 1) { |
1309 } else { | 1310 apply_coupling_method(ac, &cc->ch[0], cce, index); |
1310 av_log(ac->avccontext, AV_LOG_ERROR, | 1311 if (coup->ch_select[c] != 0) |
1311 "coupling target %sE[%d] not available\n", | 1312 index++; |
1312 coup->type[c] == TYPE_CPE ? "CP" : "SC", coup->id_select[c]); | 1313 } |
1313 break; | 1314 if (coup->ch_select[c] != 2) |
1315 apply_coupling_method(ac, &cc->ch[1], cce, index++); | |
1316 } else | |
1317 index += 1 + (coup->ch_select[c] == 3); | |
1318 } | |
1314 } | 1319 } |
1315 } | 1320 } |
1316 } | 1321 } |
1317 | 1322 |
1318 /** | 1323 /** |
1319 * Convert spectral data to float samples, applying all supported tools as appropriate. | 1324 * Convert spectral data to float samples, applying all supported tools as appropriate. |
1320 */ | 1325 */ |
1321 static void spectral_to_sample(AACContext * ac) { | 1326 static void spectral_to_sample(AACContext * ac) { |
1322 int i, type; | 1327 int i, type; |
1323 for (i = 0; i < MAX_ELEM_ID; i++) { | 1328 for(type = 3; type >= 0; type--) { |
1324 for(type = 0; type < 4; type++) { | 1329 for (i = 0; i < MAX_ELEM_ID; i++) { |
1325 ChannelElement *che = ac->che[type][i]; | 1330 ChannelElement *che = ac->che[type][i]; |
1326 if(che) { | 1331 if(che) { |
1327 if(che->coup.coupling_point == BEFORE_TNS) | 1332 if(type <= TYPE_CPE) |
1328 apply_channel_coupling(ac, che, apply_dependent_coupling); | 1333 apply_channel_coupling(ac, che, type, i, BEFORE_TNS, apply_dependent_coupling); |
1329 if(che->ch[0].tns.present) | 1334 if(che->ch[0].tns.present) |
1330 apply_tns(che->ch[0].coeffs, &che->ch[0].tns, &che->ch[0].ics, 1); | 1335 apply_tns(che->ch[0].coeffs, &che->ch[0].tns, &che->ch[0].ics, 1); |
1331 if(che->ch[1].tns.present) | 1336 if(che->ch[1].tns.present) |
1332 apply_tns(che->ch[1].coeffs, &che->ch[1].tns, &che->ch[1].ics, 1); | 1337 apply_tns(che->ch[1].coeffs, &che->ch[1].tns, &che->ch[1].ics, 1); |
1333 if(che->coup.coupling_point == BETWEEN_TNS_AND_IMDCT) | 1338 if(type <= TYPE_CPE) |
1334 apply_channel_coupling(ac, che, apply_dependent_coupling); | 1339 apply_channel_coupling(ac, che, type, i, BETWEEN_TNS_AND_IMDCT, apply_dependent_coupling); |
1335 imdct_and_windowing(ac, &che->ch[0]); | 1340 if(type != TYPE_CCE || che->coup.coupling_point == AFTER_IMDCT) |
1341 imdct_and_windowing(ac, &che->ch[0]); | |
1336 if(type == TYPE_CPE) | 1342 if(type == TYPE_CPE) |
1337 imdct_and_windowing(ac, &che->ch[1]); | 1343 imdct_and_windowing(ac, &che->ch[1]); |
1338 if(che->coup.coupling_point == AFTER_IMDCT) | 1344 if(type <= TYPE_CCE) |
1339 apply_channel_coupling(ac, che, apply_independent_coupling); | 1345 apply_channel_coupling(ac, che, type, i, AFTER_IMDCT, apply_independent_coupling); |
1340 } | 1346 } |
1341 } | 1347 } |
1342 } | 1348 } |
1343 } | 1349 } |
1344 | 1350 |