[FFmpeg-devel] [PATCH] [WIP] avcodec/lpc: quantize LPC coefficients by multidimensional search instead of independant scalar quantization

Ronald S. Bultje rsbultje at gmail.com
Tue May 19 03:21:30 CEST 2015


Hi,

On Mon, May 18, 2015 at 7:53 AM, Michael Niedermayer <michaelni at gmx.at>
wrote:

> This improves compression but only by a very small bit
> possibly it could be improved by exactly calculating the number of bits
> that would be needed
>
> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> ---
>  libavcodec/lpc.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 47 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/lpc.c b/libavcodec/lpc.c
> index deb02e7..930e526 100644
> --- a/libavcodec/lpc.c
> +++ b/libavcodec/lpc.c
> @@ -135,6 +135,51 @@ static void quantize_lpc_coefs(double *lpc_in, int
> order, int precision,
>      *shift = sh;
>  }
>
> +static void quantize_lpc_coefs2(double *lpc_in, int order, int precision,
> +                               int32_t *lpc_out, int *shift, int
> max_shift,
> +                               int zero_shift, const int32_t *samples,
> int len)
> +{
> +    int allsteps = 1;
> +    int i, j, step, improved;
> +    int64_t best_score = INT64_MAX;
> +    int32_t qmax;
> +
> +    qmax = (1 << (precision - 1)) - 1;
> +
> +    quantize_lpc_coefs(lpc_in, order, precision, lpc_out, shift,
> max_shift, zero_shift);
> +
> +    for (i=0; i<order; i++)
> +        allsteps *= 3;
> +
> +    do {
> +        improved = 0;
> +        for (step = 0; step < allsteps; step++) {
> +            int tmp = step;
> +            int32_t lpc_try[MAX_LPC_ORDER];
> +            int64_t score = 0;
> +            for (i=0; i<order; i++) {
> +                lpc_try[i] = av_clip(lpc_out[i] + ((tmp + 1) % 3) - 1,
> -qmax, qmax);
> +                tmp /= 3;
> +            }
> +            for (j=order; j<len; j++) {
> +                int64_t v = 0;
> +                for (i=0; i<order; i++) {
> +                    v += samples[j - 1 - i] * (int64_t)lpc_try[i];
> +                }
> +                v >>= *shift;
> +                v -= samples[j];
> +                score += FFABS(v);
> +            }
> +            if (score < best_score) {
> +                best_score = score;
> +                memcpy(lpc_out, lpc_try, sizeof(*lpc_out) * order);
> +//                 improved=1;
> +            }
> +//             av_log(0,0, "score %Ld\n", best_score);
> +        }
> +    } while(improved);
>

Is it intentional that improved is read-only?

Ronald


More information about the ffmpeg-devel mailing list