$OpenBSD: patch-libavcodec_lpc_c,v 1.1 2015/10/13 05:44:18 ajacoutot Exp $

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

--- libavcodec/lpc.c.orig	Mon Oct 12 23:03:10 2015
+++ libavcodec/lpc.c	Mon Oct 12 23:03:21 2015
@@ -173,11 +173,13 @@ 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; i++) {
+        double weight = a - b*cos((2*M_PI*i)/(len - 1));
+        s->windowed_samples[i] = weight*samples[i];
+    }
 
     s->lpc_compute_autocorr(s->windowed_samples, len, order, autoc);
     signal = autoc[0];
