:: Re: [Frei0r] "rgbnoise" plugin
Top Pagina
Delete this message
Reply to this message
Auteur: Steinar H. Gunderson
Datum:  
Aan: Minimalistic plugin API for video effects
Onderwerp: Re: [Frei0r] "rgbnoise" plugin
On Thu, Oct 04, 2012 at 06:02:55PM +0300, Janne Liljeblad wrote:
> Yes I'm serious, off-by-one stuff is just boring, just add -1 and be
> sure that you're within bounds here. I do not care if I'm using 32766
> values of the 32767 I've created, I do this kind of stuff often to
> avoid correct, but unneeded thinking.


So, the simple solution is to have a 32768-element array, and just use
rand() % 32768. No off-by-ones needed. If you are on a PDP-11 and RAND_MAX
is 32767, that's still fine; you just don't use all the elements.
(Then again, if you're on a PDP-11, you probably have other problems.)

>> Ideally, you'd just bake the entire noise*127 and float-to-int operation into
>> the table at frame start.
> Where's the unneccessary branch?


You generate two values in [0,32768> and then swap if a > b. That's not
needed; you can just generate a=[0,32768> and b=[a,32768>, and you will be
guaranteed that a <= b without any branch.

> Besides, isn't the table lookup int-to-float instead of float-to-int?


Yes, after the table lookup you have a float. The output of your filter is
not a float; it's an int, and thus, you need a float-to-int conversion
(in your case, you use an explicit cast to int). That conversion is not free
(although it is relatively cheap if you have SSE2).

/* Steinar */
--
Homepage: http://www.sesse.net/