Code
Posted: Fri Aug 27, 2010 9:34 am
Below is a lookup table generator. It simply spits out c code for a pair of lookup tables, each an array of 256 short unsigned integers.
The algorithms come from Olli Niemitalo and Matthew Gambrell link
The algorithms come from Olli Niemitalo and Matthew Gambrell link
- Code: Select all
#include <math.h>
#include <stdio.h>
static unsigned short int expgen (unsigned char input)
{
return (round((pow(2,input/256.0f)-1)*1024));
}
static unsigned short int lsgen (unsigned char input)
{
return (round(-log(sin((input+0.5f)*M_PI/256/2))/log(2)*256));
}
int main (unsigned int argc, char *argv[])
{
unsigned int i;
printf("unsigned short int expTable[] = {\n");
for (i = 0; i < 0x100; i++)
{
if (i)
printf(",\n");
printf("\t0x%04x", expgen(i));
}
printf ("\n};\n\n");
printf("unsigned short int logsinTable[] = {\n");
for (i = 0; i < 0x100; i++)
{
if (i)
printf(",\n");
printf("\t0x%04x", lsgen(i));
}
printf ("\n};\n");
return 0;
}