summaryrefslogtreecommitdiffstats
path: root/libavcodec/flacenc.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2006-07-15 23:43:38 +0000
committerMichael Niedermayer <michaelni@gmx.at>2006-07-15 23:43:38 +0000
commit408ec4e2a6c3fb40e14ac4f0fb2fb9e40ff3e6a3 (patch)
tree981867ca181d59ac2849f28241be9185f272c59c /libavcodec/flacenc.c
parent6ce704bbedac2745b51bfdb11af2431f05a1dc23 (diff)
downloadffmpeg-streaming-408ec4e2a6c3fb40e14ac4f0fb2fb9e40ff3e6a3.zip
ffmpeg-streaming-408ec4e2a6c3fb40e14ac4f0fb2fb9e40ff3e6a3.tar.gz
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
Originally committed as revision 5758 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/flacenc.c')
-rw-r--r--libavcodec/flacenc.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c
index b72da90..af36976 100644
--- a/libavcodec/flacenc.c
+++ b/libavcodec/flacenc.c
@@ -742,35 +742,41 @@ static int lpc_calc_coefs(const int32_t *samples, int blocksize, int max_order,
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]);
OpenPOWER on IntegriCloud