changeset 3473:fa545ed305c9 libavcodec

calculate all coefficients for several orders during cholesky factorization, the resulting coefficients are not strictly optimal though as there is a small difference in the autocorrelation matrixes which is ignored for the smaller orders
author michael
date Sat, 15 Jul 2006 23:43:38 +0000
parents 0e0cffe06fb3
children 24f293c3f3ef
files flacenc.c
diffstat 1 files changed, 15 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/flacenc.c	Fri Jul 14 19:31:58 2006 +0000
+++ b/flacenc.c	Sat Jul 15 23:43:38 2006 +0000
@@ -742,35 +742,41 @@
         compute_autocorr(samples, blocksize, max_order+1, autoc);
 
         compute_lpc_coefs(autoc, max_order, lpc, ref);
-
-        opt_order = estimate_best_order(ref, max_order);
     }else{
         LLSModel m[2];
-        double var[MAX_LPC_ORDER+1], eval;
+        double var[MAX_LPC_ORDER+1], eval, weight;
 
         for(pass=0; pass<use_lpc-1; pass++){
             av_init_lls(&m[pass&1], max_order);
 
+            weight=0;
             for(i=max_order; i<blocksize; i++){
                 for(j=0; j<=max_order; j++)
                     var[j]= samples[i-j];
 
                 if(pass){
-                    eval= av_evaluate_lls(&m[(pass-1)&1], var+1);
+                    eval= av_evaluate_lls(&m[(pass-1)&1], var+1, max_order-1);
                     eval= (512>>pass) + fabs(eval - var[0]);
                     for(j=0; j<=max_order; j++)
                         var[j]/= sqrt(eval);
-                }
+                    weight += 1/eval;
+                }else
+                    weight++;
 
                 av_update_lls(&m[pass&1], var, 1.0);
             }
-            av_solve_lls(&m[pass&1], 0.001);
-            opt_order= max_order; //FIXME
+            av_solve_lls(&m[pass&1], 0.001, 0);
         }
 
-        for(i=0; i<opt_order; i++)
-            lpc[opt_order-1][i]= m[(pass-1)&1].coeff[i];
+        for(i=0; i<max_order; i++){
+            for(j=0; j<max_order; j++)
+                lpc[i][j]= m[(pass-1)&1].coeff[i][j];
+            ref[i]= sqrt(m[(pass-1)&1].variance[i] / weight) * (blocksize - max_order) / 4000;
+        }
+        for(i=max_order-1; i>0; i--)
+            ref[i] = ref[i-1] - ref[i];
     }
+    opt_order = estimate_best_order(ref, max_order);
 
     i = opt_order-1;
     quantize_lpc_coefs(lpc[i], i+1, precision, coefs[i], &shift[i]);