[FFmpeg-devel] [PATCH] ac3dec: fix non-optimal dithering of zero bit mantissas
Reimar.Doeffinger at gmx.de
Sat Jan 5 12:10:07 CET 2013
On Sat, Jan 05, 2013 at 12:00:32PM +0100, madshi wrote:
> 2013/1/5 Reimar Döffinger <Reimar.Doeffinger at gmx.de>
> > Not sure about lfg (though IMHO it should be replaced by
> > lcg anyway to not needlessly waste CPU time) but usually
> > the lower bits contain more "randomness". Thus you should
> > generally be using some kind of modulo operation instead
> > of a division.
> > In addition, doing division/modulo by a value that is not
> > a power of 2 will introduce some bias. It might not be
> > relevant, but it should be analyzed to make sure it truly
> > isn't.
> Well, my knowledge about random numbers is kinda limited. Maybe someone
> with more knowledge in that area can improve my patch? In any case, with my
> patch applied the frequency response of the AC3 decoder is clearly better
> than without it, so the patch seems to work reasonably well as it is...
Well, my suggestion would be to use % 11864550 instead of / 362,
that's trivial and more readable.
There is a bias of lower than < 0.5% towards mantissas smaller than
Probably that is not an issue, but if really necessary to avoid you'd
have to ignore any values from the random number generator that are
larger or equal to 11864550*362, i.e. retry getting a random number
until it is smaller than that.
More information about the ffmpeg-devel