summaryrefslogtreecommitdiff
path: root/libavcodec/acelp_vectors.c
diff options
context:
space:
mode:
authorReynaldo H. Verdejo Pinochet <reynaldo@opendot.cl>2009-11-04 19:29:29 +0000
committerReynaldo H. Verdejo Pinochet <reynaldo@opendot.cl>2009-11-04 19:29:29 +0000
commit0c50f8e6ccda2ff0b265d36412fae103b276af2e (patch)
treeb9f3d071e6c48f011ecc1ba3229b71ceeb60d95a /libavcodec/acelp_vectors.c
parent223217746c5beaa6110ce9ade2a582fc10d3d630 (diff)
Implement ff_scale_vector_to_given_sum_of_squares()
to aid generic gain control routines. Changes for qcelp are included. Patch Collin McQuillan. Originally committed as revision 20450 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/acelp_vectors.c')
-rw-r--r--libavcodec/acelp_vectors.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/libavcodec/acelp_vectors.c b/libavcodec/acelp_vectors.c
index 2d9aa1ad79..e6979205b9 100644
--- a/libavcodec/acelp_vectors.c
+++ b/libavcodec/acelp_vectors.c
@@ -22,6 +22,7 @@
#include <inttypes.h>
#include "avcodec.h"
+#include "celp_math.h"
#include "acelp_vectors.h"
#include "celp_math.h"
@@ -177,3 +178,14 @@ void ff_adaptative_gain_control(float *buf_out, float speech_energ,
*gain_mem = mem;
}
+
+void ff_scale_vector_to_given_sum_of_squares(float *out, const float *in,
+ float sum_of_squares, const int n)
+{
+ int i;
+ float scalefactor = ff_dot_productf(in, in, n);
+ if (scalefactor)
+ scalefactor = sqrt(sum_of_squares / scalefactor);
+ for (i = 0; i < n; i++)
+ out[i] = in[i] * scalefactor;
+}