[FFmpeg-devel] [PATCH] Common fixed-point ACELP routines (1/3) - math
Vladimir Voroshilov
voroshil
Wed Apr 23 21:41:54 CEST 2008
Michael Niedermayer wrote:
> On Thu, Apr 24, 2008 at 12:58:08AM +0700, Vladimir Voroshilov wrote:
> > Michael Niedermayer wrote:
> > > On Tue, Apr 22, 2008 at 11:53:10PM +0700, Vladimir Voroshilov wrote:
> > > >
> > > > Michael Niedermayer wrote:
> > > > > On Tue, Apr 22, 2008 at 09:12:16AM +0700, Vladimir Voroshilov wrote:
> > > > > > On Tue, Apr 22, 2008 at 6:05 AM, Michael Niedermayer <michaelni at gmx.at> wrote:
[...]
> > +{
> > + uint32_t result;
> > + uint8_t power_int;
> > + uint8_t frac_x0;
> > + uint16_t frac_dx;
> > +
> > + assert(value > 0);
> > +
> > + // Stripping zeros from beginning
> > + power_int = av_log2(value);
> > + result = value << (31 - power_int);
> > +
> > + // b31 is always non-zero now
> > + frac_x0 = (result & 0x7c000000) >> 26; // b26-b31 and [32..63] -> [0..31]
> > + frac_dx = (result & 0x03fff800) >> 11;
> > +
> > + result = tab_log2[frac_x0] << 15;
> > + result += frac_dx * (tab_log2[frac_x0+1] - tab_log2[frac_x0]);
> > +
> > + return (power_int << 15) + (result >> 15);
> > +}
>
> int ff_log2(unsigned int value)
> {
> uint8_t power_int;
> uint8_t frac_x0;
> uint16_t frac_dx;
>
> assert(value > 0);
>
> power_int = av_log2(value);
> value <<= 31 - power_int;
>
> frac_x0 = (value & 0x7c000000) >> 26
> frac_dx = (value & 0x03fff800) >> 11;
>
> value = tab_log2[frac_x0];
> value += (frac_dx * (tab_log2[frac_x0+1] - tab_log2[frac_x0])) >> 15;
>
> return (power_int << 15) + value;
> }
Fixed in local tree.
> [...]
> > +/**
> > + * \brief multiplies 32-bit integer by another 16-bit and divides result by 2^15
> > + * \param var_q24 32-bit integer
> > + * \param var_15 16-bit integer
> > + *
> > + * \return result of (var_q24 * var_q15 >> 15) with clipping to [INT_MIN; INT_MAX] range
> > + */
> > +static inline int mul_24_15(int var_q24, int16_t var_q15)
> > +{
> > + int64_t tmp = (((int64_t)var_q24 * (int64_t)var_q15) >> 15);
> > +
> > + if(tmp < INT_MIN)
> > + return INT_MIN;
> > + else if (tmp > INT_MAX)
> > + return INT_MAX;
> > + else
> > + return tmp;
> > +}
>
> INT_MIN/MAX depends on how bits there are in int, this is not what g729
> wants.
Fixed in local tree.
[...]
> > +/**
> > + * \brief Calculates sum of array elements absolute values
> > + * \param speech array with input data
> > + * \param cycles number elements to proceed
> > + * \param shift right shift by this value will be done before addition
> > + *
> > + * \return sum of absolute values
> > + */
> > +static int sum_of_absolute(const int16_t* speech, int cycles, int shift)
> > +{
> > + int n;
> > + int sum = 0;
> > +
> > + for(n=0; n<cycles; n++)
> > + sum += FFABS(speech[n] >> shift);
> > +
> > + return sum;
> > +}
>
> The place where the shift is done is not optimal for precission.
I've just realized that i'm not using shift at all.
Should i keep routine as is, remove shift or remove all routine?
Currently moved outside loop.
--
Regards,
Vladimir Voroshilov mailto:voroshil at gmail.com
Omsk State University
JID: voroshil at jabber.ru
ICQ: 95587719
More information about the ffmpeg-devel
mailing list