commit 01bcf8294df5f09050fb9dc9d40be647f2ea0af1
parent ad1e324f7eaebfa6c6ed04ad853b2a0261883603
Author: Matt Demanett <matt@demanett.net>
Date: Wed, 28 Apr 2021 21:17:23 -0400
TablePhasor: fix lookup bug with small tables. #177
Diffstat:
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/dsp/oscillator.cpp b/src/dsp/oscillator.cpp
@@ -60,14 +60,17 @@ float Phasor::nextForPhase(phase_t phase) {
float TablePhasor::nextForPhase(phase_t phase) {
+ phase %= cyclePhase;
if (_tableLength >= 1024) {
int i = (((((uint64_t)phase) << 16) / cyclePhase) * _tableLength) >> 16;
i %= _tableLength;
return _table.value(i);
}
- float fi = (phase / (float)cyclePhase) * _tableLength;
- int i = (int)fi % _tableLength;
+ float fi = phase / (float)cyclePhase;
+ assert(fi >= 0.0f && fi < 1.0f);
+ fi *= _tableLength;
+ int i = fi;
float v1 = _table.value(i);
float v2 = _table.value(i + 1 == _tableLength ? 0 : i + 1);
return v1 + (fi - i)*(v2 - v1);