]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/lls.c
rtmp: Follow Flash player numbering for channels.
[ffmpeg] / libavutil / lls.c
index b29fc968dae38d9c3fe334d547fe438dc0d1c841..f87c2cd153302a608639970a377e8e5eabb055ad 100644 (file)
 #include <math.h>
 #include <string.h>
 
+#include "attributes.h"
+#include "version.h"
 #include "lls.h"
 
-void av_init_lls(LLSModel *m, int indep_count)
-{
-    memset(m, 0, sizeof(LLSModel));
-    m->indep_count = indep_count;
-}
-
-void av_update_lls(LLSModel *m, double *var, double decay)
+static void update_lls(LLSModel *m, double *var)
 {
     int i, j;
 
     for (i = 0; i <= m->indep_count; i++) {
         for (j = i; j <= m->indep_count; j++) {
-            m->covariance[i][j] *= decay;
             m->covariance[i][j] += var[i] * var[j];
         }
     }
 }
 
-void av_solve_lls(LLSModel *m, double threshold, int min_order)
+void avpriv_solve_lls(LLSModel *m, double threshold, unsigned short min_order)
 {
     int i, j, k;
-    double (*factor)[MAX_VARS + 1] = (void *) &m->covariance[1][0];
-    double (*covar) [MAX_VARS + 1] = (void *) &m->covariance[1][1];
+    double (*factor)[MAX_VARS_ALIGN] = (void *) &m->covariance[1][0];
+    double (*covar) [MAX_VARS_ALIGN] = (void *) &m->covariance[1][1];
     double *covar_y                = m->covariance[0];
     int count                      = m->indep_count;
 
@@ -105,7 +100,7 @@ void av_solve_lls(LLSModel *m, double threshold, int min_order)
     }
 }
 
-double av_evaluate_lls(LLSModel *m, double *param, int order)
+static double evaluate_lls(LLSModel *m, double *param, int order)
 {
     int i;
     double out = 0;
@@ -116,6 +111,35 @@ double av_evaluate_lls(LLSModel *m, double *param, int order)
     return out;
 }
 
+av_cold void avpriv_init_lls(LLSModel *m, int indep_count)
+{
+    memset(m, 0, sizeof(LLSModel));
+    m->indep_count = indep_count;
+    m->update_lls = update_lls;
+    m->evaluate_lls = evaluate_lls;
+    if (ARCH_X86)
+        ff_init_lls_x86(m);
+}
+
+#if FF_API_LLS_PRIVATE
+av_cold void av_init_lls(LLSModel *m, int indep_count)
+{
+    avpriv_init_lls(m, indep_count);
+}
+void av_update_lls(LLSModel *m, double *param, double decay)
+{
+    m->update_lls(m, param);
+}
+void av_solve_lls(LLSModel *m, double threshold, int min_order)
+{
+    avpriv_solve_lls(m, threshold, min_order);
+}
+double av_evaluate_lls(LLSModel *m, double *param, int order)
+{
+    return m->evaluate_lls(m, param, order);
+}
+#endif /* FF_API_LLS_PRIVATE */
+
 #ifdef TEST
 
 #include <stdio.h>
@@ -129,20 +153,20 @@ int main(void)
     AVLFG lfg;
 
     av_lfg_init(&lfg, 1);
-    av_init_lls(&m, 3);
+    avpriv_init_lls(&m, 3);
 
     for (i = 0; i < 100; i++) {
-        double var[4];
+        LOCAL_ALIGNED(32, double, var, [4]);
         double eval;
 
         var[0] = (av_lfg_get(&lfg) / (double) UINT_MAX - 0.5) * 2;
         var[1] = var[0] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
         var[2] = var[1] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
         var[3] = var[2] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
-        av_update_lls(&m, var, 0.99);
-        av_solve_lls(&m, 0.001, 0);
+        m.update_lls(&m, var);
+        avpriv_solve_lls(&m, 0.001, 0);
         for (order = 0; order < 3; order++) {
-            eval = av_evaluate_lls(&m, var + 1, order);
+            eval = m.evaluate_lls(&m, var + 1, order);
             printf("real:%9f order:%d pred:%9f var:%f coeffs:%f %9f %9f\n",
                    var[0], order, eval, sqrt(m.variance[order] / (i + 1)),
                    m.coeff[order][0], m.coeff[order][1],