From a44c14aa9e37efaf9e2573b8fd4a429630eaa5e9 Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Tue, 25 Jul 2023 19:47:57 +0100 Subject: [PATCH 01/24] Attempt at creating audio sync listen EPS8266 --- platformio.ini | 1 + usermods/audioreactive/audio_reactive.h | 94 +++++++++++++++---------- usermods/audioreactive/audio_source.h | 3 +- 3 files changed, 59 insertions(+), 39 deletions(-) diff --git a/platformio.ini b/platformio.ini index a8db8f4c..eadc0a73 100644 --- a/platformio.ini +++ b/platformio.ini @@ -261,6 +261,7 @@ build_flags = -DVTABLES_IN_FLASH ; restrict to minimal mime-types -DMIMETYPE_MINIMAL + -D USERMOD_AUDIOREACTIVE lib_deps = #https://github.com/lorol/LITTLEFS.git diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index 12ce9bf1..74131c91 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -1,11 +1,13 @@ #pragma once #include "wled.h" + +#ifdef ARDUINO_ARCH_ESP32 + #include #include +#include -#ifndef ARDUINO_ARCH_ESP32 - #error This audio reactive usermod does not support the ESP8266. #endif #if defined(WLED_DEBUG) || defined(SR_DEBUG) @@ -66,6 +68,28 @@ #define PLOT_FLUSH() #endif +static volatile bool disableSoundProcessing = false; // if true, sound processing (FFT, filters, AGC) will be suspended. "volatile" as its shared between tasks. +static uint8_t audioSyncEnabled = 0; // bit field: bit 0 - send, bit 1 - receive (config value) +static bool udpSyncConnected = false; // UDP connection status -> true if connected to multicast group + +#define NUM_GEQ_CHANNELS 16 // number of frequency channels. Don't change !! + +// audioreactive variables +static float micDataReal = 0.0f; // MicIn data with full 24bit resolution - lowest 8bit after decimal point +static float multAgc = 1.0f; // sample * multAgc = sampleAgc. Our AGC multiplier +static float sampleAvg = 0.0f; // Smoothed Average sample - sampleAvg < 1 means "quiet" (simple noise gate) +static float sampleAgc = 0.0f; // Smoothed AGC sample +static float volumeSmth = 0.0f; // either sampleAvg or sampleAgc depending on soundAgc; smoothed sample +static float FFT_MajorPeak = 1.0f; // FFT: strongest (peak) frequency +static float FFT_Magnitude = 0.0f; // FFT: volume (magnitude) of peak frequency +static bool samplePeak = false; // Boolean flag for peak - used in effects. Responding routine may reset this flag. Auto-reset after strip.getMinShowDelay() +static bool udpSamplePeak = false; // Boolean flag for peak. Set at the same tiem as samplePeak, but reset by transmitAudioData +static unsigned long timeOfPeak = 0; // time of last sample peak detection. +static uint8_t fftResult[NUM_GEQ_CHANNELS]= {0};// Our calculated freq. channel result table to be used by effects + + +#ifdef ARDUINO_ARCH_ESP32 + // use audio source class (ESP32 specific) #include "audio_source.h" constexpr i2s_port_t I2S_PORT = I2S_NUM_0; // I2S port to use (do not change !) @@ -84,8 +108,6 @@ static uint8_t inputLevel = 128; // UI slider value uint8_t sampleGain = SR_GAIN; // sample gain (config value) #endif static uint8_t soundAgc = 1; // Automagic gain control: 0 - none, 1 - normal, 2 - vivid, 3 - lazy (config value) -static uint8_t audioSyncEnabled = 0; // bit field: bit 0 - send, bit 1 - receive (config value) -static bool udpSyncConnected = false; // UDP connection status -> true if connected to multicast group // user settable parameters for limitSoundDynamics() static bool limiterOn = true; // bool: enable / disable dynamics limiter @@ -120,7 +142,6 @@ const float agcSampleSmooth[AGC_NUM_PRESETS] = { 1/12.f, 1/6.f, 1/16.f}; // // AGC presets end static AudioSource *audioSource = nullptr; -static volatile bool disableSoundProcessing = false; // if true, sound processing (FFT, filters, AGC) will be suspended. "volatile" as its shared between tasks. static uint8_t useInputFilter = 0; // enables low-cut filtering. Applies before FFT. //WLEDMM add experimental settings @@ -132,23 +153,14 @@ static uint8_t averageByRMS = true; // false: use mean val #endif static uint8_t freqDist = 0; // 0=old 1=rightshift mode -// audioreactive variables shared with FFT task -static float micDataReal = 0.0f; // MicIn data with full 24bit resolution - lowest 8bit after decimal point -static float multAgc = 1.0f; // sample * multAgc = sampleAgc. Our AGC multiplier -static float sampleAvg = 0.0f; // Smoothed Average sample - sampleAvg < 1 means "quiet" (simple noise gate) -static float sampleAgc = 0.0f; // Smoothed AGC sample // variables used in effects -static float volumeSmth = 0.0f; // either sampleAvg or sampleAgc depending on soundAgc; smoothed sample //static int16_t volumeRaw = 0; // either sampleRaw or rawSampleAgc depending on soundAgc //static float my_magnitude =0.0f; // FFT_Magnitude, scaled by multAgc // peak detection -static bool samplePeak = false; // Boolean flag for peak - used in effects. Responding routine may reset this flag. Auto-reset after strip.getMinShowDelay() static uint8_t maxVol = 31; // (was 10) Reasonable value for constant volume for 'peak detector', as it won't always trigger (deprecated) static uint8_t binNum = 8; // Used to select the bin for FFT based beat detection (deprecated) -static bool udpSamplePeak = false; // Boolean flag for peak. Set at the same tiem as samplePeak, but reset by transmitAudioData -static unsigned long timeOfPeak = 0; // time of last sample peak detection. static void detectSamplePeak(void); // peak detection function (needs scaled FFT reasults in vReal[]) static void autoResetPeak(void); // peak auto-reset function @@ -174,7 +186,6 @@ void FFTcode(void * parameter); // audio processing task: read samples, run static void runMicFilter(uint16_t numSamples, float *sampleBuffer); // pre-filtering of raw samples (band-pass) static void postProcessFFTResults(bool noiseGateOpen, int numberOfChannels); // post-processing and post-amp of GEQ channels -#define NUM_GEQ_CHANNELS 16 // number of frequency channels. Don't change !! static TaskHandle_t FFT_Task = nullptr; @@ -230,10 +241,7 @@ static const float fftResultPink[MAX_PINK+1][NUM_GEQ_CHANNELS] = { */ // globals and FFT Output variables shared with animations -static float FFT_MajorPeak = 1.0f; // FFT: strongest (peak) frequency -static float FFT_Magnitude = 0.0f; // FFT: volume (magnitude) of peak frequency static float FFT_MajPeakSmth = 1.0f; // FFT: (peak) frequency, smooth -static uint8_t fftResult[NUM_GEQ_CHANNELS]= {0};// Our calculated freq. channel result table to be used by effects #if defined(WLED_DEBUG) || defined(SR_DEBUG) || defined(SR_STATS) static float fftTaskCycle = 0; // avg cycle time for FFT task static float fftTime = 0; // avg time for single FFT @@ -303,7 +311,6 @@ static float windowWeighingFactors[samplesFFT] = {0.0f}; // around 50% slower on -S2 // lib_deps += https://github.com/blazoncek/arduinoFFT.git #endif -#include #ifdef UM_AUDIOREACTIVE_USE_NEW_FFT static ArduinoFFT FFT = ArduinoFFT( vReal, vImag, samplesFFT, SAMPLE_RATE, windowWeighingFactors); @@ -820,7 +827,7 @@ static void autoResetPeak(void) { } } - +#endif //////////////////// // usermod class // //////////////////// @@ -829,6 +836,8 @@ static void autoResetPeak(void) { class AudioReactive : public Usermod { private: +#ifdef ARDUINO_ARCH_ESP32 + #ifndef AUDIOPIN int8_t audioPin = -1; #else @@ -870,7 +879,7 @@ class AudioReactive : public Usermod { #else int8_t mclkPin = MCLK_PIN; #endif - +#endif // new "V2" audiosync struct - 40 Bytes struct audioSyncPacket { char header[6]; // 06 Bytes @@ -1032,6 +1041,7 @@ class AudioReactive : public Usermod { #endif // FFT_SAMPLING_LOG } // logAudio() +#ifdef ARDUINO_ARCH_ESP32 ////////////////////// // Audio Processing // @@ -1328,7 +1338,7 @@ class AudioReactive : public Usermod { last_volumeSmth = volumeSmth; last_time = millis(); } - +#endif ////////////////////// // UDP Sound Sync // @@ -1357,7 +1367,7 @@ class AudioReactive : public Usermod { last_connection_attempt = millis(); connected(); // try to start UDP } - +#ifdef ARDUINO_ARCH_ESP32 void transmitAudioData() { if (!udpSyncConnected) return; @@ -1385,7 +1395,7 @@ class AudioReactive : public Usermod { } return; } // transmitAudioData() - +#endif static bool isValidUdpSyncVersion(const char *header) { return strncmp_P(header, PSTR(UDP_SYNC_HEADER), 6) == 0; } @@ -1536,6 +1546,8 @@ class AudioReactive : public Usermod { um_data->u_type[10] = UMT_FLOAT; } +#ifdef ARDUINO_ARCH_ESP32 + // Reset I2S peripheral for good measure i2s_driver_uninstall(I2S_NUM_0); // E (696) I2S: i2s_driver_uninstall(2006): I2S port 0 has not installed #if !defined(CONFIG_IDF_TARGET_ESP32C3) @@ -1619,10 +1631,11 @@ class AudioReactive : public Usermod { delay(250); // give microphone enough time to initialise if (!audioSource) enabled = false; // audio failed to initialise - if (enabled) onUpdateBegin(false); // create FFT task if (FFT_Task == nullptr) enabled = false; // FFT task creation failed +#endif + if (enabled) onUpdateBegin(false); // create FFT task if (enabled) disableSoundProcessing = false; // all good - enable audio processing - +#ifdef ARDUINO_ARCH_ESP32 if((!audioSource) || (!audioSource->isInitialized())) { // audio source failed to initialize. Still stay "enabled", as there might be input arriving via UDP Sound Sync #ifdef WLED_DEBUG DEBUG_PRINTLN(F("AR: Failed to initialize sound input driver. Please check input PIN settings.")); @@ -1633,7 +1646,7 @@ class AudioReactive : public Usermod { } else { USER_PRINTLN(F("AR: sound input driver initialized successfully.")); } - +#endif // try to start UDP last_UDPTime = 0; receivedFormat = 0; @@ -1723,6 +1736,7 @@ class AudioReactive : public Usermod { if (audioSyncEnabled & 0x02) disableSoundProcessing = true; // make sure everything is disabled IF in audio Receive mode if (audioSyncEnabled & 0x01) disableSoundProcessing = false; // keep running audio IF we're in audio Transmit mode +#ifdef ARDUINO_ARCH_ESP32 if (!audioSource->isInitialized()) disableSoundProcessing = true; // no audio source @@ -1776,6 +1790,7 @@ class AudioReactive : public Usermod { } limitSampleDynamics(); } // if (!disableSoundProcessing) +#endif autoResetPeak(); // auto-reset sample peak after strip minShowDelay if (!udpSyncConnected) udpSamplePeak = false; // reset UDP samplePeak while UDP is unconnected @@ -1832,13 +1847,14 @@ class AudioReactive : public Usermod { if ((sampleAvg >= 1)) maxSample5sec = fmaxf(maxSample5sec, (soundAgc) ? rawSampleAgc : sampleRaw); // follow maximum volume } +#ifdef ARDUINO_ARCH_ESP32 //UDP Microphone Sync - transmit mode if ((audioSyncEnabled & 0x01) && (millis() - lastTime > 20)) { // Only run the transmit code IF we're in Transmit mode transmitAudioData(); lastTime = millis(); } - +#endif } @@ -1850,6 +1866,7 @@ class AudioReactive : public Usermod { } +#ifdef ARDUINO_ARCH_ESP32 void onUpdateBegin(bool init) { #ifdef WLED_DEBUG @@ -1921,7 +1938,7 @@ class AudioReactive : public Usermod { } return false; } - +#endif //////////////////////////// // Settings and Info Page // @@ -1976,7 +1993,7 @@ class AudioReactive : public Usermod { } // The following can be used for troubleshooting user errors and is so not enclosed in #ifdef WLED_DEBUG - +#ifdef ARDUINO_ARCH_ESP32 // current Audio input infoArr = user.createNestedArray(F("Audio Source")); if (audioSyncEnabled & 0x02) { @@ -2037,7 +2054,7 @@ class AudioReactive : public Usermod { infoArr.add(roundf(multAgc*100.0f) / 100.0f); infoArr.add("x"); } - +#endif // UDP Sound Sync status infoArr = user.createNestedArray(F("UDP Sound Sync")); if (audioSyncEnabled) { @@ -2156,7 +2173,7 @@ class AudioReactive : public Usermod { { JsonObject top = root.createNestedObject(FPSTR(_name)); top[FPSTR(_enabled)] = enabled; - +#ifdef ARDUINO_ARCH_ESP32 #if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) JsonObject amic = top.createNestedObject(FPSTR(_analogmic)); amic["pin"] = audioPin; @@ -2191,7 +2208,7 @@ class AudioReactive : public Usermod { JsonObject freqScale = top.createNestedObject("frequency"); freqScale[F("scale")] = FFTScalingMode; freqScale[F("profile")] = pinkIndex; //WLEDMM - +#endif JsonObject sync = top.createNestedObject("sync"); sync[F("port")] = audioSyncPort; sync[F("mode")] = audioSyncEnabled; @@ -2219,7 +2236,7 @@ class AudioReactive : public Usermod { bool configComplete = !top.isNull(); configComplete &= getJsonValue(top[FPSTR(_enabled)], enabled); - +#ifdef ARDUINO_ARCH_ESP32 #if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) configComplete &= getJsonValue(top[FPSTR(_analogmic)]["pin"], audioPin); #else @@ -2260,7 +2277,7 @@ class AudioReactive : public Usermod { configComplete &= getJsonValue(top["frequency"][F("scale")], FFTScalingMode); configComplete &= getJsonValue(top["frequency"][F("profile")], pinkIndex); //WLEDMM - +#endif configComplete &= getJsonValue(top["sync"][F("port")], audioSyncPort); configComplete &= getJsonValue(top["sync"][F("mode")], audioSyncEnabled); @@ -2271,7 +2288,7 @@ class AudioReactive : public Usermod { void appendConfigData() { oappend(SET_F("addInfo('AudioReactive:help',0,'');")); - +#ifdef ARDUINO_ARCH_ESP32 //WLEDMM: add defaults #if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) // -S3/-S2/-C3 don't support analog audio #ifdef AUDIOPIN @@ -2427,13 +2444,13 @@ class AudioReactive : public Usermod { oappend(SET_F("addOption(dd,'userdefined #2',9);")); #endif oappend(SET_F("addInfo('AudioReactive:frequency:profile',1,'☾');")); - +#endif oappend(SET_F("dd=addDropdown('AudioReactive','sync:mode');")); oappend(SET_F("addOption(dd,'Off',0);")); oappend(SET_F("addOption(dd,'Send',1);")); oappend(SET_F("addOption(dd,'Receive',2);")); oappend(SET_F("addInfo('AudioReactive:digitalmic:type',1,'requires reboot!');")); // 0 is field type, 1 is actual field - +#ifdef ARDUINO_ARCH_ESP32 oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',0,'sd/data/dout','I2S SD');")); #ifdef I2S_SDPIN oappend(SET_F("xOpt('AudioReactive:digitalmic:pin[]',0,' ⎌',")); oappendi(I2S_SDPIN); oappend(");"); @@ -2473,6 +2490,7 @@ class AudioReactive : public Usermod { oappend(SET_F("xOpt('AudioReactive:digitalmic:pin[]',5,' ⎌',")); oappendi(ES7243_SCLPIN); oappend(");"); #endif oappend(SET_F("dRO('AudioReactive:digitalmic:pin[]',5);")); // disable read only pins +#endif } diff --git a/usermods/audioreactive/audio_source.h b/usermods/audioreactive/audio_source.h index c774a5be..a7c91127 100644 --- a/usermods/audioreactive/audio_source.h +++ b/usermods/audioreactive/audio_source.h @@ -1,5 +1,5 @@ #pragma once - +#ifdef ARDUINO_ARCH_ESP32 #include #include "wled.h" #include @@ -875,3 +875,4 @@ class SPH0654 : public I2SSource { #endif } }; +#endif \ No newline at end of file From 565293ca8c8b3cc6fda8b18a81e721d55a49c01a Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Tue, 25 Jul 2023 19:58:08 +0100 Subject: [PATCH 02/24] Attempt at creating audio sync listen EPS8266 --- usermods/audioreactive/audio_reactive.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index 74131c91..7398b1ce 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -1969,6 +1969,7 @@ class AudioReactive : public Usermod { infoArr.add(uiDomString); if (enabled) { +#ifdef ARDUINO_ARCH_ESP32 // Input Level Slider if (disableSoundProcessing == false) { // only show slider when audio processing is running if (soundAgc > 0) { @@ -1991,7 +1992,7 @@ class AudioReactive : public Usermod { uiDomString += F(" />
"); // infoArr.add(uiDomString); } - +#endif // The following can be used for troubleshooting user errors and is so not enclosed in #ifdef WLED_DEBUG #ifdef ARDUINO_ARCH_ESP32 // current Audio input @@ -2127,9 +2128,11 @@ class AudioReactive : public Usermod { enabled = usermod[FPSTR(_enabled)].as(); if (prevEnabled != enabled) onUpdateBegin(!enabled); } +#ifdef ARDUINO_ARCH_ESP32 if (usermod[FPSTR(_inputLvl)].is()) { inputLevel = min(255,max(0,usermod[FPSTR(_inputLvl)].as())); } +#endif } } From a7e0ba56e4bc67b37d8dc67d0b124d6b062a3f18 Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Tue, 25 Jul 2023 21:19:53 +0100 Subject: [PATCH 03/24] Attempt at creating audio sync listen EPS8266 --- usermods/audioreactive/audio_reactive.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index 7398b1ce..25911fb2 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -2450,7 +2450,9 @@ class AudioReactive : public Usermod { #endif oappend(SET_F("dd=addDropdown('AudioReactive','sync:mode');")); oappend(SET_F("addOption(dd,'Off',0);")); +#ifdef ARDUINO_ARCH_ESP32 oappend(SET_F("addOption(dd,'Send',1);")); +#endif oappend(SET_F("addOption(dd,'Receive',2);")); oappend(SET_F("addInfo('AudioReactive:digitalmic:type',1,'requires reboot!');")); // 0 is field type, 1 is actual field #ifdef ARDUINO_ARCH_ESP32 From 7a417713829cc5d1690bef2dbe3490346a15b818 Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Wed, 26 Jul 2023 02:31:24 +0100 Subject: [PATCH 04/24] Attempt at creating audio sync listen EPS8266 --- usermods/audioreactive/audio_reactive.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index 25911fb2..247630d4 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -819,6 +819,8 @@ static void detectSamplePeak(void) { } } +#endif + static void autoResetPeak(void) { uint16_t MinShowDelay = MAX(50, strip.getMinShowDelay()); // Fixes private class variable compiler error. Unsure if this is the correct way of fixing the root problem. -THATDONFC if (millis() - timeOfPeak > MinShowDelay) { // Auto-reset of samplePeak after a complete frame has passed. @@ -827,7 +829,6 @@ static void autoResetPeak(void) { } } -#endif //////////////////// // usermod class // //////////////////// From 555ea5c9b28a2e76bcbbea658404db1557c68323 Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Thu, 27 Jul 2023 11:57:28 +0100 Subject: [PATCH 05/24] Fix compile errors for soundAgc and limitSoundDynamics - but not ideal, should only be on the sender --- usermods/audioreactive/audio_reactive.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index 247630d4..f1d64668 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -87,6 +87,12 @@ static bool udpSamplePeak = false; // Boolean flag for peak. Set at the same t static unsigned long timeOfPeak = 0; // time of last sample peak detection. static uint8_t fftResult[NUM_GEQ_CHANNELS]= {0};// Our calculated freq. channel result table to be used by effects +static uint8_t soundAgc = 1; // Automagic gain control: 0 - none, 1 - normal, 2 - vivid, 3 - lazy (config value) + +// user settable parameters for limitSoundDynamics() +static bool limiterOn = true; // bool: enable / disable dynamics limiter +static uint16_t attackTime = 50; // int: attack time in milliseconds. Default 0.08sec +static uint16_t decayTime = 300; // int: decay time in milliseconds. New default 300ms. Old default was 1.40sec #ifdef ARDUINO_ARCH_ESP32 @@ -107,12 +113,7 @@ static uint8_t inputLevel = 128; // UI slider value #else uint8_t sampleGain = SR_GAIN; // sample gain (config value) #endif -static uint8_t soundAgc = 1; // Automagic gain control: 0 - none, 1 - normal, 2 - vivid, 3 - lazy (config value) -// user settable parameters for limitSoundDynamics() -static bool limiterOn = true; // bool: enable / disable dynamics limiter -static uint16_t attackTime = 50; // int: attack time in milliseconds. Default 0.08sec -static uint16_t decayTime = 300; // int: decay time in milliseconds. New default 300ms. Old default was 1.40sec // user settable options for FFTResult scaling static uint8_t FFTScalingMode = 3; // 0 none; 1 optimized logarithmic; 2 optimized linear; 3 optimized sqare root #ifndef SR_FREQ_PROF From 3367039605c29a82ce27fa72e62d27c0a146c261 Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Thu, 27 Jul 2023 12:04:53 +0100 Subject: [PATCH 06/24] Fix compile errors for packet type --- usermods/audioreactive/audio_reactive.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index f1d64668..7245ae2b 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -1309,6 +1309,7 @@ class AudioReactive : public Usermod { scaledvalue = (scaledvalue - logMinSample) / (logMaxSample - logMinSample); // 0...1 return fminf(fmaxf(256.0*scaledvalue, 0), 255.0); // scaled value } +#endif /* Limits the dynamics of volumeSmth (= sampleAvg or sampleAgc). @@ -1340,7 +1341,6 @@ class AudioReactive : public Usermod { last_volumeSmth = volumeSmth; last_time = millis(); } -#endif ////////////////////// // UDP Sound Sync // @@ -1399,10 +1399,10 @@ class AudioReactive : public Usermod { } // transmitAudioData() #endif static bool isValidUdpSyncVersion(const char *header) { - return strncmp_P(header, PSTR(UDP_SYNC_HEADER), 6) == 0; + return strncmp_P(header, UDP_SYNC_HEADER, 6) == 0; } static bool isValidUdpSyncVersion_v1(const char *header) { - return strncmp_P(header, PSTR(UDP_SYNC_HEADER_v1), 6) == 0; + return strncmp_P(header, UDP_SYNC_HEADER_v1, 6) == 0; } void decodeAudioData(int packetSize, uint8_t *fftBuff) { From 1b4bd50e26bfeb8018980841a38bb4ff488fceb7 Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Thu, 27 Jul 2023 12:08:42 +0100 Subject: [PATCH 07/24] soundAgc should be none by default --- usermods/audioreactive/audio_reactive.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index 7245ae2b..bcde3261 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -87,7 +87,8 @@ static bool udpSamplePeak = false; // Boolean flag for peak. Set at the same t static unsigned long timeOfPeak = 0; // time of last sample peak detection. static uint8_t fftResult[NUM_GEQ_CHANNELS]= {0};// Our calculated freq. channel result table to be used by effects -static uint8_t soundAgc = 1; // Automagic gain control: 0 - none, 1 - normal, 2 - vivid, 3 - lazy (config value) +// TODO: probably best not used by receive nodes +static uint8_t soundAgc = 0; // Automagic gain control: 0 - none, 1 - normal, 2 - vivid, 3 - lazy (config value) // user settable parameters for limitSoundDynamics() static bool limiterOn = true; // bool: enable / disable dynamics limiter From baff1a96ac0f7151ed93eaa4c054ffef4d06d54d Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Thu, 27 Jul 2023 12:10:26 +0100 Subject: [PATCH 08/24] add comment about limitSoundDynamics --- usermods/audioreactive/audio_reactive.h | 1 + 1 file changed, 1 insertion(+) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index bcde3261..a4955d0c 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -90,6 +90,7 @@ static uint8_t fftResult[NUM_GEQ_CHANNELS]= {0};// Our calculated freq. channel // TODO: probably best not used by receive nodes static uint8_t soundAgc = 0; // Automagic gain control: 0 - none, 1 - normal, 2 - vivid, 3 - lazy (config value) +// TODO: probably best not used by receive nodes // user settable parameters for limitSoundDynamics() static bool limiterOn = true; // bool: enable / disable dynamics limiter static uint16_t attackTime = 50; // int: attack time in milliseconds. Default 0.08sec From e7209db038c8a8db64b33fff0a446d412a4836fb Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Thu, 27 Jul 2023 12:19:13 +0100 Subject: [PATCH 09/24] Fix compile errors for um_data not present on receive node --- usermods/audioreactive/audio_reactive.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index a4955d0c..8bf5d671 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -1538,6 +1538,7 @@ class AudioReactive : public Usermod { um_data->u_type[4] = UMT_FLOAT; um_data->u_data[5] = &my_magnitude; // used (New) um_data->u_type[5] = UMT_FLOAT; +#ifdef ARDUINO_ARCH_ESP32 um_data->u_data[6] = &maxVol; // assigned in effect function from UI element!!! (Puddlepeak, Ripplepeak, Waterfall) um_data->u_type[6] = UMT_BYTE; um_data->u_data[7] = &binNum; // assigned in effect function from UI element!!! (Puddlepeak, Ripplepeak, Waterfall) @@ -1548,6 +1549,7 @@ class AudioReactive : public Usermod { um_data->u_type[9] = UMT_FLOAT; um_data->u_data[10] = &agcSensitivity; // used (New) um_data->u_type[10] = UMT_FLOAT; +#endif } #ifdef ARDUINO_ARCH_ESP32 From 96c19b6c506bb9a6668be775c3e3b4d580d39348 Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Sun, 13 Aug 2023 16:40:43 +0100 Subject: [PATCH 10/24] Revert placement of arduinoFFT.h include as per comments on PR:60 --- usermods/audioreactive/audio_reactive.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index 8bf5d671..05daeb22 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -6,7 +6,6 @@ #include #include -#include #endif @@ -314,6 +313,7 @@ static float windowWeighingFactors[samplesFFT] = {0.0f}; // around 50% slower on -S2 // lib_deps += https://github.com/blazoncek/arduinoFFT.git #endif +#include #ifdef UM_AUDIOREACTIVE_USE_NEW_FFT static ArduinoFFT FFT = ArduinoFFT( vReal, vImag, samplesFFT, SAMPLE_RATE, windowWeighingFactors); From f4a1deba34471cd603ec520e20e790af2ca9ad76 Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Sun, 13 Aug 2023 16:54:16 +0100 Subject: [PATCH 11/24] Expose dynamics - limiter, rise and fall as calc runs on receive too --- usermods/audioreactive/audio_reactive.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index 05daeb22..d9c95719 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -89,7 +89,6 @@ static uint8_t fftResult[NUM_GEQ_CHANNELS]= {0};// Our calculated freq. channel // TODO: probably best not used by receive nodes static uint8_t soundAgc = 0; // Automagic gain control: 0 - none, 1 - normal, 2 - vivid, 3 - lazy (config value) -// TODO: probably best not used by receive nodes // user settable parameters for limitSoundDynamics() static bool limiterOn = true; // bool: enable / disable dynamics limiter static uint16_t attackTime = 50; // int: attack time in milliseconds. Default 0.08sec @@ -2208,16 +2207,16 @@ class AudioReactive : public Usermod { poweruser[F("micLev")] = micLevelMethod; poweruser[F("freqDist")] = freqDist; poweruser[F("freqRMS")] = averageByRMS; - + + JsonObject freqScale = top.createNestedObject("frequency"); + freqScale[F("scale")] = FFTScalingMode; + freqScale[F("profile")] = pinkIndex; //WLEDMM +#endif JsonObject dynLim = top.createNestedObject("dynamics"); dynLim[F("limiter")] = limiterOn; dynLim[F("rise")] = attackTime; dynLim[F("fall")] = decayTime; - JsonObject freqScale = top.createNestedObject("frequency"); - freqScale[F("scale")] = FFTScalingMode; - freqScale[F("profile")] = pinkIndex; //WLEDMM -#endif JsonObject sync = top.createNestedObject("sync"); sync[F("port")] = audioSyncPort; sync[F("mode")] = audioSyncEnabled; @@ -2280,13 +2279,13 @@ class AudioReactive : public Usermod { configComplete &= getJsonValue(top["experiments"][F("freqDist")], freqDist); configComplete &= getJsonValue(top["experiments"][F("freqRMS")], averageByRMS); + configComplete &= getJsonValue(top["frequency"][F("scale")], FFTScalingMode); + configComplete &= getJsonValue(top["frequency"][F("profile")], pinkIndex); //WLEDMM +#endif configComplete &= getJsonValue(top["dynamics"][F("limiter")], limiterOn); configComplete &= getJsonValue(top["dynamics"][F("rise")], attackTime); configComplete &= getJsonValue(top["dynamics"][F("fall")], decayTime); - configComplete &= getJsonValue(top["frequency"][F("scale")], FFTScalingMode); - configComplete &= getJsonValue(top["frequency"][F("profile")], pinkIndex); //WLEDMM -#endif configComplete &= getJsonValue(top["sync"][F("port")], audioSyncPort); configComplete &= getJsonValue(top["sync"][F("mode")], audioSyncEnabled); From f0cc7f04ed51142681b2f6532352291c26147391 Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Sun, 13 Aug 2023 17:11:32 +0100 Subject: [PATCH 12/24] Fix maxVol and binNum --- usermods/audioreactive/audio_reactive.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index d9c95719..6a6e2be4 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -94,6 +94,10 @@ static bool limiterOn = true; // bool: enable / disable dynamics static uint16_t attackTime = 50; // int: attack time in milliseconds. Default 0.08sec static uint16_t decayTime = 300; // int: decay time in milliseconds. New default 300ms. Old default was 1.40sec +// peak detection +static uint8_t maxVol = 31; // (was 10) Reasonable value for constant volume for 'peak detector', as it won't always trigger (deprecated) +static uint8_t binNum = 8; // Used to select the bin for FFT based beat detection (deprecated) + #ifdef ARDUINO_ARCH_ESP32 // use audio source class (ESP32 specific) @@ -1548,6 +1552,20 @@ class AudioReactive : public Usermod { um_data->u_type[9] = UMT_FLOAT; um_data->u_data[10] = &agcSensitivity; // used (New) um_data->u_type[10] = UMT_FLOAT; +#else + // ESP8266 + // See https://github.com/MoonModules/WLED/pull/60#issuecomment-1666972133 for explaination of these alternative sources of data + + um_data->u_data[6] = &maxVol; // assigned in effect function from UI element!!! (Puddlepeak, Ripplepeak, Waterfall) + um_data->u_type[6] = UMT_BYTE; + um_data->u_data[7] = &binNum; // assigned in effect function from UI element!!! (Puddlepeak, Ripplepeak, Waterfall) + um_data->u_type[7] = UMT_BYTE; + um_data->u_data[8] = &FFT_MajorPeak; // new + um_data->u_type[8] = UMT_FLOAT; + um_data->u_data[9] = &volumeSmth; // used (New) + um_data->u_type[9] = UMT_FLOAT; + // um_data->u_data[10] = &agcSensitivity; // used (New) + // um_data->u_type[10] = UMT_FLOAT; #endif } From 0672d1c59db61530318152ef13e419a0ab33c6fa Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Sun, 13 Aug 2023 17:16:11 +0100 Subject: [PATCH 13/24] Fix maxVol and binNum --- usermods/audioreactive/audio_reactive.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index 6a6e2be4..751201ed 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -164,8 +164,6 @@ static uint8_t freqDist = 0; // 0=old 1=rightshift //static float my_magnitude =0.0f; // FFT_Magnitude, scaled by multAgc // peak detection -static uint8_t maxVol = 31; // (was 10) Reasonable value for constant volume for 'peak detector', as it won't always trigger (deprecated) -static uint8_t binNum = 8; // Used to select the bin for FFT based beat detection (deprecated) static void detectSamplePeak(void); // peak detection function (needs scaled FFT reasults in vReal[]) static void autoResetPeak(void); // peak auto-reset function From 1c7d5d766d11aa195099f8bb4f00be7850a34488 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 22 Aug 2023 22:49:01 +0200 Subject: [PATCH 14/24] minor fix for 8266 small typo, resulting in "A0" listed twice in the pin info. --- wled00/pin_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wled00/pin_manager.cpp b/wled00/pin_manager.cpp index 6a1880d1..dd8eb16e 100644 --- a/wled00/pin_manager.cpp +++ b/wled00/pin_manager.cpp @@ -144,7 +144,7 @@ String PinManagerClass::getPinSpecialText(int gpio) { // special purpose PIN in #endif #else // ESP 8266 - if ((gpio == 0) || (gpio == 17)) return (F("analog-in (A0)")); // 17 seems to be an alias for "A0" on 8266 + if ((gpio == A0) || (gpio == 17)) return (F("analog-in (A0)")); // 17 seems to be an alias for "A0" on 8266 #endif From f689d5115bfdd4b2dc17a93352a006dbafca62fe Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 22 Aug 2023 22:55:05 +0200 Subject: [PATCH 15/24] 8266 hotfix: solving connectivity problems * it seems that `WiFiUDP.flsuh()` does something completely different from 8266, and its actually causing WLED to stall on UI calls. So not usable on 8266. * fixing a few compiler warnings about "comparing signed and unsigned" NB: its a hotfix, we have to check if there are other problems on 8266. Also its definitely ugly, but it helps as a band aid. --- usermods/audioreactive/audio_reactive.h | 8 ++++-- wled00/FX.cpp | 2 +- wled00/ntp.cpp | 6 +++++ wled00/udp.cpp | 36 ++++++++++++++++++++----- wled00/wled.h | 5 ++++ wled00/ws.cpp | 2 +- 6 files changed, 49 insertions(+), 10 deletions(-) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index 751201ed..ac0453c5 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -1472,7 +1472,9 @@ class AudioReactive : public Usermod { packetSize = fftUdp.parsePacket(); } catch(...) { packetSize = 0; // low heap memory -> discard packet. - fftUdp.flush(); +#ifdef ARDUINO_ARCH_ESP32 + fftUdp.flush(); // this does not work on 8266 +#endif DEBUG_PRINTLN(F("receiveAudioData: parsePacket out of memory exception caught!")); USER_FLUSH(); } @@ -1828,7 +1830,9 @@ class AudioReactive : public Usermod { if (have_new_sample) last_UDPTime = millis(); lastTime = millis(); } else { - fftUdp.flush(); // WLEDMM: Flush this if we haven't read it. +#ifdef ARDUINO_ARCH_ESP32 + fftUdp.flush(); // WLEDMM: Flush this if we haven't read it. Does not work on 8266. +#endif } if (have_new_sample) syncVolumeSmth = volumeSmth; // remember received sample else volumeSmth = syncVolumeSmth; // restore originally received sample for next run of dynamics limiter diff --git a/wled00/FX.cpp b/wled00/FX.cpp index dc786e54..9a590924 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -5102,7 +5102,7 @@ uint16_t mode_2DLissajous(void) { // By: Andrew Tuline uint_fast16_t phase = (strip.now * (1 + SEGENV.custom3)) /32; // allow user to control rotation speed if (SEGENV.check3) { // WLEDMM: this is the original "float" code featuring anti-aliasing - unsigned maxLoops = max(192, 4*(cols+rows)); + int maxLoops = max(192, 4*(cols+rows)); maxLoops = ((maxLoops / 128) +1) * 128; // make sure whe have half or full turns => multiples of 128 for (int i=0; i < maxLoops; i ++) { float xlocn = float(sin8(phase/2 + (i* SEGMENT.speed)/64)) / 255.0f; // WLEDMM align speed with original effect diff --git a/wled00/ntp.cpp b/wled00/ntp.cpp index c7b82bb8..f139a816 100644 --- a/wled00/ntp.cpp +++ b/wled00/ntp.cpp @@ -226,9 +226,15 @@ void sendNTPPacket() bool checkNTPResponse() { +#ifdef ARDUINO_ARCH_ESP32 ntpUdp.flush(); +#endif int cb = ntpUdp.parsePacket(); +#ifdef ARDUINO_ARCH_ESP32 if (!cb) {ntpUdp.flush(); return false;} // WLEDMM flush buffer +#else + if (!cb) {return false;} // WLEDMM do not flush buffer +#endif uint32_t ntpPacketReceivedTime = millis(); DEBUG_PRINT(F("NTP recv, l=")); diff --git a/wled00/udp.cpp b/wled00/udp.cpp index a9ea2856..c3ea2fda 100644 --- a/wled00/udp.cpp +++ b/wled00/udp.cpp @@ -240,10 +240,14 @@ void handleNotifications() if (!udpConnected) return; bool isSupp = false; +#ifdef ARDUINO_ARCH_ESP32 notifierUdp.flush(); +#endif int packetSize = notifierUdp.parsePacket(); // WLEDMM function returns int, not size_t if ((packetSize < 1) && udp2Connected) { +#ifdef ARDUINO_ARCH_ESP32 notifier2Udp.flush(); +#endif packetSize = notifier2Udp.parsePacket(); isSupp = true; } @@ -251,11 +255,18 @@ void handleNotifications() //hyperion / raw RGB if (!packetSize && udpRgbConnected) { +#ifdef ARDUINO_ARCH_ESP32 rgbUdp.flush(); +#endif packetSize = rgbUdp.parsePacket(); if (packetSize) { +#ifdef ARDUINO_ARCH_ESP32 if (!receiveDirect) {rgbUdp.flush(); notifierUdp.flush(); notifier2Udp.flush(); return;} if (packetSize > UDP_IN_MAXSIZE || packetSize < 3) {rgbUdp.flush(); notifierUdp.flush(); notifier2Udp.flush(); return;} +#else + if (!receiveDirect) {return;} + if (packetSize > UDP_IN_MAXSIZE || packetSize < 3) {return;} +#endif realtimeIP = rgbUdp.remoteIP(); DEBUG_PRINTLN(rgbUdp.remoteIP()); #ifndef ARDUINO_ARCH_ESP32 @@ -263,10 +274,14 @@ void handleNotifications() #endif rgbUdp.read(lbuf, packetSize); realtimeLock(realtimeTimeoutMs, REALTIME_MODE_HYPERION); +#ifdef ARDUINO_ARCH_ESP32 if (realtimeOverride && !(realtimeMode && useMainSegmentOnly)) {notifierUdp.flush(); notifier2Udp.flush(); return;} +#else + if (realtimeOverride && !(realtimeMode && useMainSegmentOnly)) {return;} +#endif uint16_t id = 0; uint16_t totalLen = strip.getLengthTotal(); - for (size_t i = 0; i < packetSize -2; i += 3) + for (int i = 0; i < packetSize -2; i += 3) { setRealtimePixel(id, lbuf[i], lbuf[i+1], lbuf[i+2], 0); id++; if (id >= totalLen) break; @@ -276,12 +291,21 @@ void handleNotifications() } } +#ifdef ARDUINO_ARCH_ESP32 if (!(receiveNotifications || receiveDirect)) {notifierUdp.flush(); notifier2Udp.flush(); return;} +#else + if (!(receiveNotifications || receiveDirect)) {return;} +#endif localIP = Network.localIP(); //notifier and UDP realtime +#ifdef ARDUINO_ARCH_ESP32 if (!packetSize || packetSize > UDP_IN_MAXSIZE) {notifierUdp.flush(); notifier2Udp.flush(); return;} if (!isSupp && notifierUdp.remoteIP() == localIP) {notifierUdp.flush(); notifier2Udp.flush(); return;} //don't process broadcasts we send ourselves +#else + if (!packetSize || packetSize > UDP_IN_MAXSIZE) {return;} + if (!isSupp && notifierUdp.remoteIP() == localIP) {return;} //don't process broadcasts we send ourselves +#endif #ifndef ARDUINO_ARCH_ESP32 uint8_t udpIn[packetSize +1]; // WLEDMM: use global buffer on ESP32 @@ -539,14 +563,14 @@ void handleNotifications() uint16_t totalLen = strip.getLengthTotal(); if (udpIn[0] == 1) //warls { - for (size_t i = 2; i < packetSize -3; i += 4) + for (int i = 2; i < packetSize -3; i += 4) { setRealtimePixel(udpIn[i], udpIn[i+1], udpIn[i+2], udpIn[i+3], 0); } } else if (udpIn[0] == 2) //drgb { uint16_t id = 0; - for (size_t i = 2; i < packetSize -2; i += 3) + for (int i = 2; i < packetSize -2; i += 3) { setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], 0); @@ -555,7 +579,7 @@ void handleNotifications() } else if (udpIn[0] == 3) //drgbw { uint16_t id = 0; - for (size_t i = 2; i < packetSize -3; i += 4) + for (int i = 2; i < packetSize -3; i += 4) { setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], udpIn[i+3]); @@ -564,7 +588,7 @@ void handleNotifications() } else if (udpIn[0] == 4) //dnrgb { uint16_t id = ((udpIn[3] << 0) & 0xFF) + ((udpIn[2] << 8) & 0xFF00); - for (size_t i = 4; i < packetSize -2; i += 3) + for (int i = 4; i < packetSize -2; i += 3) { if (id >= totalLen) break; setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], 0); @@ -573,7 +597,7 @@ void handleNotifications() } else if (udpIn[0] == 5) //dnrgbw { uint16_t id = ((udpIn[3] << 0) & 0xFF) + ((udpIn[2] << 8) & 0xFF00); - for (size_t i = 4; i < packetSize -2; i += 4) + for (int i = 4; i < packetSize -2; i += 4) { if (id >= totalLen) break; setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], udpIn[i+3]); diff --git a/wled00/wled.h b/wled00/wled.h index 7701edeb..f276cc22 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -63,6 +63,11 @@ //This is generally a terrible idea, but improves boot success on boards with a 3.3v regulator + cap setup that can't provide 400mA peaks //#define WLED_DISABLE_BROWNOUT_DET +// WLED-MM MANDATORY flags +#ifdef ARDUINO_ARCH_ESP32 // this feature seems unstable on 8266 +#define WLEDMM_PROTECT_SERVICE // prevents crashes when effects are drawing while asyncWebServer tries to modify segments at the same time +#endif + // Library inclusions. #include #ifdef ESP8266 diff --git a/wled00/ws.cpp b/wled00/ws.cpp index 1a7bcb77..a729d852 100644 --- a/wled00/ws.cpp +++ b/wled00/ws.cpp @@ -253,7 +253,7 @@ static bool sendLiveLedsWs(uint32_t wsClient) // WLEDMM added "static" void handleWs() { - if (millis() - wsLastLiveTime > max((strip.getLengthTotal()/20), WS_LIVE_INTERVAL)) //WLEDMM dynamic nr of peek frames per second + if ((millis() - wsLastLiveTime) > (unsigned long)(max((strip.getLengthTotal()/20), WS_LIVE_INTERVAL))) //WLEDMM dynamic nr of peek frames per second { #ifdef ESP8266 ws.cleanupClients(3); From 2cc6925f178f00e6b3445e9c4ac0962f42d1ed94 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 22 Aug 2023 23:42:03 +0200 Subject: [PATCH 16/24] agcSensitivity (to align um_data with esp32) all elements of um_data must be filled, otherwise some effects will crash. This adds a dummy " agcSensitivity" value that stays at 128. --- usermods/audioreactive/audio_reactive.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index ac0453c5..6473de84 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -88,6 +88,7 @@ static uint8_t fftResult[NUM_GEQ_CHANNELS]= {0};// Our calculated freq. channel // TODO: probably best not used by receive nodes static uint8_t soundAgc = 0; // Automagic gain control: 0 - none, 1 - normal, 2 - vivid, 3 - lazy (config value) +static float agcSensitivity = 128; // AGC sensitivity estimation, based on agc gain (multAgc). calculated by getSensitivity(). range 0..255 // user settable parameters for limitSoundDynamics() static bool limiterOn = true; // bool: enable / disable dynamics limiter @@ -942,7 +943,6 @@ class AudioReactive : public Usermod { // variables used in effects int16_t volumeRaw = 0; // either sampleRaw or rawSampleAgc depending on soundAgc float my_magnitude =0.0f; // FFT_Magnitude, scaled by multAgc - float agcSensitivity = 128; // AGC sensitivity estimation, based on agc gain (multAgc). calculated by getSensitivity(). range 0..255 float soundPressure = 0; // Sound Pressure estimation, based on microphone raw readings. 0 ->5db, 255 ->105db // used to feed "Info" Page @@ -1560,12 +1560,12 @@ class AudioReactive : public Usermod { um_data->u_type[6] = UMT_BYTE; um_data->u_data[7] = &binNum; // assigned in effect function from UI element!!! (Puddlepeak, Ripplepeak, Waterfall) um_data->u_type[7] = UMT_BYTE; - um_data->u_data[8] = &FFT_MajorPeak; // new + um_data->u_data[8] = &FFT_MajorPeak; // new - substitute for FFT_MajPeakSmth um_data->u_type[8] = UMT_FLOAT; - um_data->u_data[9] = &volumeSmth; // used (New) + um_data->u_data[9] = &volumeSmth; // used (New) - substitute for soundPressure um_data->u_type[9] = UMT_FLOAT; - // um_data->u_data[10] = &agcSensitivity; // used (New) - // um_data->u_type[10] = UMT_FLOAT; + um_data->u_data[10] = &agcSensitivity; // used (New) - dummy value (128 => 50%) + um_data->u_type[10] = UMT_FLOAT; #endif } From d221745e3fe37038a228b570ca1e9cefd043ad84 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Wed, 23 Aug 2023 12:37:30 +0200 Subject: [PATCH 17/24] some improvements * remove some internal variables (soundAgc, multAgc, ....) * prototype for autoResetPeak(void) * changed `#ifndef ESP8266` to `#ifdef ARDUINO_ARCH_ESP32` * replacement code for computing max sample * Info Page: "audio source" added (idle/receiving/not connected/Off) --- usermods/audioreactive/audio_reactive.h | 55 +++++++++++++++++++------ 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index 6473de84..a01c3dc8 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -9,7 +9,7 @@ #endif -#if defined(WLED_DEBUG) || defined(SR_DEBUG) +#if defined(ARDUINO_ARCH_ESP32) && (defined(WLED_DEBUG) || defined(SR_DEBUG)) #include #endif @@ -74,10 +74,13 @@ static bool udpSyncConnected = false; // UDP connection status -> true i #define NUM_GEQ_CHANNELS 16 // number of frequency channels. Don't change !! // audioreactive variables +#ifdef ARDUINO_ARCH_ESP32 static float micDataReal = 0.0f; // MicIn data with full 24bit resolution - lowest 8bit after decimal point static float multAgc = 1.0f; // sample * multAgc = sampleAgc. Our AGC multiplier static float sampleAvg = 0.0f; // Smoothed Average sample - sampleAvg < 1 means "quiet" (simple noise gate) static float sampleAgc = 0.0f; // Smoothed AGC sample +static uint8_t soundAgc = 0; // Automagic gain control: 0 - none, 1 - normal, 2 - vivid, 3 - lazy (config value) +#endif static float volumeSmth = 0.0f; // either sampleAvg or sampleAgc depending on soundAgc; smoothed sample static float FFT_MajorPeak = 1.0f; // FFT: strongest (peak) frequency static float FFT_Magnitude = 0.0f; // FFT: volume (magnitude) of peak frequency @@ -87,7 +90,6 @@ static unsigned long timeOfPeak = 0; // time of last sample peak detection. static uint8_t fftResult[NUM_GEQ_CHANNELS]= {0};// Our calculated freq. channel result table to be used by effects // TODO: probably best not used by receive nodes -static uint8_t soundAgc = 0; // Automagic gain control: 0 - none, 1 - normal, 2 - vivid, 3 - lazy (config value) static float agcSensitivity = 128; // AGC sensitivity estimation, based on agc gain (multAgc). calculated by getSensitivity(). range 0..255 // user settable parameters for limitSoundDynamics() @@ -96,6 +98,10 @@ static uint16_t attackTime = 50; // int: attack time in millisecond static uint16_t decayTime = 300; // int: decay time in milliseconds. New default 300ms. Old default was 1.40sec // peak detection +#ifdef ARDUINO_ARCH_ESP32 +static void detectSamplePeak(void); // peak detection function (needs scaled FFT reasults in vReal[]) - no used for 8266 receive-only mode +#endif +static void autoResetPeak(void); // peak auto-reset function static uint8_t maxVol = 31; // (was 10) Reasonable value for constant volume for 'peak detector', as it won't always trigger (deprecated) static uint8_t binNum = 8; // Used to select the bin for FFT based beat detection (deprecated) @@ -164,10 +170,6 @@ static uint8_t freqDist = 0; // 0=old 1=rightshift //static int16_t volumeRaw = 0; // either sampleRaw or rawSampleAgc depending on soundAgc //static float my_magnitude =0.0f; // FFT_Magnitude, scaled by multAgc -// peak detection -static void detectSamplePeak(void); // peak detection function (needs scaled FFT reasults in vReal[]) -static void autoResetPeak(void); // peak auto-reset function - // shared vars for debugging #ifdef MIC_LOGGER static volatile float micReal_min = 0.0f; // MicIn data min from last batch of samples @@ -931,6 +933,7 @@ class AudioReactive : public Usermod { int last_soundAgc = -1; // used to detect AGC mode change (for resetting AGC internal error buffers) double control_integrated = 0.0; // persistent across calls to agcAvg(); "integrator control" = accumulated error +#ifdef ARDUINO_ARCH_ESP32 // variables used by getSample() and agcAvg() int16_t micIn = 0; // Current sample starts with negative values and large values, which is why it's 16 bit signed double sampleMax = 0.0; // Max sample over a few seconds. Needed for AGC controler. @@ -939,6 +942,7 @@ class AudioReactive : public Usermod { float sampleReal = 0.0f; // "sampleRaw" as float, to provide bits that are lost otherwise (before amplification by sampleGain or inputLevel). Needed for AGC. int16_t sampleRaw = 0; // Current sample. Must only be updated ONCE!!! (amplified mic value by sampleGain and inputLevel) int16_t rawSampleAgc = 0; // not smoothed AGC sample +#endif // variables used in effects int16_t volumeRaw = 0; // either sampleRaw or rawSampleAgc depending on soundAgc @@ -1402,10 +1406,10 @@ class AudioReactive : public Usermod { } // transmitAudioData() #endif static bool isValidUdpSyncVersion(const char *header) { - return strncmp_P(header, UDP_SYNC_HEADER, 6) == 0; + return strncmp(header, UDP_SYNC_HEADER, 6) == 0; } static bool isValidUdpSyncVersion_v1(const char *header) { - return strncmp_P(header, UDP_SYNC_HEADER_v1, 6) == 0; + return strncmp(header, UDP_SYNC_HEADER_v1, 6) == 0; } void decodeAudioData(int packetSize, uint8_t *fftBuff) { @@ -1413,12 +1417,14 @@ class AudioReactive : public Usermod { // update samples for effects volumeSmth = fmaxf(receivedPacket->sampleSmth, 0.0f); volumeRaw = fmaxf(receivedPacket->sampleRaw, 0.0f); +#ifdef ARDUINO_ARCH_ESP32 // update internal samples sampleRaw = volumeRaw; sampleAvg = volumeSmth; rawSampleAgc = volumeRaw; sampleAgc = volumeSmth; - multAgc = 1.0f; + multAgc = 1.0f; +#endif // Only change samplePeak IF it's currently false. // If it's true already, then the animation still needs to respond. autoResetPeak(); @@ -1427,7 +1433,7 @@ class AudioReactive : public Usermod { if (samplePeak) timeOfPeak = millis(); //userVar1 = samplePeak; } - //These values are only available on the ESP32 + //These values are only computed by ESP32 for (int i = 0; i < NUM_GEQ_CHANNELS; i++) fftResult[i] = receivedPacket->fftResult[i]; my_magnitude = fmaxf(receivedPacket->FFT_Magnitude, 0.0f); FFT_Magnitude = my_magnitude; @@ -1439,12 +1445,14 @@ class AudioReactive : public Usermod { // update samples for effects volumeSmth = fmaxf(receivedPacket->sampleAgc, 0.0f); volumeRaw = volumeSmth; // V1 format does not have "raw" AGC sample +#ifdef ARDUINO_ARCH_ESP32 // update internal samples sampleRaw = fmaxf(receivedPacket->sampleRaw, 0.0f); sampleAvg = fmaxf(receivedPacket->sampleAvg, 0.0f);; sampleAgc = volumeSmth; rawSampleAgc = volumeRaw; multAgc = 1.0f; +#endif // Only change samplePeak IF it's currently false. // If it's true already, then the animation still needs to respond. autoResetPeak(); @@ -1482,7 +1490,9 @@ class AudioReactive : public Usermod { packetSize = fftUdp.parsePacket(); #endif +#ifdef ARDUINO_ARCH_ESP32 if ((packetSize > 0) && ((packetSize < 5) || (packetSize > UDPSOUND_MAX_PACKET))) fftUdp.flush(); // discard invalid packets (too small or too big) +#endif if ((packetSize > 5) && (packetSize <= UDPSOUND_MAX_PACKET)) { static uint8_t fftUdpBuffer[UDPSOUND_MAX_PACKET+1] = { 0 }; // static buffer for receiving, to reuse the same memory and avoid heap fragmentation //DEBUGSR_PRINTLN("Received UDP Sync Packet"); @@ -1693,7 +1703,7 @@ class AudioReactive : public Usermod { } if (audioSyncPort > 0 && (audioSyncEnabled & 0x03)) { - #ifndef ESP8266 + #ifdef ARDUINO_ARCH_ESP32 udpSyncConnected = fftUdp.beginMulticast(IPAddress(239, 0, 0, 1), audioSyncPort); #else udpSyncConnected = fftUdp.beginMulticast(WiFi.localIP(), IPAddress(239, 0, 0, 1), audioSyncPort); @@ -1851,7 +1861,9 @@ class AudioReactive : public Usermod { volumeSmth =0.0f; volumeRaw =0; my_magnitude = 0.1; FFT_Magnitude = 0.01; FFT_MajorPeak = 2; +#ifdef ARDUINO_ARCH_ESP32 multAgc = 1; +#endif DEBUGSR_PRINTLN(F("AR loop(): UDP closed due to inactivity.")); } @@ -1864,6 +1876,7 @@ class AudioReactive : public Usermod { #endif // Info Page: keep max sample from last 5 seconds +#ifdef ARDUINO_ARCH_ESP32 if ((millis() - sampleMaxTimer) > CYCLE_SAMPLEMAX) { sampleMaxTimer = millis(); maxSample5sec = (0.15 * maxSample5sec) + 0.85 *((soundAgc) ? sampleAgc : sampleAvg); // reset, and start with some smoothing @@ -1871,6 +1884,16 @@ class AudioReactive : public Usermod { } else { if ((sampleAvg >= 1)) maxSample5sec = fmaxf(maxSample5sec, (soundAgc) ? rawSampleAgc : sampleRaw); // follow maximum volume } +#else // similar functionality for 8266 receive only - use VolumeSmth instead of raw sample data + if ((millis() - sampleMaxTimer) > CYCLE_SAMPLEMAX) { + sampleMaxTimer = millis(); + maxSample5sec = (0.15 * maxSample5sec) + 0.85 * volumeSmth; // reset, and start with some smoothing + if (volumeSmth < 1.0f) maxSample5sec = 0; // noise gate + if (maxSample5sec < 0.0f) maxSample5sec = 0; // avoid negative values + } else { + if (volumeSmth >= 1.0f) maxSample5sec = fmaxf(maxSample5sec, volumeRaw); // follow maximum volume + } +#endif #ifdef ARDUINO_ARCH_ESP32 //UDP Microphone Sync - transmit mode @@ -1976,7 +1999,9 @@ class AudioReactive : public Usermod { */ void addToJsonInfo(JsonObject& root) { - char myStringBuffer[16]; // buffer for snprintf() +#ifdef ARDUINO_ARCH_ESP32 + char myStringBuffer[16]; // buffer for snprintf() - not used yet on 8266 +#endif JsonObject user = root["u"]; if (user.isNull()) user = root.createNestedObject("u"); @@ -2019,7 +2044,6 @@ class AudioReactive : public Usermod { } #endif // The following can be used for troubleshooting user errors and is so not enclosed in #ifdef WLED_DEBUG -#ifdef ARDUINO_ARCH_ESP32 // current Audio input infoArr = user.createNestedArray(F("Audio Source")); if (audioSyncEnabled & 0x02) { @@ -2033,6 +2057,11 @@ class AudioReactive : public Usermod { } else { infoArr.add(F(" - no connection")); } +#ifndef ARDUINO_ARCH_ESP32 // substitute for 8266 + } else { + infoArr.add(F("sound sync Off")); + } +#else // ESP32 only } else { // Analog or I2S digital input if (audioSource && (audioSource->isInitialized())) { From 3255530ee36004ea2e36ad4f966107ca38b8a693 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Wed, 23 Aug 2023 14:40:47 +0200 Subject: [PATCH 18/24] basic debug support on 8266 --- usermods/audioreactive/audio_reactive.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index a01c3dc8..5e53893e 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -977,13 +977,15 @@ class AudioReactive : public Usermod { if (disableSoundProcessing && (!udpSyncConnected || ((audioSyncEnabled & 0x02) == 0))) return; // no audio availeable #ifdef MIC_LOGGER // Debugging functions for audio input and sound processing. Comment out the values you want to see + PLOT_PRINT("volumeSmth:"); PLOT_PRINT(volumeSmth + 256.0f); PLOT_PRINT("\t"); // +256 to move above other lines + //PLOT_PRINT("volumeRaw:"); PLOT_PRINT(volumeRaw + 256.0f); PLOT_PRINT("\t"); // +256 to move above other lines + //PLOT_PRINT("samplePeak:"); PLOT_PRINT((samplePeak!=0) ? 128:0); PLOT_PRINT("\t"); + #ifdef ARDUINO_ARCH_ESP32 PLOT_PRINT("micMin:"); PLOT_PRINT(0.5f * micReal_min); PLOT_PRINT("\t"); // scaled down to 50%, for better readability PLOT_PRINT("micMax:"); PLOT_PRINT(0.5f * micReal_max); PLOT_PRINT("\t"); // scaled down to 50% //PLOT_PRINT("micAvg:"); PLOT_PRINT(0.5f * micReal_avg); PLOT_PRINT("\t"); // scaled down to 50% //PLOT_PRINT("micDC:"); PLOT_PRINT(0.5f * (micReal_min + micReal_max)/2.0f);PLOT_PRINT("\t"); // scaled down to 50% PLOT_PRINT("micReal:"); PLOT_PRINT(micDataReal + 256.0f); PLOT_PRINT("\t"); // +256 to move above other lines - PLOT_PRINT("volumeSmth:"); PLOT_PRINT(volumeSmth + 256.0f); PLOT_PRINT("\t"); // +256 to move above other lines - //PLOT_PRINT("volumeRaw:"); PLOT_PRINT(volumeRaw + 256.0f); PLOT_PRINT("\t"); // +256 to move above other lines PLOT_PRINT("DC_Level:"); PLOT_PRINT(micLev + 256.0f); PLOT_PRINT("\t"); // +256 to move above other lines // //PLOT_PRINT("filtmicMin:"); PLOT_PRINT(0.5f * micReal_min2); PLOT_PRINT("\t"); // scaled down to 50% // //PLOT_PRINT("filtmicMax:"); PLOT_PRINT(0.5f * micReal_max2); PLOT_PRINT("\t"); // scaled down to 50% @@ -993,8 +995,8 @@ class AudioReactive : public Usermod { //PLOT_PRINT("micIn:"); PLOT_PRINT(micIn); PLOT_PRINT("\t"); //PLOT_PRINT("sample:"); PLOT_PRINT(sample); PLOT_PRINT("\t"); //PLOT_PRINT("sampleMax:"); PLOT_PRINT(sampleMax); PLOT_PRINT("\t"); - //PLOT_PRINT("samplePeak:"); PLOT_PRINT((samplePeak!=0) ? 128:0); PLOT_PRINT("\t"); //PLOT_PRINT("multAgc:"); PLOT_PRINT(multAgc, 4); PLOT_PRINT("\t"); + #endif PLOT_PRINTLN(); PLOT_FLUSH(); #endif @@ -1757,7 +1759,7 @@ class AudioReactive : public Usermod { #endif disableSoundProcessing = true; } else { - #ifdef WLED_DEBUG + #if defined(ARDUINO_ARCH_ESP32) && defined(WLED_DEBUG) if ((disableSoundProcessing == true) && (audioSyncEnabled == 0) && audioSource->isInitialized()) { // we just switched to "enabled" DEBUG_PRINTLN("[AR userLoop] realtime mode ended - audio processing resumed."); DEBUG_PRINTF( " RealtimeMode = %d; RealtimeOverride = %d\n", int(realtimeMode), int(realtimeOverride)); @@ -2128,6 +2130,7 @@ class AudioReactive : public Usermod { } #if defined(WLED_DEBUG) || defined(SR_DEBUG) || defined(SR_STATS) + #ifdef ARDUINO_ARCH_ESP32 infoArr = user.createNestedArray(F("I2S cycle time")); infoArr.add(roundf(fftTaskCycle)/100.0f); infoArr.add(" ms"); @@ -2149,6 +2152,7 @@ class AudioReactive : public Usermod { DEBUGSR_PRINTF("AR Sampling time : %5.2f ms\n", roundf(sampleTime)/100.0f); DEBUGSR_PRINTF("AR FFT time : %5.2f ms\n", roundf(fftTime)/100.0f); #endif + #endif } } From 023279c702feb296cc967c0e945d5e9ac73ad527 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Wed, 23 Aug 2023 13:18:48 +0200 Subject: [PATCH 19/24] 8266: minor buildenv updates * -Wno-register not needed any more (solved in FastLED 3.6.0) * ARDUINOJSON_DEBUG added to debug_flags * use WLEDMM_PROTECT_SERVICE on 8266, too --- platformio.ini | 13 ++++++++++--- wled00/wled.h | 2 -- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/platformio.ini b/platformio.ini index eadc0a73..e157b750 100644 --- a/platformio.ini +++ b/platformio.ini @@ -129,7 +129,8 @@ platform_packages = platformio/framework-arduinoespressif8266 # FLAGS: DEBUG # # ------------------------------------------------------------------------------ -debug_flags = -D DEBUG=1 -D WLED_DEBUG -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_UPDATER -DDEBUG_ESP_OTA -DDEBUG_TLS_MEM +debug_flags = -D DEBUG=1 -D WLED_DEBUG -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_UPDATER -DDEBUG_ESP_OTA -DDEBUG_TLS_MEM + -DARDUINOJSON_DEBUG=1 ;; enables some debug asserts in arduinoJSON #if needed (for memleaks etc) also add; -DDEBUG_ESP_OOM -include "umm_malloc/umm_malloc_cfg.h" #-DDEBUG_ESP_CORE is not working right now @@ -248,7 +249,7 @@ build_flags = -DESP8266 -DFP_IN_IROM ;-Wno-deprecated-declarations - -Wno-register ;; leaves some warnings when compiling C files: command-line option '-Wno-register' is valid for C++/ObjC++ but not for C + ;; -Wno-register ;; leaves some warnings when compiling C files: command-line option '-Wno-register' is valid for C++/ObjC++ but not for C ;-Dregister= # remove warnings in C++17 due to use of deprecated register keyword by the FastLED library ;; warning: this can be dangerous -Wno-misleading-indentation ; NONOSDK22x_190703 = 2.2.2-dev(38a443e) @@ -1282,12 +1283,17 @@ build_flags = ${common.build_flags_esp8266} -D WLED_WATCHDOG_TIMEOUT=0 -D WLED_DISABLE_ALEXA -D WLED_DISABLE_HUESYNC - ; -D WLED_DEBUG + ; -D WLED_DEBUG ${common.debug_flags} ;; un-comment for debug messages + ;; -D WLED_DISABLE_ESPNOW ;; might help in case of WiFi connectivity problems + ; -D WLED_DISABLE_LOXONE ; FLASH 1272 bytes + ; -D WLED_DISABLE_MQTT ; RAM 216 bytes; FLASH 16496 bytes + ; -D WLED_DISABLE_INFRARED ;RAM 136 bytes; FLASH 24492 bytes ewowi: disabled to stay below 100% ; -D WLED_DISABLE_2D ; -D USERMOD_AUDIOREACTIVE ; -D USERMOD_ARTIFX ; to be done ; -UWLED_USE_MY_CONFIG monitor_filters = esp8266_exception_decoder +; lib_ignore = IRremoteESP8266 ; use with WLED_DISABLE_INFRARED for faster compilation ; RAM: [====== ] 59.3% (used 48616 bytes from 81920 bytes) ; Flash: [======== ] 77.0% (used 804236 bytes from 1044464 bytes) @@ -1309,6 +1315,7 @@ build_flags = ${common.build_flags_esp8266} -D WLED_DISABLE_LOXONE ; -D USERMOD_AUDIOREACTIVE ; -D USERMOD_ARTIFX ; to be done + ;; -D WLED_DISABLE_ESPNOW ;; might help in case of WiFi connectivity problems -D USERMOD_PIRSWITCH -D USERMOD_DALLASTEMPERATURE ;; disabled because it hangs during usermod setup on -S3 (autodetect broken?) -D USERMOD_MULTI_RELAY diff --git a/wled00/wled.h b/wled00/wled.h index f276cc22..14c0843d 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -64,9 +64,7 @@ //#define WLED_DISABLE_BROWNOUT_DET // WLED-MM MANDATORY flags -#ifdef ARDUINO_ARCH_ESP32 // this feature seems unstable on 8266 #define WLEDMM_PROTECT_SERVICE // prevents crashes when effects are drawing while asyncWebServer tries to modify segments at the same time -#endif // Library inclusions. #include From 1306cc041227594affa4b87b38713dd237db74cd Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Wed, 23 Aug 2023 13:19:48 +0200 Subject: [PATCH 20/24] show kernel debug messages in debug builds --- wled00/wled.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wled00/wled.cpp b/wled00/wled.cpp index adfa2b82..68a0afa1 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -430,8 +430,8 @@ void WLED::setup() #endif //Serial0.setDebugOutput(false); - #ifdef WLED_DEBUG - Serial.setDebugOutput(true); + #if CORE_DEBUG_LEVEL || defined(WLED_DEBUG_HEAP) || defined(WLED_DEBUG) + Serial.setDebugOutput(true); // enables kernel debug messages on Serial #endif USER_FLUSH(); delay(100); USER_PRINTLN(); @@ -1030,6 +1030,8 @@ void WLED::initInterfaces() } #endif +// aOtaEnabled=false; strcpy(cmDNS, ""); // WLEDMM use this to disable OTA and mDNS + //WLEDMM: add netdebug variables #ifdef WLED_DEBUG_HOST if (netDebugPrintIP[0] == 0) { From ecc6f1aa62cc6071d0c01bcf348d44bc8a2eee26 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Wed, 23 Aug 2023 15:39:32 +0200 Subject: [PATCH 21/24] bugfix seems I was too fast with removing _P from strncmp_P --- usermods/audioreactive/audio_reactive.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index 5e53893e..81d272bf 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -1408,10 +1408,10 @@ class AudioReactive : public Usermod { } // transmitAudioData() #endif static bool isValidUdpSyncVersion(const char *header) { - return strncmp(header, UDP_SYNC_HEADER, 6) == 0; + return strncmp_P(header, UDP_SYNC_HEADER, 6) == 0; } static bool isValidUdpSyncVersion_v1(const char *header) { - return strncmp(header, UDP_SYNC_HEADER_v1, 6) == 0; + return strncmp_P(header, UDP_SYNC_HEADER_v1, 6) == 0; } void decodeAudioData(int packetSize, uint8_t *fftBuff) { From 9e4f040d4103fd3069bcab633ad89d690f2bf1b4 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Thu, 24 Aug 2023 14:21:47 +0200 Subject: [PATCH 22/24] esp8266 build envs new: esp8266_2MB_S updated: esp8266_4MB_S --- platformio.ini | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/platformio.ini b/platformio.ini index ec9e618f..0622e9a3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -45,15 +45,16 @@ default_envs = ; esp32_4MB_S ;; experimental, optimized for speed - esp32_4MB_M ; recommended default + esp32_4MB_M ;; esp32 recommended default esp32_4MB_M_eth esp32_4MB_M_debug esp32_4MB_XL ; esp32_16MB_S ;; experimental, optimized for speed - esp32_16MB_M + esp32_16MB_M ;; esp32 recommended for boards with 16MB flash ; esp32_16MB_M_debug ; esp32_16MB_XL - esp8266_4MB_S + esp8266_2MB_S + esp8266_4MB_S ;; recommended for 8266 with audio sync esp8266_4MB_M wemos_shield_esp32_4MB_M ; wemos_shield_esp32_4MB_ICS4343x_M @@ -1231,6 +1232,27 @@ build_flags = ${esp32_4MB_M_base.build_flags} ; RAM: [== ] 24.5% (used 80348 bytes from 327680 bytes) ; Flash: [======= ] 69.4% (used 1455233 bytes from 2097152 bytes) + +[env:esp8266_2MB_S] +extends = env:esp8266_2m +upload_speed = 460800 ;115200 +board_build.f_cpu = 160000000L ;; we want 160Mhz (default = 80Mhz) +build_flags = ${common.build_flags_esp8266} + -D WLED_RELEASE_NAME=esp8266_2MB_S + -D WLED_DISABLE_ALEXA + -D WLED_DISABLE_HUESYNC + -D WLED_DISABLE_ESPNOW ;; might help in case of WiFi connectivity problems + -D WLED_DISABLE_LOXONE ; FLASH 1272 bytes + ;; -D WLED_DISABLE_MQTT ; RAM 216 bytes; FLASH 16496 bytes + ;; -D WLED_DISABLE_INFRARED ;RAM 136 bytes; FLASH 24492 bytes + ; -D WLED_DISABLE_2D + ; -UWLED_USE_MY_CONFIG + ; -D WLED_DEBUG +; monitor_filters = esp8266_exception_decoder +;; lib_ignore = IRremoteESP8266 ; use with WLED_DISABLE_INFRARED for faster compilation +; RAM: [====== ] 60.8% (used 49836 bytes from 81920 bytes) +; Flash: [======== ] 83.3% (used 869783 bytes from 1044464 bytes) + [env:esp8266_4MB_S] extends = env:d1_mini upload_speed = 460800 ;115200 @@ -1239,13 +1261,17 @@ build_flags = ${common.build_flags_esp8266} -D WLED_RELEASE_NAME=esp8266_4MB_S -D WLED_DISABLE_ALEXA -D WLED_DISABLE_HUESYNC + -D WLED_DISABLE_ESPNOW ;; might help in case of WiFi connectivity problems + -D WLED_DISABLE_LOXONE ; FLASH 1272 bytes + ;; -D WLED_DISABLE_MQTT ; RAM 216 bytes; FLASH 16496 bytes + ;; -D WLED_DISABLE_INFRARED ;RAM 136 bytes; FLASH 24492 bytes ; -D WLED_DISABLE_2D ; -UWLED_USE_MY_CONFIG ; -D WLED_DEBUG ; monitor_filters = esp8266_exception_decoder -; RAM: [====== ] 59.3% (used 48608 bytes from 81920 bytes) -; Flash: [======== ] 77.0% (used 804176 bytes from 1044464 bytes) - +;; lib_ignore = IRremoteESP8266 ; use with WLED_DISABLE_INFRARED for faster compilation +; RAM: [====== ] 60.8% (used 49824 bytes from 81920 bytes) +; Flash: [======== ] 83.3% (used 869779 bytes from 1044464 bytes) [env:esp8266_4MB_M] extends = env:d1_mini upload_speed = 460800 ;115200 @@ -1369,8 +1395,8 @@ lib_deps = ${esp8266.lib_deps} OneWire@~2.3.5 ; used for USERMOD_FOUR_LINE_DISPLAY and USERMOD_DALLASTEMPERATURE olikraus/U8g2 @ ^2.28.8 ; used for USERMOD_FOUR_LINE_DISPLAY ElectronicCats/MPU6050 @ 0.6.0 ; used for USERMOD_MPU6050_IMU -; RAM: [====== ] 62.4% (used 51092 bytes from 81920 bytes) -; Flash: [========= ] 85.5% (used 893056 bytes from 1044464 bytes) +; RAM: [====== ] 63.8% (used 52272 bytes from 81920 bytes) +; Flash: [========= ] 90.4% (used 944487 bytes from 1044464 bytes) [env:esp01_1MB_S] board = esp01_1m From f09fd7b50e3c8b507697398180cd90cfbc75a41f Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Thu, 24 Aug 2023 17:56:37 +0200 Subject: [PATCH 23/24] Update CONTRIBUTING.md small update for coding style --- CONTRIBUTING.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 560a7097..61b8f88d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -23,6 +23,11 @@ if (a == b) { } ``` +```cpp +if (a == b) doStuff(a); +``` + +less readable, but acceptable in some cases: ```cpp if (a == b) { @@ -30,9 +35,6 @@ if (a == b) } ``` -```cpp -if (a == b) doStuff(a); -``` There should always be a space between a keyword and its condition and between the condition and brace. Within the condition, no space should be between the paranthesis and variables. @@ -75,4 +77,4 @@ Good: There is no set character limit for a comment within a line, though as a rule of thumb you should wrap your comment if it exceeds the width of your editor window. -Inline comments are OK if they describe that line only and are not exceedingly wide. \ No newline at end of file +Inline comments are OK if they describe that line only and are not exceedingly wide. From 6379a61828f18843092bc478a1d1f6b79460fa24 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Thu, 24 Aug 2023 18:02:38 +0200 Subject: [PATCH 24/24] Update CONTRIBUTING.md --- CONTRIBUTING.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 61b8f88d..b4fbef51 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,6 +20,8 @@ Good: ```cpp if (a == b) { doStuff(a); +} else { + doOtherStuff(b); } ```