From 504eee37debbf7ce6ec3b79ae8825727258c3fd7 Mon Sep 17 00:00:00 2001 From: Vitor Sessak Date: Tue, 27 Oct 2009 23:53:18 +0000 Subject: Commit some functions that are used by both SIPR and AMR. Based on AMR SoC code by Robert Swain and Colin McQuillan. Originally committed as revision 20392 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/acelp_vectors.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'libavcodec/acelp_vectors.c') diff --git a/libavcodec/acelp_vectors.c b/libavcodec/acelp_vectors.c index 5443006718..2d9aa1ad79 100644 --- a/libavcodec/acelp_vectors.c +++ b/libavcodec/acelp_vectors.c @@ -23,6 +23,7 @@ #include #include "avcodec.h" #include "acelp_vectors.h" +#include "celp_math.h" const uint8_t ff_fc_2pulses_9bits_track1[16] = { @@ -155,3 +156,24 @@ void ff_weighted_vector_sumf(float *out, const float *in_a, const float *in_b, 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; +} -- cgit v1.2.3