On Thu, Oct 04, 2012 at 03:08:22AM +0300, Janne Liljeblad wrote:
> - create lookup table: static double gaussian_lookup[32767];
Why 32767 and not 32768? (Also, seemingly, you are only using 32766 of the
values.) You usually either want a power-of-two (for fast mod) or a prime
(for not getting into sync with other factors). Power-of-two-minus-two is
just odd.
> - fill it with original gaussian distributed random values at f0r_init(..)
You still multiply noise and 127.0 together for every single pixel.
Why don't you simply multiply noise by 127.0 at the beginning of the frame?
(You do it as noise * next_gauss() * 127.0; if you'd done (noise * 127.0) *
next_gauss(), the compiler could have done it for you if it had inlined the
function. But I doubt it's going to inline something that big without you
asking explicitly.)
Ideally, you'd just bake the entire noise*127 and float-to-int operation into
the table at frame start. Then you'd do it once for each of the 32768
elements and be done with it.
> - as an anti-pattern measure, randomize lookup range when index overflows
Note that you are creating a bias here; the patterns in the middle of the
array are much more likely to be seen than, say, gaussian_lookup[0..10].
This might not matter, though.
You also don't need the swap logic (it's an impossible-to-predict branch).
You can either use modular arithmetic to wrap around (which would also fix
the bias), or you can generate the first number in [0,32768> and the next in
[n+1,32768>.
/* Steinar */
--
Homepage:
http://www.sesse.net/