-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
34 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
#include "xtrig.h" | ||
|
||
double sine_lookup[LUT_SIZE]; | ||
double sine_lut[LUT_SIZE]; | ||
|
||
void init_lookup_tables() { | ||
void ftrig_init_lut() { | ||
for (int i = 0; i < LUT_SIZE; i++) | ||
sine_lookup[i] = sin(i * LUT_BIN_SIZE); | ||
sine_lut[i] = sin(i * LUT_BIN_SIZE); | ||
} | ||
|
||
/** Get the index of an angle in the LUT */ | ||
static int get_lookup_index(double rad) { | ||
return (int) round(rad / LUT_BIN_SIZE); | ||
} | ||
|
||
double xsin(double rad) { | ||
double fsin(double rad) { | ||
// use the period and symmetry to compute based off [0, pi/2] | ||
rad = fmod(rad, 2*M_PI); | ||
if (rad < 0) rad += 2*M_PI; | ||
if (rad <= HALF_PI) { | ||
return sine_lookup[get_lookup_index(rad)]; | ||
return sine_lut[get_lookup_index(rad)]; | ||
} else if (rad <= M_PI) { | ||
return sine_lookup[get_lookup_index(M_PI - rad)]; | ||
return sine_lut[get_lookup_index(M_PI - rad)]; | ||
} else if (rad <= 3*HALF_PI) { | ||
return -sine_lookup[get_lookup_index(rad - M_PI)]; | ||
return -sine_lut[get_lookup_index(rad - M_PI)]; | ||
} else { | ||
return -sine_lookup[get_lookup_index(2*M_PI - rad)]; | ||
return -sine_lut[get_lookup_index(2*M_PI - rad)]; | ||
} | ||
} | ||
|
||
double xcos(double rad) { | ||
return xsin(HALF_PI - rad); | ||
double fcos(double rad) { | ||
return fsin(HALF_PI - rad); | ||
} | ||
|