$OpenBSD: patch-libavcodec_lpc_c,v 1.2 2016/04/07 06:01:19 ajacoutot Exp $

lpc: correctly apply windowing to the samples in the float-only lpc

lavc/lpc: exploit even symmetry of window function

--- libavcodec/lpc.c.orig	Wed Jan 13 15:27:48 2016
+++ libavcodec/lpc.c	Thu Mar 24 20:27:56 2016
@@ -173,11 +173,14 @@ double ff_lpc_calc_ref_coefs_f(LPCContext *s, const fl
     int i;
     double signal = 0.0f, avg_err = 0.0f;
     double autoc[MAX_LPC_ORDER+1] = {0}, error[MAX_LPC_ORDER+1] = {0};
-    const double c = (len - 1)/2.0f;
+    const double a = 0.5f, b = 1.0f - a;
 
-    /* Welch window */
-    for (i = 0; i < len; i++)
-        s->windowed_samples[i] = 1.0f - ((samples[i]-c)/c)*((samples[i]-c)/c);
+    /* Apply windowing */
+    for (i = 0; i <= len / 2; i++) {
+        double weight = a - b*cos((2*M_PI*i)/(len - 1));
+        s->windowed_samples[i] = weight*samples[i];
+        s->windowed_samples[len-1-i] = weight*samples[len-1-i];
+    }
 
     s->lpc_compute_autocorr(s->windowed_samples, len, order, autoc);
     signal = autoc[0];
