[FFmpeg-devel] [PATCH] G.729A (now fixed-point) decoder

Michael Niedermayer michaelni
Wed Mar 19 15:30:14 CET 2008


On Wed, Mar 19, 2008 at 03:10:35PM +0100, Reimar D?ffinger wrote:
> Hello,
> On Sun, Mar 16, 2008 at 12:24:58AM +0600, Vladimir Voroshilov wrote:
> > +/**
> > + * \brief shift to right with rounding
> > + * \param var1 32-bit integer to shift
> > + * \param var2 16-bit shift
> > + */
> > +static int l_shr_r(int var1, int16_t var2)
> > +{
> > +    if(var1 && (var1 & (1 << (var2 - 1))))
> > +        return (var1 >> var2) + 1;
> > +    else
> > +        return (var1 >> var2);
> > +}
> 
> Same as
> return ((var1 >> (var2 - 1)) + 1) >> 1;
> ?

yes

but it should be

(var1 + (1<<(var2 - 1)) ) >> var2;

with someone analyzing the code to ensure it wont overflow, failing that
a assert() can be used to catch overflows.


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

Asymptotically faster algorithms should always be preferred if you have
asymptotical amounts of data
-------------- 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/20080319/9b66d146/attachment.pgp>



More information about the ffmpeg-devel mailing list