[FFmpeg-devel] [PATCH] Box-Muller gaussian generator
Vitor Sessak
vitor1001
Sun Dec 6 19:40:20 CET 2009
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?
-Vitor
More information about the ffmpeg-devel
mailing list