]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/lpc.c
Merge commit '6536da7371b4847a2824ed46b98829f127f24dad'
[ffmpeg] / libavcodec / lpc.c
index 02ab61cf1ce38d75d82052f6037ee76193fef3a3..5cda7797e42ceda00e0db67959c8f70697c46931 100644 (file)
@@ -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+1] = {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
  *
@@ -271,62 +291,6 @@ int ff_lpc_calc_coefs(LPCContext *s,
     return opt_order;
 }
 
-/**
- * Simplified Levinson LPC accepting float samples
- *
- * @param lpc_type LPC method for determining coefficients,
- *                 see #FFLPCType for details
- */
-int ff_lpc_calc_levinson(LPCContext *s, const float *samples, int len,
-                         double lpc[][MAX_LPC_ORDER], int min_order,
-                         int max_order, int omethod)
-{
-    double ref[MAX_LPC_ORDER] = { 0 };
-    double autoc[MAX_LPC_ORDER+1];
-    double *w_data = s->windowed_samples;
-    int i, n2 = (len >> 1);
-    double w, c = 2.0 / (len - 1.0);
-
-    av_assert2(max_order >= MIN_LPC_ORDER && max_order <= MAX_LPC_ORDER);
-
-    /* reinit LPC context if parameters have changed */
-    if (len > s->blocksize || max_order > s->max_order) {
-        ff_lpc_end(s);
-        ff_lpc_init(s, len, max_order, FF_LPC_TYPE_LEVINSON);
-    }
-
-    /* Apply welch window */
-    if (len & 1) {
-        for(i=0; i<n2; i++) {
-            w = c - i - 1.0;
-            w = 1.0 - (w * w);
-            w_data[i] = samples[i] * w;
-            w_data[len-1-i] = samples[len-1-i] * w;
-        }
-    } else {
-        w_data+=n2;
-        samples+=n2;
-        for(i=0; i<n2; i++) {
-            w = c - n2 + i;
-            w = 1.0 - (w * w);
-            w_data[-i-1] = samples[-i-1] * w;
-            w_data[+i  ] = samples[+i  ] * w;
-        }
-    }
-
-    s->lpc_compute_autocorr(w_data, len, max_order, autoc);
-
-    compute_lpc_coefs(autoc, max_order, &lpc[0][0], max_order, 0, 1);
-
-    if(omethod == ORDER_METHOD_EST) {
-        for(i=0; i<max_order; i++)
-            ref[i] = fabs(lpc[i][i]);
-        return estimate_best_order(ref, min_order, max_order);
-    }
-
-    return max_order;
-}
-
 av_cold int ff_lpc_init(LPCContext *s, int blocksize, int max_order,
                         enum FFLPCType lpc_type)
 {