[FFmpeg-cvslog] avcodec/aacdec_common: Apply offset for SBR VLCs during init

Andreas Rheinhardt git at videolan.org
Tue Oct 31 23:19:58 EET 2023


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Mon Sep 25 01:33:28 2023 +0200| [7f66d9d6c5bf19388ea889e7bc7edc636c04d091] | committer: Andreas Rheinhardt

avcodec/aacdec_common: Apply offset for SBR VLCs during init

This avoids having to apply it later after every get_vlc2().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7f66d9d6c5bf19388ea889e7bc7edc636c04d091
---

 libavcodec/aacdec_common.c   |  6 +++++-
 libavcodec/aacsbr.h          |  3 ---
 libavcodec/aacsbr_template.c | 26 ++++++--------------------
 3 files changed, 11 insertions(+), 24 deletions(-)

diff --git a/libavcodec/aacdec_common.c b/libavcodec/aacdec_common.c
index 6a592600dc..4af60e8c7c 100644
--- a/libavcodec/aacdec_common.c
+++ b/libavcodec/aacdec_common.c
@@ -269,6 +269,10 @@ static const uint8_t sbr_huffman_nb_codes[] = {
     121, 121, 49, 49, 63, 63, 25, 25, 63, 25
 };
 
+static const int8_t sbr_vlc_offsets[10] = {
+    -60, -60, -24, -24, -31, -31, -12, -12, -31, -12
+};
+
 const VLCElem *ff_aac_sbr_vlc[10];
 
 static av_cold void aacdec_common_init(void)
@@ -305,7 +309,7 @@ static av_cold void aacdec_common_init(void)
             ff_vlc_init_tables_from_lengths(&state, 9, sbr_huffman_nb_codes[i],
                                             &tab[0][1], 2,
                                             &tab[0][0], 2, 1,
-                                            0, 0);
+                                            sbr_vlc_offsets[i], 0);
         tab += sbr_huffman_nb_codes[i];
     }
 }
diff --git a/libavcodec/aacsbr.h b/libavcodec/aacsbr.h
index 0d182f822c..3a19fe1c7e 100644
--- a/libavcodec/aacsbr.h
+++ b/libavcodec/aacsbr.h
@@ -66,9 +66,6 @@ enum {
     EXTENSION_ID_PS = 2,
 };
 
-static const int8_t vlc_sbr_lav[10] =
-    { 60, 60, 24, 24, 31, 31, 12, 12, 31, 12 };
-
 /** Initialize SBR. */
 void AAC_RENAME(ff_aac_sbr_init)(void);
 /** Initialize one SBR context. */
diff --git a/libavcodec/aacsbr_template.c b/libavcodec/aacsbr_template.c
index a82be8a8d5..98e9fd8fed 100644
--- a/libavcodec/aacsbr_template.c
+++ b/libavcodec/aacsbr_template.c
@@ -804,7 +804,6 @@ static int read_sbr_envelope(AACContext *ac, SpectralBandReplication *sbr, GetBi
     int bits;
     int i, j, k;
     const VLCElem *t_huff, *f_huff;
-    int t_lav, f_lav;
     const int delta = (ch == 1 && sbr->bs_coupling == 1) + 1;
     const int odd = sbr->n[1] & 1;
 
@@ -812,29 +811,21 @@ static int read_sbr_envelope(AACContext *ac, SpectralBandReplication *sbr, GetBi
         if (ch_data->bs_amp_res) {
             bits   = 5;
             t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_BAL_3_0DB];
-            t_lav  = vlc_sbr_lav[T_HUFFMAN_ENV_BAL_3_0DB];
             f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_BAL_3_0DB];
-            f_lav  = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_3_0DB];
         } else {
             bits   = 6;
             t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_BAL_1_5DB];
-            t_lav  = vlc_sbr_lav[T_HUFFMAN_ENV_BAL_1_5DB];
             f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_BAL_1_5DB];
-            f_lav  = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_1_5DB];
         }
     } else {
         if (ch_data->bs_amp_res) {
             bits   = 6;
             t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_3_0DB];
-            t_lav  = vlc_sbr_lav[T_HUFFMAN_ENV_3_0DB];
             f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_3_0DB];
-            f_lav  = vlc_sbr_lav[F_HUFFMAN_ENV_3_0DB];
         } else {
             bits   = 7;
             t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_1_5DB];
-            t_lav  = vlc_sbr_lav[T_HUFFMAN_ENV_1_5DB];
             f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_1_5DB];
-            f_lav  = vlc_sbr_lav[F_HUFFMAN_ENV_1_5DB];
         }
     }
 
