[SCM] libav/experimental: Implement AMR gain function that is used by both AMR and SIPR.

siretart at users.alioth.debian.org siretart at users.alioth.debian.org
Sun Jun 30 16:53:53 UTC 2013


The following commit has been merged in the experimental branch:
commit 083c5a48ece9a6f316c49f383fa056279c811fd6
Author: Vitor Sessak <vitor1001 at gmail.com>
Date:   Sat Oct 31 02:02:30 2009 +0000

    Implement AMR gain function that is used by both AMR and SIPR.
    
    Based on AMR SoC code by Robert Swain and Colin McQuillan.
    
    Originally committed as revision 20421 to svn://svn.ffmpeg.org/ffmpeg/trunk

diff --git a/libavcodec/acelp_pitch_delay.c b/libavcodec/acelp_pitch_delay.c
index ac929c4..4c809d7 100644
--- a/libavcodec/acelp_pitch_delay.c
+++ b/libavcodec/acelp_pitch_delay.c
@@ -119,3 +119,24 @@ int16_t ff_acelp_decode_gain_code(
     return mr_energy >> 12;
 #endif
 }
+
+float ff_amr_set_fixed_gain(float fixed_gain_factor, float fixed_mean_energy,
+                            float *prediction_error, float energy_mean,
+                            const float *pred_table)
+{
+    // Equations 66-69:
+    // ^g_c = ^gamma_gc * 100.05 (predicted dB + mean dB - dB of fixed vector)
+    // Note 10^(0.05 * -10log(average x2)) = 1/sqrt((average x2)).
+    float val = fixed_gain_factor *
+        exp2f(log2f(10.0) * 0.05 *
+              (ff_dot_productf(pred_table, prediction_error, 4) +
+               energy_mean)) /
+        sqrtf(fixed_mean_energy);
+
+    // update quantified prediction error energy history
+    memmove(&prediction_error[0], &prediction_error[1],
+            3 * sizeof(prediction_error[0]));
+    prediction_error[3] = 20.0 * log10f(fixed_gain_factor);
+
+    return val;
+}
diff --git a/libavcodec/acelp_pitch_delay.h b/libavcodec/acelp_pitch_delay.h
index 2504a9e..42307d2 100644
--- a/libavcodec/acelp_pitch_delay.h
+++ b/libavcodec/acelp_pitch_delay.h
@@ -220,4 +220,18 @@ int16_t ff_acelp_decode_gain_code(
     int subframe_size,
     int max_pred_order);
 
+/**
+ * Calculate fixed gain (part of section 6.1.3 of AMR spec)
+ *
+ * @param fixed_gain_factor gain correction factor
+ * @param fixed_energy decoded algebraic codebook vector energy
+ * @param prediction_error vector of the quantified predictor errors of
+ *        the four previous subframes. It is updated by this function.
+ * @param energy_mean desired mean innovation energy
+ * @param pred_table table of four moving average coefficients
+ */
+float ff_amr_set_fixed_gain(float fixed_gain_factor, float fixed_mean_energy,
+                            float *prediction_error, float energy_mean,
+                            const float *pred_table);
+
 #endif /* AVCODEC_ACELP_PITCH_DELAY_H */

-- 
Libav/FFmpeg packaging



More information about the pkg-multimedia-commits mailing list