diff acelp_vectors.c @ 10463:9f35b262d3f0 libavcodec

Commit some functions that are used by both SIPR and AMR. Based on AMR SoC code by Robert Swain and Colin McQuillan.
author vitor
date Tue, 27 Oct 2009 23:53:18 +0000
parents 139d30c8c274
children 5f2ced30548b
line wrap: on
line diff
--- a/acelp_vectors.c	Tue Oct 27 20:56:56 2009 +0000
+++ b/acelp_vectors.c	Tue Oct 27 23:53:18 2009 +0000
@@ -23,6 +23,7 @@
 #include <inttypes.h>
 #include "avcodec.h"
 #include "acelp_vectors.h"
+#include "celp_math.h"
 
 const uint8_t ff_fc_2pulses_9bits_track1[16] =
 {
@@ -155,3 +156,24 @@
         out[i] = weight_coeff_a * in_a[i]
                + weight_coeff_b * in_b[i];
 }
+
+void ff_adaptative_gain_control(float *buf_out, float speech_energ,
+                                int size, float alpha, float *gain_mem)
+{
+    int i;
+    float postfilter_energ = ff_dot_productf(buf_out, buf_out, size);
+    float gain_scale_factor = 1.0;
+    float mem = *gain_mem;
+
+    if (postfilter_energ)
+        gain_scale_factor = sqrt(speech_energ / postfilter_energ);
+
+    gain_scale_factor *= 1.0 - alpha;
+
+    for (i = 0; i < size; i++) {
+        mem = alpha * mem + gain_scale_factor;
+        buf_out[i] *= mem;
+    }
+
+    *gain_mem = mem;
+}