Index: mlpenc.c =================================================================== --- mlpenc.c (revision 3116) +++ mlpenc.c (working copy) @@ -22,6 +22,7 @@ #include "avcodec.h" #include "bitstream.h" #include "libavutil/crc.h" +#include "dsputil.h" /* TODO add comments! */ @@ -107,6 +108,8 @@ DecodingParams decoding_params[MAX_SUBSTREAMS]; RestartHeader restart_header[MAX_SUBSTREAMS]; + + DSPContext dsp; } MLPEncodeContext; #define SYNC_MAJOR 0xf8726f @@ -290,6 +293,8 @@ ctx->avctx = avctx; + dsputil_init(&ctx->dsp, avctx); + ctx->sample_rate = mlp_sample_rate(avctx->sample_rate); if (ctx->sample_rate < 0) { av_log(avctx, AV_LOG_ERROR, "Unsupported sample_rate.\n"); @@ -555,20 +560,49 @@ } } +#define ORDER_METHOD_EST 0 +#define ORDER_METHOD_2LEVEL 1 +#define ORDER_METHOD_4LEVEL 2 +#define ORDER_METHOD_8LEVEL 3 +#define ORDER_METHOD_SEARCH 4 +#define ORDER_METHOD_LOG 5 + +#define MAX_LPC_ORDER 32 + +/** + * Calculate LPC coefficients for multiple orders + */ +int ff_lpc_calc_coefs(DSPContext *dsp, + const int32_t *samples, int blocksize, int max_order, + int precision, int32_t coefs[][MAX_LPC_ORDER], + int *shift, int use_lpc, int omethod); + static void set_filter_params(MLPEncodeContext *ctx, unsigned int channel, unsigned int filter) { FilterParams *fp = &ctx->filter_params[channel][filter]; if (filter == FIR) { - fp->order = 4; - fp->shift = 0; - fp->coeff[0] = 1; - fp->coeff[1] = 0; - fp->coeff[2] = 0; - fp->coeff[3] = 0; + int32_t coefs[MAX_LPC_ORDER][MAX_LPC_ORDER]; + int32_t samples[MAX_BLOCKSIZE]; + int shift[MAX_FILTER_ORDER]; + int order; + int i; + + for (i = 0; i < ctx->avctx->frame_size; i++) + samples[i] = ctx->sample_buffer[i][channel]; + + order = ff_lpc_calc_coefs(&ctx->dsp, samples, ctx->avctx->frame_size, + 8, 9, coefs, shift, 1, ORDER_METHOD_EST); + + fp->order = order; + fp->shift = shift[order-1]; + + for (i = 0; i < order; i++) + fp->coeff[i] = coefs[order-1][i]; + } else { /* IIR */ - fp->order = 4; + fp->order = 0; fp->shift = 0; fp->coeff[0] = 0; fp->coeff[1] = 0;