Skip to content

Commit

Permalink
AR: fastpath optimizations
Browse files Browse the repository at this point in the history
Some optimizations in FASTPATH mode, to ensure that audio processing takes places as soon as new samples are arriving:
* raise fftTask prio to 4 (above async_tcp) - to ensure that other gimmicks (MQTT, IR, alexa, live preview (ws), json API, or web UI) cannot cause delays by preempting audio.
* changed the "be nice" condition in AR::loop
  • Loading branch information
softhack007 committed Nov 27, 2023
1 parent 8645e5e commit 1ac2443
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions usermods/audioreactive/audio_reactive.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@
//#define SR_STATS

#if !defined(FFTTASK_PRIORITY)
#if defined(WLEDMM_FASTPATH) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && defined(ARDUINO_ARCH_ESP32)
// FASTPATH: use higher priority, to avoid that webserver (ws, json, etc) delays sample processing
//#define FFTTASK_PRIORITY 3 // competing with async_tcp
#define FFTTASK_PRIORITY 4 // above async_tcp
#else
#define FFTTASK_PRIORITY 1 // standard: looptask prio
//#define FFTTASK_PRIORITY 2 // above looptask, below async_tcp
//#define FFTTASK_PRIORITY 4 // above async_tcp
#endif
#endif

#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3)
Expand Down Expand Up @@ -499,6 +504,11 @@ void FFTcode(void * parameter)
}
#endif

#if defined(WLEDMM_FASTPATH) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && defined(ARDUINO_ARCH_ESP32)
// experimental - be nice to LED update task (trying to avoid flickering) - dual core only
if (strip.isServicing()) delay(2);
#endif

// band pass filter - can reduce noise floor by a factor of 50
// downside: frequencies below 100Hz will be ignored
if ((useInputFilter > 0) && (useInputFilter < 99)) {
Expand Down Expand Up @@ -1881,7 +1891,7 @@ class AudioReactive : public Usermod {
return;
}
// We cannot wait indefinitely before processing audio data
if (strip.isUpdating() && (millis() - lastUMRun < 2)) return; // be nice, but not too nice
if (strip.isServicing() && (millis() - lastUMRun < 2)) return; // WLEDMM isServicing() is the critical part (be nice, but not too nice)

// suspend local sound processing when "real time mode" is active (E131, UDP, ADALIGHT, ARTNET)
if ( (realtimeOverride == REALTIME_OVERRIDE_NONE) // please add other overrides here if needed
Expand Down

0 comments on commit 1ac2443

Please sign in to comment.