BogaudioModules

BogaudioModules for VCV Rack
Log | Files | Refs | README | LICENSE

commit 6e4202622ab37924ff524866b5c971f4bc78daa4
parent 98cb5a4e4558754b748ee5cad0d351f960fd8514
Author: Matt Demanett <matt@demanett.net>
Date:   Sat, 21 Apr 2018 20:23:54 -0400

Fixed-point arithmetic in oscillator table lookup.

Diffstat:
Msrc/dsp/oscillator.cpp | 11++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/dsp/oscillator.cpp b/src/dsp/oscillator.cpp @@ -56,15 +56,20 @@ float Phasor::_nextForPhase(phase_t phase) { float TablePhasor::_nextForPhase(phase_t phase) { + if (_tableLength >= 1024) { + int i = (((((uint64_t)phase) << 16) / maxPhase) * _tableLength) >> 16; + if (i >= _tableLength) { + i %= _tableLength; + } + return _table.value(i); + } + float fi = (phase / (float)maxPhase) * _tableLength; int i = (int)fi; if (i >= _tableLength) { i %= _tableLength; } float v1 = _table.value(i); - if (_tableLength >= 1024) { - return v1; - } float v2 = _table.value(i + 1 == _tableLength ? 0 : i + 1); return v1 + (fi - i)*(v2 - v1); }