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

Francesco Lavra francescolavra
Sun May 16 16:35:36 CEST 2010


On Mon, 2010-05-10 at 12:55 +0200, Michael Niedermayer wrote:
> 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

Fixed.

> > +        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

Fixed slightly differently, since now gain is a float.

Updated patch coming in a bit.





More information about the ffmpeg-devel mailing list