[FFmpeg-devel] [PATCH] Box-Muller gaussian generator
Michael Niedermayer
michaelni
Fri Dec 11 01:40:08 CET 2009
On Sun, Dec 06, 2009 at 11:13:37PM +0100, Stefano Sabatini wrote:
> On date Sunday 2009-12-06 19:40:20 +0100, Vitor Sessak encoded:
> > Stefano Sabatini wrote:
> >> Hi,
> >>
> >> I'm going to use this for a noise filter, I believe this could be
> >> useful in other part of libav* though.
> >
> >> +double av_bmg_get(AVBMG *bmg)
> >> +{
> >> + double x1, x2, w, y;
> >> + AVLFG *lfg = &bmg->lfg;
> >> +
> >> + do {
> >> + x1 = 2.0 * ranf(lfg) - 1.0;
> >> + x2 = 2.0 * ranf(lfg) - 1.0;
> >> + w = x1*x1 + x2*x2;
> >> + } while (w >= 1.0);
> >> +
> >> + w = sqrt((-2.0 * log(w)) / w);
> >> + y = x2 * w;
> >> +
> >> + return bmg->mean + y * bmg->std_dev;
> >> +}
> >
> > This generates two numbers to use only one. Isn't it faster to store the
> > second number for the next call or have a function to fill a buffer of
> > random numbers?
>
> Implemented the first idea.
void av_bmg_get(AVLFG *lfg, double out[2]);
double x1, x2, w;
do {
x1 = 2.0/UINT_MAX*av_lfg_get(lfg) - 1.0;
x2 = 2.0/UINT_MAX*av_lfg_get(lfg) - 1.0;
w = x1*x1 + x2*x2;
} while (w >= 1.0);
w = sqrt((-2.0 * log(w)) / w);
out[0] = x1 * w;
out[1] = x2 * w;
}
comments welcome, if none ill commit above
libavutil is supposed to be clean and i wont tolerate it being filled up with
odd mess like what was suggested! Above does the same, faster and much
simpler, besides its not containing an obvious divison by zero bug
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Republics decline into democracies and democracies degenerate into
despotisms. -- Aristotle
-------------- 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/20091211/05eabb6f/attachment.pgp>
More information about the ffmpeg-devel
mailing list