X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Flpc.c;h=fbd1bdf002403abd0cc90c82a6cf2d6548b85958;hb=369380e1c4c6fc9b0d9ff04ec23d46b252ba7110;hp=126dbc12668e3cf98703b039c9e49011a973bcc0;hpb=f101eab1be1a296a1a048cd905edfcacc3b546ed;p=ffmpeg diff --git a/libavcodec/lpc.c b/libavcodec/lpc.c index 126dbc12668..fbd1bdf0024 100644 --- a/libavcodec/lpc.c +++ b/libavcodec/lpc.c @@ -148,6 +148,18 @@ static int estimate_best_order(double *ref, int min_order, int max_order) return est; } +int ff_lpc_calc_ref_coefs(LPCContext *s, + const int32_t *samples, int order, double *ref) +{ + double autoc[MAX_LPC_ORDER + 1]; + + s->lpc_apply_welch_window(samples, s->blocksize, s->windowed_samples); + s->lpc_compute_autocorr(s->windowed_samples, s->blocksize, order, autoc); + compute_ref_coefs(autoc, order, ref, NULL); + + return order; +} + /** * Calculate LPC coefficients for multiple orders * @@ -164,7 +176,7 @@ int ff_lpc_calc_coefs(LPCContext *s, double autoc[MAX_LPC_ORDER+1]; double ref[MAX_LPC_ORDER]; double lpc[MAX_LPC_ORDER][MAX_LPC_ORDER]; - int i, j, pass; + int i, j, pass = 0; int opt_order; assert(max_order >= MIN_LPC_ORDER && max_order <= MAX_LPC_ORDER && @@ -177,7 +189,7 @@ int ff_lpc_calc_coefs(LPCContext *s, ff_lpc_init(s, blocksize, max_order, lpc_type); } - if (lpc_type == FF_LPC_TYPE_LEVINSON) { + if (lpc_type == FF_LPC_TYPE_LEVINSON || (lpc_type == FF_LPC_TYPE_CHOLESKY && lpc_passes > 1)) { s->lpc_apply_welch_window(samples, blocksize, s->windowed_samples); s->lpc_compute_autocorr(s->windowed_samples, blocksize, max_order, autoc); @@ -186,12 +198,21 @@ int ff_lpc_calc_coefs(LPCContext *s, for(i=0; i>pass) + fabs(eval - var[0]); inv = 1/eval; rinv = sqrt(inv); @@ -210,9 +231,9 @@ int ff_lpc_calc_coefs(LPCContext *s, }else weight++; - av_update_lls(&m[pass&1], var, 1.0); + m[pass&1].update_lls(&m[pass&1], var); } - av_solve_lls(&m[pass&1], 0.001, 0); + avpriv_solve_lls(&m[pass&1], 0.001, 0); } for(i=0; imax_order = max_order; s->lpc_type = lpc_type; - if (lpc_type == FF_LPC_TYPE_LEVINSON) { - s->windowed_buffer = av_mallocz((blocksize + 2 + FFALIGN(max_order, 4)) * - sizeof(*s->windowed_samples)); - if (!s->windowed_buffer) - return AVERROR(ENOMEM); - s->windowed_samples = s->windowed_buffer + FFALIGN(max_order, 4); - } else { - s->windowed_samples = NULL; - } + s->windowed_buffer = av_mallocz((blocksize + 2 + FFALIGN(max_order, 4)) * + sizeof(*s->windowed_samples)); + if (!s->windowed_buffer) + return AVERROR(ENOMEM); + s->windowed_samples = s->windowed_buffer + FFALIGN(max_order, 4); s->lpc_apply_welch_window = lpc_apply_welch_window_c; s->lpc_compute_autocorr = lpc_compute_autocorr_c;