1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-01-12 15:31:09 +00:00

Wraps log_sin in an access function to enshrine sign and mask rules; switches both functions to non-math.h clashing names.

This commit is contained in:
Thomas Harte 2020-04-17 23:22:42 -04:00
parent 6f7c8b35c5
commit 4a295cd95e

View File

@ -21,6 +21,14 @@ namespace OPL {
*/
struct LogSin {
int logsin;
int sign;
};
/*!
@returns Negative log sin of x, assuming a 1024-unit circle.
*/
constexpr LogSin negative_log_sin(int x) {
/// Defines the first quadrant of 1024-unit negative log to the base two of sine (that conveniently misses sin(0)).
///
/// Expected branchless usage for a full 1024 unit output:
@ -65,11 +73,19 @@ constexpr int16_t log_sin[] = {
2, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0
};
constexpr int16_t sign[] = { 1, -1 };
constexpr int16_t mask[] = { 0, 255 };
return {
.logsin = log_sin[x & 255] ^ mask[(x >> 8) & 1],
.sign = sign[(x >> 9) & 1]
};
}
/*!
@returns 2 ^ -x/256 in 0.10 fixed-point form.
*/
constexpr int exp(int x) {
constexpr int power_two(int x) {
/// A derivative of the exponent table in a real OPL2; mapped_exp[x] = (source[c ^ 0xff] << 1) | 0x800.
///
/// The ahead-of-time transformation represents fixed work the OPL2 does when reading its table