[FFmpeg-devel] [PATCH] Box-Muller gaussian generator

Stefano Sabatini stefano.sabatini-lala
Sun Dec 6 23:13:37 CET 2009


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.

Regards.
-- 
FFmpeg = Faboulous and Free MultiPurpose Erroneous Ghost
-------------- next part --------------
A non-text attachment was scrubbed...
Name: implement-bmg.patch
Type: text/x-diff
Size: 4164 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20091206/7a9741dd/attachment.patch>



More information about the ffmpeg-devel mailing list