[FFmpeg-devel] [PATCH] RealAudio 14.4K encoder

Michael Niedermayer michaelni
Mon May 10 12:55:48 CEST 2010


On Sat, May 08, 2010 at 08:57:39PM +0200, Francesco Lavra wrote:
[...]

> +/**
> + * Quantizes a value by searching a sorted table for the element with the
> +   nearest value
> + * @param value value to quantize
> + * @param table array containing the quantization table
> + * @param size size of the quantization table
> + * @return index of the quantization table corresponding to the element with the
> + *         nearest value
> + */
> +static int quantize(int value, const int16_t *table, unsigned int size)
> +{
> +    int error;
> +    int index;
> +    unsigned int low = 0, high = size - 1;
> +
> +    while (1) {
> +        index = (low + high) >> 1;
> +        error = table[index] - value;
> +        if (index == low)
> +            return (FFABS(error) < FFABS(table[high] - value) ? low : high);

table[high] + error > value ? low : high


> +        if (error > 0) {
> +            high = index;
> +        } else {
> +            low = index;
> +        }
> +    }
> +}
> +
> +
> +/**
> + * Calculates match score and gain of an LPC-filtered vector with respect to
> +   input data
> + * @param block array used to calculate the filtered vector
> + * @param coefs coefficients of the LPC filter
> + * @param vect original vector
> + * @param data input data
> + * @param score pointer to variable where match score is returned
> + * @param gain pointer to variable where gain is returned
> + */
> +static void get_match_score(int16_t *block, const int16_t *coefs,
> +                            const int16_t *vect, const int16_t *data,
> +                            float *score, int *gain)
> +{
> +    float c, g;
> +    int i;
> +
> +    if (ff_celp_lp_synthesis_filter(block, coefs, vect, BLOCKSIZE, LPC_ORDER, 1,
> +                                    0x800)) {
> +        *score = 0;
> +        return;
> +    }
> +    c = g = 0;
> +    for (i = 0; i < BLOCKSIZE; i++) {
> +        g += block[i] * block[i];
> +        c += data[i] * block[i];
> +    }
> +    if (!g || (c <= 0)) {
> +        *score = 0;
> +        return;
> +    }

> +    *score = c * c / g;
> +    *gain = (c * 0x1000) / g;

g=c/g;
*score = g * c;
*gain  = g * 0x1000;

avoids one division, probably makes no meassureable speed difference though

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I have never wished to cater to the crowd; for what I know they do not
approve, and what they approve I do not know. -- Epicurus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100510/bf7df405/attachment.pgp>



More information about the ffmpeg-devel mailing list