Skip to content

Commit

Permalink
(experimental) loop2 to get fresh audio just before drawing
Browse files Browse the repository at this point in the history
* introducing usermod::loop2() - runs just before strip.service()
--> expecting to reduce lagging between audio and visual to an absolute minimum.
  • Loading branch information
softhack007 committed Sep 21, 2024
1 parent e100a2d commit f1088bb
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions usermods/audioreactive/audio_reactive.h
Original file line number Diff line number Diff line change
Expand Up @@ -2352,6 +2352,11 @@ class AudioReactive : public Usermod {
#endif
}

#if defined(_MoonModules_WLED_) && defined(WLEDMM_FASTPATH)
void loop2(void) {
loop();
}
#endif

bool getUMData(um_data_t **data)
{
Expand Down
2 changes: 2 additions & 0 deletions wled00/fcn_declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ class Usermod {
virtual ~Usermod() { if (um_data) delete um_data; }
virtual void setup() = 0; // pure virtual, has to be overriden
virtual void loop() = 0; // pure virtual, has to be overriden
virtual void loop2() {} // WLEDMM called just before effects will be processed
virtual void handleOverlayDraw() {} // called after all effects have been processed, just before strip.show()
virtual bool handleButton(uint8_t b) { return false; } // button overrides are possible here
virtual bool getUMData(um_data_t **data) { if (data) *data = nullptr; return false; }; // usermod data exchange [see examples for audio effects]
Expand Down Expand Up @@ -329,6 +330,7 @@ class UsermodManager {

public:
void loop();
void loop2(); // WLEDMM loop just before drawing effects (presets and everything already handled)
void handleOverlayDraw();
bool handleButton(uint8_t b);
bool getUMData(um_data_t **um_data, uint8_t mod_id = USERMOD_ID_RESERVED); // USERMOD_ID_RESERVED will poll all usermods
Expand Down
1 change: 1 addition & 0 deletions wled00/um_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ void UsermodManager::connected() { for (byte i = 0; i < numMods; i++) um
void UsermodManager::loop() { for (byte i = 0; i < numMods; i++) ums[i]->loop(); }
void UsermodManager::handleOverlayDraw() { for (byte i = 0; i < numMods; i++) ums[i]->handleOverlayDraw(); }
// void UsermodManager::appendConfigData() { for (byte i = 0; i < numMods; i++) ums[i]->appendConfigData(); } //WLEDMM not used
void UsermodManager::loop2() { for (unsigned i = 0; i < numMods; i++) ums[i]->loop2(); }
bool UsermodManager::handleButton(uint8_t b) {
bool overrideIO = false;
for (byte i = 0; i < numMods; i++) {
Expand Down
13 changes: 13 additions & 0 deletions wled00/wled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,19 @@ void WLED::loop()
handlePresets();
yield();

#if defined(_MoonModules_WLED_) && defined(WLEDMM_FASTPATH)
#ifdef WLED_DEBUG
unsigned long usermod2Millis = millis();
#endif
usermods.loop2();
#ifdef WLED_DEBUG
usermod2Millis = millis() - usermod2Millis;
avgUsermodMillis += usermod2Millis;
if (usermod2Millis > maxUsermodMillis) maxUsermodMillis = usermod2Millis;
#endif
yield();
#endif

#ifdef WLED_DEBUG
unsigned long stripMillis = millis();
#endif
Expand Down
2 changes: 1 addition & 1 deletion wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

// version code in format yymmddb (b = daily build)
#define VERSION 2409060
#define VERSION 2409210

// WLEDMM - you can check for this define in usermods, to only enabled WLEDMM specific code in the "right" fork. Its not defined in AC WLED.
#define _MoonModules_WLED_
Expand Down

0 comments on commit f1088bb

Please sign in to comment.