From 0317f964f43995d26d4a54d2f7d37b686ee5a97b Mon Sep 17 00:00:00 2001 From: flatmush Date: Fri, 25 Feb 2011 15:32:23 +0000 Subject: Added option to replace sin function with ~384KiB look-up table for fastest and most accurate results. Added tool to generate sin tables. Tests indicate that using a lut is still ~2.1% out from sinf so it's very possible that our sin function is more accurate than the libmath sinf function on the computer I'm testing with. In which case the accuracy results are offset by that amount. --- fixsingen/fixsingen.cbp | 48 ++++++++++++++++++++++++++++++++++++++++++++++ fixsingen/fixsingen.depend | 22 +++++++++++++++++++++ fixsingen/main.c | 35 +++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 fixsingen/fixsingen.cbp create mode 100644 fixsingen/fixsingen.depend create mode 100644 fixsingen/main.c (limited to 'fixsingen') diff --git a/fixsingen/fixsingen.cbp b/fixsingen/fixsingen.cbp new file mode 100644 index 0000000..7282665 --- /dev/null +++ b/fixsingen/fixsingen.cbp @@ -0,0 +1,48 @@ + + + + + + diff --git a/fixsingen/fixsingen.depend b/fixsingen/fixsingen.depend new file mode 100644 index 0000000..c4ab73e --- /dev/null +++ b/fixsingen/fixsingen.depend @@ -0,0 +1,22 @@ +# depslib dependency file v1.0 +1298645188 source:g:\vrfx\libfixmath\fixsingen\main.c + + + + + + +1298453688 g:\vrfx\libfixmath\\libfixmath\fixmath.h + "uint32.h" + "fract32.h" + "fix16.h" + +1298453688 g:\vrfx\libfixmath\\libfixmath\uint32.h + + +1298453688 g:\vrfx\libfixmath\\libfixmath\fract32.h + + +1298634082 g:\vrfx\libfixmath\\libfixmath\fix16.h + + diff --git a/fixsingen/main.c b/fixsingen/main.c new file mode 100644 index 0000000..ce71647 --- /dev/null +++ b/fixsingen/main.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include + +int main(int argc, char** argv) { + FILE* fp = fopen("fix16_trig_sin_lut.h", "wb"); + if(fp == NULL) { + fprintf(stderr, "Error: Unable to open file for writing.\n"); + return EXIT_FAILURE; + } + + fprintf(fp, "#ifndef __fix16_trig_sin_lut_h__\n"); + fprintf(fp, "#define __fix16_trig_sin_lut_h__\n"); + fprintf(fp, "\n"); + + fprintf(fp, "static fix16_t _fix16_sin_lut[%"PRIi32"] = {", (fix16_pi >> 1)); + + uintptr_t i; + for(i = 0; i < (fix16_pi >> 1); i++) { + if((i & 7) == 0) + fprintf(fp, "\n\t"); + fix16_t fix16_sin_lut = fix16_from_dbl(sin(fix16_to_dbl(i))); + fprintf(fp, "%"PRIi32", ", fix16_sin_lut); + } + fprintf(fp, "\n\t};\n"); + + fprintf(fp, "\n"); + fprintf(fp, "#endif\n"); + + fclose(fp); + + return EXIT_SUCCESS; +} -- cgit v1.2.3