Skip to content

Commit

Permalink
add lookup_waveshape function (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
luismrguimaraes authored Sep 13, 2024
1 parent a0d3fab commit b2e00f3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions include/sst/waveshapers/WaveshaperTables.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ struct WaveshaperTables
};

const static WaveshaperTables globalWaveshaperTables;

static inline double lookup_waveshape(sst::waveshapers::WaveshaperType entry, double x)
{
x *= 32.f;
x += 512.f;
int e = (int)x;
float a = x - (float)e;

if (e > 0x3fd)
return 1;
if (e < 1)
return -1;

const auto &waveshapers = globalWaveshaperTables.waveshapers[(int)entry];
return (1 - a) * waveshapers[e & 0x3ff] + a * waveshapers[(e + 1) & 0x3ff];
}
} // namespace sst::waveshapers

#endif // SST_WAVESHAPERS_WAVESHAPERTABLES_H

0 comments on commit b2e00f3

Please sign in to comment.