changeset 11435:4dfd0bfbb8dc libavcodec

aacsbr: Merge sbr_time_freq_grid into read_sbr_grid (and into copy_sbr_grid).
author alexc
date Tue, 09 Mar 2010 10:26:25 +0000
parents c969ceeffb36
children d90f6c676063
files aacsbr.c
diffstat 1 files changed, 66 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
--- a/aacsbr.c	Tue Mar 09 10:25:42 2010 +0000
+++ b/aacsbr.c	Tue Mar 09 10:26:25 2010 +0000
@@ -698,8 +698,71 @@
         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);
+        return -1;
+    }
+
+    ch_data->t_env_num_env_old = ch_data->t_env[ch_data->bs_num_env[0]];
+    ch_data->t_env[0]                      = abs_bord_lead;
+    ch_data->t_env[ch_data->bs_num_env[1]] = abs_bord_trail;
+
+    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++)
+            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];
+    } else { // FIXVAR
+        for (i = 0; i < n_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--)
+            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];
+    } else { // FIXFIX or VARFIX
+        for (i = n_rel_lead; i < ch_data->bs_num_env[1]; i++)
+            ch_data->t_env[i + 1] = abs_bord_trail;
+    }
+
     ch_data->bs_num_noise = (ch_data->bs_num_env[1] > 1) + 1;
 
+    ch_data->t_q[0] = ch_data->t_env[0];
+    if (ch_data->bs_num_noise > 1) { // typo in spec bases this on bs_num_env...
+        unsigned int idx;
+        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);
+        } else { // VARFIX
+            if (!ch_data->bs_pointer)
+                idx = 1;
+            else if (ch_data->bs_pointer == 1)
+                idx = ch_data->bs_num_env[1] - 1;
+            else // bs_pointer > 1
+                idx = ch_data->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]];
+    } else
+        ch_data->t_q[1] = ch_data->t_env[ch_data->bs_num_env[1]];
+
     return 0;
 }
 
@@ -707,6 +770,7 @@
     //These variables are saved from the previous frame rather than copied
     dst->bs_freq_res[0] = dst->bs_freq_res[dst->bs_num_env[1]];
     dst->bs_num_env[0]  = dst->bs_num_env[1];
+    dst->t_env_num_env_old = dst->t_env[dst->bs_num_env[0]];
 
     //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));
@@ -714,6 +778,8 @@
     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;
@@ -1030,77 +1096,6 @@
     return cnt;
 }
 
-/// Time/frequency Grid (14496-3 sp04 p200)
-static int sbr_time_freq_grid(AACContext *ac, SpectralBandReplication *sbr,
-                              SBRData *ch_data, int ch)
-{
-    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;
-    int i;
-
-    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);
-        return -1;
-    }
-
-    ch_data->t_env_num_env_old = ch_data->t_env[ch_data->bs_num_env[0]];
-    ch_data->t_env[0]                      = abs_bord_lead;
-    ch_data->t_env[ch_data->bs_num_env[1]] = abs_bord_trail;
-
-    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++)
-            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];
-    } else { // FIXVAR
-        for (i = 0; i < n_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--)
-            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];
-    } else { // FIXFIX or VARFIX
-        for (i = n_rel_lead; i < ch_data->bs_num_env[1]; i++)
-            ch_data->t_env[i + 1] = abs_bord_trail;
-    }
-
-    ch_data->t_q[0] = ch_data->t_env[0];
-    if (ch_data->bs_num_noise > 1) { // typo in spec bases this on bs_num_env...
-        unsigned int idx;
-        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);
-        } else { // VARFIX
-            if (!ch_data->bs_pointer)
-                idx = 1;
-            else if (ch_data->bs_pointer == 1)
-                idx = ch_data->bs_num_env[1] - 1;
-            else // bs_pointer > 1
-                idx = ch_data->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]];
-    } else
-        ch_data->t_q[1] = ch_data->t_env[ch_data->bs_num_env[1]];
-
-    return 0;
-}
-
 /// Dequantization and stereo decoding (14496-3 sp04 p203)
 static void sbr_dequant(SpectralBandReplication *sbr, int id_aac)
 {
@@ -1738,12 +1733,7 @@
 
 void ff_sbr_dequant(AACContext *ac, SpectralBandReplication *sbr, int id_aac)
 {
-    int ch;
-
     if (sbr->start) {
-        for (ch = 0; ch < (id_aac == TYPE_CPE) + 1; ch++) {
-            sbr_time_freq_grid(ac, sbr, &sbr->data[ch], ch);
-        }
         sbr_dequant(sbr, id_aac);
     }
 }