3#include "util/lookuptables/lookuptables.h"
5#define CONG (jcong = 69069 * jcong + 1234567)
7extern uint32_t z, w, jcong;
15[[gnu::always_inline]]
inline int32_t interpolateTableSigned(uint32_t input, int32_t numBitsInInput,
16 const int16_t* table, int32_t numBitsInTableSize = 8) {
17 int32_t whichValue = input >> (numBitsInInput - numBitsInTableSize);
18 int32_t rshiftAmount = numBitsInInput - 16 - numBitsInTableSize;
20 if (rshiftAmount >= 0)
21 rshifted = input >> rshiftAmount;
23 rshifted = input << (-rshiftAmount);
24 int32_t strength2 = rshifted & 65535;
25 int32_t strength1 = 65536 - strength2;
26 return (int32_t)table[whichValue] * strength1 + (int32_t)table[whichValue + 1] * strength2;
29[[gnu::always_inline]]
inline int32_t getSine(uint32_t phase, uint8_t numBitsInInput = 32) {
30 return interpolateTableSigned(phase, numBitsInInput, sineWaveSmall, 8);
33[[gnu::always_inline]]
inline int32_t getSquare(uint32_t phase, uint32_t phaseWidth = 2147483648u) {
34 return ((phase >= phaseWidth) ? (-2147483648) : 2147483647);
37[[gnu::always_inline]]
inline int32_t getSquareSmall(uint32_t phase, uint32_t phaseWidth = 2147483648u) {
38 return ((phase >= phaseWidth) ? (-1073741824) : 1073741823);
47[[gnu::always_inline]]
inline int32_t getTriangleSmall(uint32_t phase) {
48 if (phase >= 2147483648u)
50 return phase - 1073741824;
53[[gnu::always_inline]]
inline int32_t getTriangle(uint32_t phase) {
55 int32_t offset = 0x80000000u;
56 if (phase >= 0x80000000u) {
58 offset = 0x80000000u - 1;
60 return slope * phase + offset;