Added define for bitshift, removed dithering

dithering is not really needed, the FPS_MULTIPLIER is a much better option.
This commit is contained in:
Damian Schneider 2024-11-04 19:33:42 +01:00
parent 3733715184
commit 4634ace74e
2 changed files with 4 additions and 7 deletions

View File

@ -54,6 +54,7 @@
#ifndef FPS_MULTIPLIER #ifndef FPS_MULTIPLIER
#define FPS_MULTIPLIER 1 // dev option: multiplier to get sub-frame FPS without floats #define FPS_MULTIPLIER 1 // dev option: multiplier to get sub-frame FPS without floats
#endif #endif
#define FPS_CALC_SHIFT 7 // bit shift for fixed point math
/* each segment uses 82 bytes of SRAM memory, so if you're application fails because of /* each segment uses 82 bytes of SRAM memory, so if you're application fails because of
insufficient memory, decreasing MAX_NUM_SEGMENTS may help */ insufficient memory, decreasing MAX_NUM_SEGMENTS may help */
@ -737,7 +738,7 @@ class WS2812FX { // 96 bytes
_transitionDur(750), _transitionDur(750),
_targetFps(WLED_FPS), _targetFps(WLED_FPS),
_frametime(FRAMETIME_FIXED), _frametime(FRAMETIME_FIXED),
_cumulativeFps(50<<7), _cumulativeFps(50 << FPS_CALC_SHIFT),
_isServicing(false), _isServicing(false),
_isOffRefreshRequired(false), _isOffRefreshRequired(false),
_hasWhiteChannel(false), _hasWhiteChannel(false),

View File

@ -1414,7 +1414,7 @@ void WS2812FX::show() {
size_t diff = showNow - _lastShow; size_t diff = showNow - _lastShow;
if (diff > 0) { // skip calculation if no time has passed if (diff > 0) { // skip calculation if no time has passed
size_t fpsCurr = (1000<<7) / diff; // fixed point 9.7 bit size_t fpsCurr = (1000 << FPS_CALC_SHIFT) / diff; // fixed point math
_cumulativeFps = (FPS_CALC_AVG * _cumulativeFps + fpsCurr + FPS_CALC_AVG / 2) / (FPS_CALC_AVG + 1); // "+FPS_CALC_AVG/2" for proper rounding _cumulativeFps = (FPS_CALC_AVG * _cumulativeFps + fpsCurr + FPS_CALC_AVG / 2) / (FPS_CALC_AVG + 1); // "+FPS_CALC_AVG/2" for proper rounding
_lastShow = showNow; _lastShow = showNow;
} }
@ -1434,11 +1434,7 @@ bool WS2812FX::isUpdating() const {
*/ */
uint16_t WS2812FX::getFps() const { uint16_t WS2812FX::getFps() const {
if (millis() - _lastShow > 2000) return 0; if (millis() - _lastShow > 2000) return 0;
#ifdef WLED_DEBUG return (FPS_MULTIPLIER * _cumulativeFps) >> FPS_CALC_SHIFT; // _cumulativeFps is stored in fixed point
return (FPS_MULTIPLIER * (_cumulativeFps + (random16() & 63))) >> 7; // + random("0.5") for dithering
#else
return (FPS_MULTIPLIER * _cumulativeFps) >> 7; // _cumulativeFps is stored in fixed point 9.7 bit
#endif
} }
void WS2812FX::setTargetFps(uint8_t fps) { void WS2812FX::setTargetFps(uint8_t fps) {