Mercurial > libavcodec.hg
changeset 11437:8b2d9e680000 libavcodec
aacsbr: Cleanup the newly merged read_sbr_grid, eliminating several context
and some duplicate local variables.
author | alexc |
---|---|
date | Tue, 09 Mar 2010 10:27:35 +0000 |
parents | d90f6c676063 |
children | db5623d197a3 |
files | aacsbr.c sbr.h |
diffstat | 2 files changed, 48 insertions(+), 65 deletions(-) [+] |
line wrap: on
line diff
--- a/aacsbr.c Tue Mar 09 10:26:54 2010 +0000 +++ b/aacsbr.c Tue Mar 09 10:27:35 2010 +0000 @@ -617,6 +617,12 @@ GetBitContext *gb, SBRData *ch_data) { int i; + unsigned bs_pointer; + int abs_bord_lead = 0; + // frameLengthFlag ? 15 : 16; 960 sample length frames unsupported; this value is numTimeSlots + int abs_bord_trail = 16; + int num_rel_lead, num_rel_trail; + uint8_t bs_rel_bord[2][3]; ch_data->bs_freq_res[0] = ch_data->bs_freq_res[ch_data->bs_num_env[1]]; ch_data->bs_num_env[0] = ch_data->bs_num_env[1]; @@ -625,6 +631,7 @@ switch (ch_data->bs_frame_class = get_bits(gb, 2)) { case FIXFIX: ch_data->bs_num_env[1] = 1 << get_bits(gb, 2); + num_rel_lead = ch_data->bs_num_env[1] - 1; if (ch_data->bs_num_env[1] == 1) ch_data->bs_amp_res = 0; @@ -635,43 +642,44 @@ return -1; } - ch_data->bs_pointer = 0; + bs_pointer = 0; ch_data->bs_freq_res[1] = get_bits1(gb); for (i = 1; i < ch_data->bs_num_env[1]; i++) ch_data->bs_freq_res[i + 1] = ch_data->bs_freq_res[1]; break; case FIXVAR: - ch_data->bs_var_bord[1] = get_bits(gb, 2); - ch_data->bs_num_rel[1] = get_bits(gb, 2); - ch_data->bs_num_env[1] = ch_data->bs_num_rel[1] + 1; + abs_bord_trail += get_bits(gb, 2); + num_rel_trail = get_bits(gb, 2); + num_rel_lead = 0; + ch_data->bs_num_env[1] = num_rel_trail + 1; - for (i = 0; i < ch_data->bs_num_rel[1]; i++) - ch_data->bs_rel_bord[1][i] = 2 * get_bits(gb, 2) + 2; + for (i = 0; i < num_rel_trail; i++) + bs_rel_bord[1][i] = 2 * get_bits(gb, 2) + 2; - ch_data->bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env[1]]); + bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env[1]]); for (i = 0; i < ch_data->bs_num_env[1]; i++) ch_data->bs_freq_res[ch_data->bs_num_env[1] - i] = get_bits1(gb); break; case VARFIX: - ch_data->bs_var_bord[0] = get_bits(gb, 2); - ch_data->bs_num_rel[0] = get_bits(gb, 2); - ch_data->bs_num_env[1] = ch_data->bs_num_rel[0] + 1; + abs_bord_lead = get_bits(gb, 2); + num_rel_lead = get_bits(gb, 2); + ch_data->bs_num_env[1] = num_rel_lead + 1; - for (i = 0; i < ch_data->bs_num_rel[0]; i++) - ch_data->bs_rel_bord[0][i] = 2 * get_bits(gb, 2) + 2; + for (i = 0; i < num_rel_lead; i++) + bs_rel_bord[0][i] = 2 * get_bits(gb, 2) + 2; - ch_data->bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env[1]]); + bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env[1]]); get_bits1_vector(gb, ch_data->bs_freq_res + 1, ch_data->bs_num_env[1]); break; case VARVAR: - ch_data->bs_var_bord[0] = get_bits(gb, 2); - ch_data->bs_var_bord[1] = get_bits(gb, 2); - ch_data->bs_num_rel[0] = get_bits(gb, 2); - ch_data->bs_num_rel[1] = get_bits(gb, 2); - ch_data->bs_num_env[1] = ch_data->bs_num_rel[0] + ch_data->bs_num_rel[1] + 1; + abs_bord_lead = get_bits(gb, 2); + abs_bord_trail += get_bits(gb, 2); + num_rel_lead = get_bits(gb, 2); + num_rel_trail = get_bits(gb, 2); + ch_data->bs_num_env[1] = num_rel_lead + num_rel_trail + 1; if (ch_data->bs_num_env[1] > 5) { av_log(ac->avccontext, AV_LOG_ERROR, @@ -680,38 +688,21 @@ return -1; } - for (i = 0; i < ch_data->bs_num_rel[0]; i++) - ch_data->bs_rel_bord[0][i] = 2 * get_bits(gb, 2) + 2; - for (i = 0; i < ch_data->bs_num_rel[1]; i++) - ch_data->bs_rel_bord[1][i] = 2 * get_bits(gb, 2) + 2; + for (i = 0; i < num_rel_lead; i++) + bs_rel_bord[0][i] = 2 * get_bits(gb, 2) + 2; + for (i = 0; i < num_rel_trail; i++) + bs_rel_bord[1][i] = 2 * get_bits(gb, 2) + 2; - ch_data->bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env[1]]); + bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env[1]]); get_bits1_vector(gb, ch_data->bs_freq_res + 1, ch_data->bs_num_env[1]); break; } - if (ch_data->bs_pointer > ch_data->bs_num_env[1] + 1) { + if (bs_pointer > ch_data->bs_num_env[1] + 1) { av_log(ac->avccontext, AV_LOG_ERROR, "Invalid bitstream, bs_pointer points to a middle noise border outside the time borders table: %d\n", - ch_data->bs_pointer); - return -1; - } - - int abs_bord_lead = ch_data->bs_frame_class >= 2 ? ch_data->bs_var_bord[0] : 0; - // frameLengthFlag ? 15 : 16; 960 sample length frames unsupported; this value is numTimeSlots - int abs_bord_trail = (ch_data->bs_frame_class & 1 ? ch_data->bs_var_bord[1] : 0) + 16; - int n_rel_lead; - - if (ch_data->bs_frame_class == FIXFIX) { - n_rel_lead = ch_data->bs_num_env[1] - 1; - } else if (ch_data->bs_frame_class == FIXVAR) { - n_rel_lead = 0; - } else if (ch_data->bs_frame_class < 4) { // VARFIX or VARVAR - n_rel_lead = ch_data->bs_num_rel[0]; - } else { - av_log(ac->avccontext, AV_LOG_ERROR, - "Invalid bs_frame_class for SBR: %d\n", ch_data->bs_frame_class); + bs_pointer); return -1; } @@ -722,22 +713,22 @@ if (ch_data->bs_frame_class == FIXFIX) { int temp = (abs_bord_trail + (ch_data->bs_num_env[1] >> 1)) / ch_data->bs_num_env[1]; - for (i = 0; i < n_rel_lead; i++) + for (i = 0; i < num_rel_lead; i++) ch_data->t_env[i + 1] = ch_data->t_env[i] + temp; } else if (ch_data->bs_frame_class > 1) { // VARFIX or VARVAR - for (i = 0; i < n_rel_lead; i++) - ch_data->t_env[i + 1] = ch_data->t_env[i] + ch_data->bs_rel_bord[0][i]; + for (i = 0; i < num_rel_lead; i++) + ch_data->t_env[i + 1] = ch_data->t_env[i] + bs_rel_bord[0][i]; } else { // FIXVAR - for (i = 0; i < n_rel_lead; i++) + for (i = 0; i < num_rel_lead; i++) ch_data->t_env[i + 1] = abs_bord_lead; } if (ch_data->bs_frame_class & 1) { // FIXVAR or VARVAR - for (i = ch_data->bs_num_env[1] - 1; i > n_rel_lead; i--) + for (i = ch_data->bs_num_env[1] - 1; i > num_rel_lead; i--) ch_data->t_env[i] = ch_data->t_env[i + 1] - - ch_data->bs_rel_bord[1][ch_data->bs_num_env[1] - 1 - i]; + bs_rel_bord[1][ch_data->bs_num_env[1] - 1 - i]; } else { // FIXFIX or VARFIX - for (i = n_rel_lead; i < ch_data->bs_num_env[1]; i++) + for (i = num_rel_lead; i < ch_data->bs_num_env[1]; i++) ch_data->t_env[i + 1] = abs_bord_trail; } @@ -749,14 +740,14 @@ if (ch_data->bs_frame_class == FIXFIX) { idx = ch_data->bs_num_env[1] >> 1; } else if (ch_data->bs_frame_class & 1) { // FIXVAR or VARVAR - idx = ch_data->bs_num_env[1] - FFMAX(ch_data->bs_pointer - 1, 1); + idx = ch_data->bs_num_env[1] - FFMAX(bs_pointer - 1, 1); } else { // VARFIX - if (!ch_data->bs_pointer) + if (!bs_pointer) idx = 1; - else if (ch_data->bs_pointer == 1) + else if (bs_pointer == 1) idx = ch_data->bs_num_env[1] - 1; else // bs_pointer > 1 - idx = ch_data->bs_pointer - 1; + idx = bs_pointer - 1; } ch_data->t_q[1] = ch_data->t_env[idx]; ch_data->t_q[2] = ch_data->t_env[ch_data->bs_num_env[1]]; @@ -765,10 +756,10 @@ ch_data->e_a[0] = -(ch_data->e_a[1] != ch_data->bs_num_env[0]); // l_APrev ch_data->e_a[1] = -1; - if ((ch_data->bs_frame_class & 1) && ch_data->bs_pointer) { // FIXVAR or VARVAR and bs_pointer != 0 - ch_data->e_a[1] = ch_data->bs_num_env[1] + 1 - ch_data->bs_pointer; - } else if ((ch_data->bs_frame_class == 2) && (ch_data->bs_pointer > 1)) // VARFIX and bs_pointer > 1 - ch_data->e_a[1] = ch_data->bs_pointer - 1; + if ((ch_data->bs_frame_class & 1) && bs_pointer) { // FIXVAR or VARVAR and bs_pointer != 0 + ch_data->e_a[1] = ch_data->bs_num_env[1] + 1 - bs_pointer; + } else if ((ch_data->bs_frame_class == 2) && (bs_pointer > 1)) // VARFIX and bs_pointer > 1 + ch_data->e_a[1] = bs_pointer - 1; return 0; } @@ -783,14 +774,10 @@ //These variables are read from the bitstream and therefore copied memcpy(dst->bs_freq_res+1, src->bs_freq_res+1, sizeof(dst->bs_freq_res)-sizeof(*dst->bs_freq_res)); memcpy(dst->bs_num_env+1, src->bs_num_env+1, sizeof(dst->bs_num_env)- sizeof(*dst->bs_num_env)); - memcpy(dst->bs_var_bord, src->bs_var_bord, sizeof(dst->bs_var_bord)); - memcpy(dst->bs_rel_bord, src->bs_rel_bord, sizeof(dst->bs_rel_bord)); - memcpy(dst->bs_num_rel, src->bs_num_rel, sizeof(dst->bs_rel_bord)); memcpy(dst->t_env, src->t_env, sizeof(dst->t_env)); memcpy(dst->t_q, src->t_q, sizeof(dst->t_q)); dst->bs_amp_res = src->bs_amp_res; dst->bs_num_noise = src->bs_num_noise; - dst->bs_pointer = src->bs_pointer; dst->bs_frame_class = src->bs_frame_class; dst->e_a[1] = src->e_a[1]; }
--- a/sbr.h Tue Mar 09 10:26:54 2010 +0000 +++ b/sbr.h Tue Mar 09 10:27:35 2010 +0000 @@ -64,10 +64,6 @@ unsigned bs_add_harmonic_flag; unsigned bs_num_env[2]; uint8_t bs_freq_res[7]; - uint8_t bs_var_bord[2]; - uint8_t bs_num_rel[2]; - uint8_t bs_rel_bord[2][3]; - unsigned bs_pointer; unsigned bs_num_noise; uint8_t bs_df_env[5]; uint8_t bs_df_noise[2];