BogaudioModules

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

commit 2ac29ff8af0ac99683dbd2b42a8602bf424d96da
parent 85d66a357f252daf04e52050199930a503fe70d3
Author: Matt Demanett <matt@demanett.net>
Date:   Fri, 25 Sep 2020 00:29:30 -0400

Analyzers: plot points so that they lay in the center of the bin frequencies rather than at the low bound.

Diffstat:
Msrc/analyzer_base.cpp | 17+++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/analyzer_base.cpp b/src/analyzer_base.cpp @@ -813,10 +813,12 @@ void AnalyzerDisplay::drawGraph( float rangeMaxHz, AmplitudePlot ampPlot ) { - float range = (rangeMaxHz - rangeMinHz) / (0.5f * APP->engine->getSampleRate()); - int pointsN = roundf(range * (_module->_core._size / 2)); - range = rangeMinHz / (0.5f * APP->engine->getSampleRate()); - int pointsOffset = roundf(range * (_module->_core._size / 2)); + float nyquist = 0.5f * APP->engine->getSampleRate(); + int binsN = _module->_core._size / _module->_core._binAverageN; + float binHz = nyquist / (float)binsN; + float range = (rangeMaxHz - rangeMinHz) / nyquist; + int pointsN = roundf(binsN * range); + int pointsOffset = roundf(binsN * (rangeMinHz / nyquist)); nvgSave(args.vg); nvgScissor(args.vg, _insetLeft, _insetTop, _graphSize.x, _graphSize.y); nvgStrokeColor(args.vg, color); @@ -827,10 +829,9 @@ void AnalyzerDisplay::drawGraph( if (i == 0) { nvgMoveTo(args.vg, _insetLeft, _insetTop + (_graphSize.y - height)); } - else { - float x = _graphSize.x * powf(i / (float)pointsN, _xAxisLogFactor); - nvgLineTo(args.vg, _insetLeft + x, _insetTop + (_graphSize.y - height)); - } + float hz = ((float)(pointsOffset + i) + 0.5f) * binHz; + float x = _graphSize.x * powf((hz - rangeMinHz) / (rangeMaxHz - rangeMinHz), _xAxisLogFactor); + nvgLineTo(args.vg, _insetLeft + x, _insetTop + (_graphSize.y - height)); } nvgStroke(args.vg); nvgRestore(args.vg);