[FFmpeg-cvslog] lpc: add ff_lpc_calc_ref_coefs_f() function
Rostislav Pehlivanov
git at videolan.org
Tue Sep 1 08:09:42 CEST 2015
ffmpeg | branch: master | Rostislav Pehlivanov <atomnuker at gmail.com> | Tue Sep 1 06:34:50 2015 +0100| [0fc3a51353509df107a8da192d8377f0121f7ab9] | committer: Rostislav Pehlivanov
lpc: add ff_lpc_calc_ref_coefs_f() function
This commit adds a function to get the reflection coefficients on
floating point samples. It's functionally identical to
ff_lpc_calc_ref_coefs() except it works on float samples and will
return the global prediction gain. The Welch window implementation
which is more optimized works only on int32_t samples so a slower
generic expression was used.
Signed-off-by: Rostislav Pehlivanov <atomnuker at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0fc3a51353509df107a8da192d8377f0121f7ab9
---
libavcodec/lpc.c | 20 ++++++++++++++++++++
libavcodec/lpc.h | 2 ++
2 files changed, 22 insertions(+)
diff --git a/libavcodec/lpc.c b/libavcodec/lpc.c
index 07fc292..315997c 100644
--- a/libavcodec/lpc.c
+++ b/libavcodec/lpc.c
@@ -167,6 +167,26 @@ int ff_lpc_calc_ref_coefs(LPCContext *s,
return order;
}
+double ff_lpc_calc_ref_coefs_f(LPCContext *s, const float *samples, int len,
+ int order, double *ref)
+{
+ int i;
+ double signal = 0.0f, avg_err = 0.0f;
+ double autoc[MAX_LPC_ORDER+1] = {0}, error[MAX_LPC_ORDER] = {0};
+ const double c = (len - 1)/2.0f;
+
+ /* Welch window */
+ for (i = 0; i < len; i++)
+ s->windowed_samples[i] = 1.0f - ((samples[i]-c)/c)*((samples[i]-c)/c);
+
+ s->lpc_compute_autocorr(s->windowed_samples, len, order, autoc);
+ signal = autoc[0];
+ compute_ref_coefs(autoc, order, ref, error);
+ for (i = 0; i < order; i++)
+ avg_err = (avg_err + error[i])/2.0f;
+ return signal/avg_err;
+}
+
/**
* Calculate LPC coefficients for multiple orders
*
diff --git a/libavcodec/lpc.h b/libavcodec/lpc.h
index 3aef623..7e0ee3e 100644
--- a/libavcodec/lpc.h
+++ b/libavcodec/lpc.h
@@ -100,6 +100,8 @@ int ff_lpc_calc_coefs(LPCContext *s,
int ff_lpc_calc_ref_coefs(LPCContext *s,
const int32_t *samples, int order, double *ref);
+double ff_lpc_calc_ref_coefs_f(LPCContext *s, const float *samples, int len,
+ int order, double *ref);
/**
* Initialize LPCContext.
More information about the ffmpeg-cvslog
mailing list