[FFmpeg-devel] Trans.: a64multienc.c and drawutils.c optimisations
Reimar Döffinger
Reimar.Doeffinger at gmx.de
Wed Dec 28 11:53:24 CET 2011
On Wed, Dec 28, 2011 at 05:43:56AM +0100, Michael Niedermayer wrote:
> On Wed, Dec 28, 2011 at 04:35:04AM +0100, yann.lepetitcorps at free.fr wrote:
> > diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
> > index 688fba4..70715c9 100644
> > --- a/libavcodec/adpcm.c
> > +++ b/libavcodec/adpcm.c
> > @@ -160,6 +160,8 @@ static inline short adpcm_ima_expand_nibble(ADPCMChannelStatus *c, char nibble,
> > return (short)c->predictor;
> > }
> >
> > +int adpcm_nibble_diff_step_tab[8] = { 0, 4, 2, 6, 1, 3, 5, 7 };
> > +
> > static inline int adpcm_ima_qt_expand_nibble(ADPCMChannelStatus *c, int nibble, int shift)
> > {
> > int step_index;
> > @@ -169,11 +171,13 @@ static inline int adpcm_ima_qt_expand_nibble(ADPCMChannelStatus *c, int nibble,
> > step = ff_adpcm_step_table[c->step_index];
> > step_index = c->step_index + ff_adpcm_index_table[nibble];
> > step_index = av_clip(step_index, 0, 88);
> > -
> > +/*
> > diff = step >> 3;
> > if (nibble & 4) diff += step;
> > if (nibble & 2) diff += step >> 1;
> > if (nibble & 1) diff += step >> 2;
> > +*/
> > + diff = (adpcm_nibble_diff_step_tab[nibble &0x7]+8) * step;
>
> see adpcm_ima_expand_nibble()
> one problem though is that this is not producing the same result
Yes, exactly that is the problem.
The rounding errors must be exactly as the code with 3 separate adds
produces, otherwise the result is incorrect.
You should test any optimization against all possible values of nibble and
c->step_index to make sure it does not change the result in any case.
I suspect a table [step & 7][nibble] should work, but due to size and cache
effects that seems likely to just be slower.
More information about the ffmpeg-devel
mailing list