From bfd0e02dd64e912a6b67c25d9f86b3b0b849ad10 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Thu, 19 Nov 2015 12:03:22 +0100 Subject: [PATCH] avcodec/aacsbr: Split pre dequantization noise factors table This allows removing a special case for the fixed point decoder and will make error checks simpler Signed-off-by: Michael Niedermayer --- libavcodec/aacsbr.c | 6 +++--- libavcodec/aacsbr_fixed.c | 6 +++--- libavcodec/aacsbr_template.c | 25 ++++++------------------- libavcodec/sbr.h | 2 ++ 4 files changed, 14 insertions(+), 25 deletions(-) diff --git a/libavcodec/aacsbr.c b/libavcodec/aacsbr.c index 81f1902822..7fb21cc3fb 100644 --- a/libavcodec/aacsbr.c +++ b/libavcodec/aacsbr.c @@ -93,8 +93,8 @@ static void sbr_dequant(SpectralBandReplication *sbr, int id_aac) } for (e = 1; e <= sbr->data[0].bs_num_noise; e++) { for (k = 0; k < sbr->n_q; k++) { - float temp1 = exp2f(NOISE_FLOOR_OFFSET - sbr->data[0].noise_facs[e][k] + 1); - float temp2 = exp2f(12 - sbr->data[1].noise_facs[e][k]); + float temp1 = exp2f(NOISE_FLOOR_OFFSET - sbr->data[0].noise_facs_q[e][k] + 1); + float temp2 = exp2f(12 - sbr->data[1].noise_facs_q[e][k]); float fac; if (temp1 > 1E20) { av_log(NULL, AV_LOG_ERROR, "envelope scalefactor overflow in dequant\n"); @@ -121,7 +121,7 @@ static void sbr_dequant(SpectralBandReplication *sbr, int id_aac) for (e = 1; e <= sbr->data[ch].bs_num_noise; e++) for (k = 0; k < sbr->n_q; k++) sbr->data[ch].noise_facs[e][k] = - exp2f(NOISE_FLOOR_OFFSET - sbr->data[ch].noise_facs[e][k]); + exp2f(NOISE_FLOOR_OFFSET - sbr->data[ch].noise_facs_q[e][k]); } } } diff --git a/libavcodec/aacsbr_fixed.c b/libavcodec/aacsbr_fixed.c index b4e3ac7f76..6ec39c14e4 100644 --- a/libavcodec/aacsbr_fixed.c +++ b/libavcodec/aacsbr_fixed.c @@ -190,13 +190,13 @@ static void sbr_dequant(SpectralBandReplication *sbr, int id_aac) SoftFloat temp1, temp2, fac; temp1.exp = NOISE_FLOOR_OFFSET - \ - sbr->data[0].noise_facs[e][k].mant + 2; + sbr->data[0].noise_facs_q[e][k] + 2; temp1.mant = 0x20000000; if (temp1.exp > 66) { // temp1 > 1E20 av_log(NULL, AV_LOG_ERROR, "envelope scalefactor overflow in dequant\n"); temp1 = FLOAT_1; } - temp2.exp = 12 - sbr->data[1].noise_facs[e][k].mant + 1; + temp2.exp = 12 - sbr->data[1].noise_facs_q[e][k] + 1; temp2.mant = 0x20000000; fac = av_div_sf(temp1, av_add_sf(FLOAT_1, temp2)); sbr->data[0].noise_facs[e][k] = fac; @@ -225,7 +225,7 @@ static void sbr_dequant(SpectralBandReplication *sbr, int id_aac) for (e = 1; e <= sbr->data[ch].bs_num_noise; e++) for (k = 0; k < sbr->n_q; k++){ sbr->data[ch].noise_facs[e][k].exp = NOISE_FLOOR_OFFSET - \ - sbr->data[ch].noise_facs[e][k].mant + 1; + sbr->data[ch].noise_facs_q[e][k] + 1; sbr->data[ch].noise_facs[e][k].mant = 0x20000000; } } diff --git a/libavcodec/aacsbr_template.c b/libavcodec/aacsbr_template.c index 66f415912c..906823ab72 100644 --- a/libavcodec/aacsbr_template.c +++ b/libavcodec/aacsbr_template.c @@ -906,33 +906,20 @@ static void read_sbr_noise(SpectralBandReplication *sbr, GetBitContext *gb, f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_3_0DB]; } -#if USE_FIXED for (i = 0; i < ch_data->bs_num_noise; i++) { if (ch_data->bs_df_noise[i]) { for (j = 0; j < sbr->n_q; j++) - ch_data->noise_facs[i + 1][j].mant = ch_data->noise_facs[i][j].mant + delta * (get_vlc2(gb, t_huff, 9, 2) - t_lav); + ch_data->noise_facs_q[i + 1][j] = ch_data->noise_facs_q[i][j] + delta * (get_vlc2(gb, t_huff, 9, 2) - t_lav); } else { - ch_data->noise_facs[i + 1][0].mant = delta * get_bits(gb, 5); // bs_noise_start_value_balance or bs_noise_start_value_level + ch_data->noise_facs_q[i + 1][0] = delta * get_bits(gb, 5); // bs_noise_start_value_balance or bs_noise_start_value_level for (j = 1; j < sbr->n_q; j++) - ch_data->noise_facs[i + 1][j].mant = ch_data->noise_facs[i + 1][j - 1].mant + delta * (get_vlc2(gb, f_huff, 9, 3) - f_lav); + ch_data->noise_facs_q[i + 1][j] = ch_data->noise_facs_q[i + 1][j - 1] + delta * (get_vlc2(gb, f_huff, 9, 3) - f_lav); } } -#else - for (i = 0; i < ch_data->bs_num_noise; i++) { - if (ch_data->bs_df_noise[i]) { - for (j = 0; j < sbr->n_q; j++) - ch_data->noise_facs[i + 1][j] = ch_data->noise_facs[i][j] + delta * (get_vlc2(gb, t_huff, 9, 2) - t_lav); - } else { - ch_data->noise_facs[i + 1][0] = delta * get_bits(gb, 5); // bs_noise_start_value_balance or bs_noise_start_value_level - for (j = 1; j < sbr->n_q; j++) - ch_data->noise_facs[i + 1][j] = ch_data->noise_facs[i + 1][j - 1] + delta * (get_vlc2(gb, f_huff, 9, 3) - f_lav); - } - } -#endif /* USE_FIXED */ - //assign 0th elements of noise_facs from last elements - memcpy(ch_data->noise_facs[0], ch_data->noise_facs[ch_data->bs_num_noise], - sizeof(ch_data->noise_facs[0])); + //assign 0th elements of noise_facs_q from last elements + memcpy(ch_data->noise_facs_q[0], ch_data->noise_facs_q[ch_data->bs_num_noise], + sizeof(ch_data->noise_facs_q[0])); } static void read_sbr_extension(AACContext *ac, SpectralBandReplication *sbr, diff --git a/libavcodec/sbr.h b/libavcodec/sbr.h index 66a88a2898..f22c47501b 100644 --- a/libavcodec/sbr.h +++ b/libavcodec/sbr.h @@ -96,8 +96,10 @@ typedef struct SBRData { AAC_FLOAT q_temp[42][48]; uint8_t s_indexmapped[8][48]; ///Envelope scalefactors + uint8_t env_facs_q[6][48]; AAC_FLOAT env_facs[6][48]; ///Noise scalefactors + uint8_t noise_facs_q[6][48]; AAC_FLOAT noise_facs[3][5]; ///Envelope time borders uint8_t t_env[8];