@@ -843,7 +834,7 @@ static int read_sbr_envelope(AACContext *ac, SpectralBandReplication *sbr, GetBi
             // bs_freq_res[0] == bs_freq_res[bs_num_env] from prev frame
             if (ch_data->bs_freq_res[i + 1] == ch_data->bs_freq_res[i]) {
                 for (j = 0; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) {
-                    ch_data->env_facs_q[i + 1][j] = ch_data->env_facs_q[i][j] + delta * (get_vlc2(gb, t_huff, 9, 3) - t_lav);
+                    ch_data->env_facs_q[i + 1][j] = ch_data->env_facs_q[i][j] + delta * get_vlc2(gb, t_huff, 9, 3);
                     if (ch_data->env_facs_q[i + 1][j] > 127U) {
                         av_log(ac->avctx, AV_LOG_ERROR, "env_facs_q %d is invalid\n", ch_data->env_facs_q[i + 1][j]);
                         return AVERROR_INVALIDDATA;
@@ -852,7 +843,7 @@ static int read_sbr_envelope(AACContext *ac, SpectralBandReplication *sbr, GetBi
             } else if (ch_data->bs_freq_res[i + 1]) {
                 for (j = 0; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) {
                     k = (j + odd) >> 1; // find k such that f_tablelow[k] <= f_tablehigh[j] < f_tablelow[k + 1]
-                    ch_data->env_facs_q[i + 1][j] = ch_data->env_facs_q[i][k] + delta * (get_vlc2(gb, t_huff, 9, 3) - t_lav);
+                    ch_data->env_facs_q[i + 1][j] = ch_data->env_facs_q[i][k] + delta * get_vlc2(gb, t_huff, 9, 3);
                     if (ch_data->env_facs_q[i + 1][j] > 127U) {
                         av_log(ac->avctx, AV_LOG_ERROR, "env_facs_q %d is invalid\n", ch_data->env_facs_q[i + 1][j]);
                         return AVERROR_INVALIDDATA;
@@ -861,7 +852,7 @@ static int read_sbr_envelope(AACContext *ac, SpectralBandReplication *sbr, GetBi
             } else {
                 for (j = 0; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) {
                     k = j ? 2*j - odd : 0; // find k such that f_tablehigh[k] == f_tablelow[j]
-                    ch_data->env_facs_q[i + 1][j] = ch_data->env_facs_q[i][k] + delta * (get_vlc2(gb, t_huff, 9, 3) - t_lav);
+                    ch_data->env_facs_q[i + 1][j] = ch_data->env_facs_q[i][k] + delta * get_vlc2(gb, t_huff, 9, 3);
                     if (ch_data->env_facs_q[i + 1][j] > 127U) {
                         av_log(ac->avctx, AV_LOG_ERROR, "env_facs_q %d is invalid\n", ch_data->env_facs_q[i + 1][j]);
                         return AVERROR_INVALIDDATA;
@@ -871,7 +862,7 @@ static int read_sbr_envelope(AACContext *ac, SpectralBandReplication *sbr, GetBi
         } else {
             ch_data->env_facs_q[i + 1][0] = delta * get_bits(gb, bits); // bs_env_start_value_balance
             for (j = 1; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) {
-                ch_data->env_facs_q[i + 1][j] = ch_data->env_facs_q[i + 1][j - 1] + delta * (get_vlc2(gb, f_huff, 9, 3) - f_lav);
+                ch_data->env_facs_q[i + 1][j] = ch_data->env_facs_q[i + 1][j - 1] + delta * get_vlc2(gb, f_huff, 9, 3);
                 if (ch_data->env_facs_q[i + 1][j] > 127U) {
                     av_log(ac->avctx, AV_LOG_ERROR, "env_facs_q %d is invalid\n", ch_data->env_facs_q[i + 1][j]);
                     return AVERROR_INVALIDDATA;
@@ -892,25 +883,20 @@ static int read_sbr_noise(AACContext *ac, SpectralBandReplication *sbr, GetBitCo
 {
     int i, j;
     const VLCElem *t_huff, *f_huff;
-    int t_lav, f_lav;
     int delta = (ch == 1 && sbr->bs_coupling == 1) + 1;
 
     if (sbr->bs_coupling && ch) {
         t_huff = ff_aac_sbr_vlc[T_HUFFMAN_NOISE_BAL_3_0DB];
-        t_lav  = vlc_sbr_lav[T_HUFFMAN_NOISE_BAL_3_0DB];
         f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_BAL_3_0DB];
-        f_lav  = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_3_0DB];
     } else {
         t_huff = ff_aac_sbr_vlc[T_HUFFMAN_NOISE_3_0DB];
-        t_lav  = vlc_sbr_lav[T_HUFFMAN_NOISE_3_0DB];
         f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_3_0DB];
-        f_lav  = vlc_sbr_lav[F_HUFFMAN_ENV_3_0DB];
     }
 
     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_q[i + 1][j] = ch_data->noise_facs_q[i][j] + 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);
                 if (ch_data->noise_facs_q[i + 1][j] > 30U) {
                     av_log(ac->avctx, AV_LOG_ERROR, "noise_facs_q %d is invalid\n", ch_data->noise_facs_q[i + 1][j]);
                     return AVERROR_INVALIDDATA;
@@ -919,7 +905,7 @@ static int read_sbr_noise(AACContext *ac, SpectralBandReplication *sbr, GetBitCo
         } else {
             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_q[i + 1][j] = ch_data->noise_facs_q[i + 1][j - 1] + 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);
                 if (ch_data->noise_facs_q[i + 1][j] > 30U) {
                     av_log(ac->avctx, AV_LOG_ERROR, "noise_facs_q %d is invalid\n", ch_data->noise_facs_q[i + 1][j]);
                     return AVERROR_INVALIDDATA;



More information about the ffmpeg-cvslog mailing list