[FFmpeg-soc] [soc]: r4164 - amr/amrnbfloatdec.c

kmalaussene subversion at mplayerhq.hu
Wed Mar 4 22:35:32 CET 2009


Author: kmalaussene
Date: Wed Mar  4 22:35:32 2009
New Revision: 4164

Log:
Move smoothing of fixed gain into its own function fixed_gain_smooth.

Modified:
   amr/amrnbfloatdec.c

Modified: amr/amrnbfloatdec.c
==============================================================================
--- amr/amrnbfloatdec.c	Wed Mar  4 21:25:29 2009	(r4163)
+++ amr/amrnbfloatdec.c	Wed Mar  4 22:35:32 2009	(r4164)
@@ -685,6 +685,44 @@ static float fixed_gain_prediction(float
 }
 
 /**
+ * fixed gain smoothing
+ *
+ * @param p the context
+ * @param lsp lsp coefficients for the current subframe
+ * @param lsp_avg averaged lsp coefficients
+ *
+ * @return fixed gain smoothed
+ */
+
+static float fixed_gain_smooth(AMRContext *p , const float *lsp, const float *lsp_avg) {
+    float diff             = 0.0;
+    float smoothing_factor = 0.0;
+    int   i;
+
+    for(i=0; i<LP_FILTER_ORDER; i++) {
+        // calculate diff
+        diff += fabs(lsp_avg[i]-lsp[i])/lsp_avg[i];
+    }
+
+    // if diff has been >0.65 for 10 frames (40 subframes) no smoothing is applied
+    if(diff > 0.65) {
+        p->diff_count++;
+    }else {
+        p->diff_count = 0;
+    }
+
+    if(p->diff_count < 40) {
+        float fixed_gain_mean;
+        // calculate the fixed gain smoothing factor (k_m)
+        smoothing_factor = FFMIN(0.25, FFMAX(0.0, diff - 0.4))/0.25;
+        // calculate the mean fixed gain for the current subframe
+        fixed_gain_mean = (p->fixed_gain[0] + p->fixed_gain[1] + p->fixed_gain[2] + p->fixed_gain[3] + p->fixed_gain[4])/5.0;
+        // calculate the smoothed fixed gain
+        p->fixed_gain[4] = smoothing_factor*p->fixed_gain[4] + (1.0 - smoothing_factor)*fixed_gain_mean;
+    }
+    return p->fixed_gain[4];
+}
+/**
  * Decode fixed and pitch gains.
  *
  * @param p the context
@@ -941,32 +979,8 @@ static int amrnb_decode_frame(AVCodecCon
         }
 
         // smooth fixed gain
-        if(p->cur_frame_mode < MODE_74 || p->cur_frame_mode == MODE_102) {
-            float diff             = 0.0;
-            float smoothing_factor = 0.0;
-
-            for(i=0; i<LP_FILTER_ORDER; i++) {
-                // calculate diff
-                diff += fabs(p->lsp_avg[i]-p->lsp[subframe][i])/p->lsp_avg[i];
-            }
-
-            // if diff has been >0.65 for 10 frames (40 subframes) no smoothing is applied
-            if(diff > 0.65) {
-                p->diff_count++;
-            }else {
-                p->diff_count = 0;
-            }
-
-            if(p->diff_count < 40) {
-                float fixed_gain_mean;
-                // calculate the fixed gain smoothing factor (k_m)
-                smoothing_factor = FFMIN(0.25, FFMAX(0.0, diff - 0.4))/0.25;
-                // calculate the mean fixed gain for the current subframe
-                fixed_gain_mean = (p->fixed_gain[0] + p->fixed_gain[1] + p->fixed_gain[2] + p->fixed_gain[3] + p->fixed_gain[4])/5.0;
-                // calculate the smoothed fixed gain
-                p->fixed_gain[4] = smoothing_factor*p->fixed_gain[4] + (1.0 - smoothing_factor)*fixed_gain_mean;
-            }
-        }
+        if(p->cur_frame_mode < MODE_74 || p->cur_frame_mode == MODE_102)
+            p->fixed_gain[4] = fixed_gain_smooth(p, p->lsp[subframe], p->lsp_avg);
 
         apply_ir_filter(p, p->fixed_vector);
 



More information about the FFmpeg-soc mailing list