diff --git a/platformio.ini b/platformio.ini
index e49c32da..b1ce10e2 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -2164,7 +2164,7 @@ board_build.partitions = tools/WLED_ESP32_4MB_256KB_FS.csv ;; 1.8MB firmware,
;; board_build.partitions = tools/WLED_ESP32_4MB_512KB_FS.csv ;; 1.7MB firmware, 500KB filesystem (esptool erase_flash needed when changing from "standard WLED" partitions)
build_flags = ${common.build_flags} ${esp32s3.build_flags} -Wno-misleading-indentation -Wno-format-truncation
${common_mm.build_flags_S}
- -D WLED_RELEASE_NAME=esp32S3_4MB_S
+ -D WLED_RELEASE_NAME=esp32S3_4MB_PSRAM_S
-DBOARD_HAS_PSRAM ;; -D WLED_USE_PSRAM
-D WLED_USE_PSRAM_JSON -DALL_JSON_TO_PSRAM ; WLEDMM --> force all JSON stuff into PSRAM; gives more free heap
-DCONFIG_MBEDTLS_DYNAMIC_BUFFER=1 ;; optional - allows some buffers to use PSRAM
@@ -2202,7 +2202,7 @@ board = lolin_s3_mini ;; -S3 mini: 4MB flash 2MB PSRAM
board_build.partitions = ${esp32.default_partitions}
build_flags = ${common.build_flags} ${esp32s3.build_flags} -Wno-misleading-indentation -Wno-format-truncation
${common_mm.build_flags_S} ${common_mm.build_flags_M}
- -D WLED_RELEASE_NAME=esp32S3_4MB_M
+ -D WLED_RELEASE_NAME=esp32S3_4MB_PSRAM_M
-DBOARD_HAS_PSRAM ;; -D WLED_USE_PSRAM
-D WLED_USE_PSRAM_JSON -DALL_JSON_TO_PSRAM ; WLEDMM --> force all JSON stuff into PSRAM; gives more free heap
-DCONFIG_MBEDTLS_DYNAMIC_BUFFER=1 ;; optional - allows some buffers to use PSRAM
diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h
index a6e317e5..5e343a2b 100644
--- a/usermods/audioreactive/audio_reactive.h
+++ b/usermods/audioreactive/audio_reactive.h
@@ -2056,7 +2056,16 @@ class AudioReactive : public Usermod {
if ((sclPin >= 0) && (i2c_scl < 0)) i2c_scl = sclPin;
if (i2c_sda >= 0) sdaPin = -1; // -1 = use global
if (i2c_scl >= 0) sclPin = -1;
-
+ case 9:
+ DEBUGSR_PRINTLN(F("AR: ES8311 Source (Mic)"));
+ audioSource = new ES8311Source(SAMPLE_RATE, BLOCK_SIZE, 1.0f);
+ //useInputFilter = 0; // to disable low-cut software filtering and restore previous behaviour
+ delay(100);
+ // WLEDMM align global pins
+ if ((sdaPin >= 0) && (i2c_sda < 0)) i2c_sda = sdaPin; // copy usermod prefs into globals (if globals not defined)
+ if ((sclPin >= 0) && (i2c_scl < 0)) i2c_scl = sclPin;
+ if (i2c_sda >= 0) sdaPin = -1; // -1 = use global
+ if (i2c_scl >= 0) sclPin = -1;
if (audioSource) audioSource->initialize(i2swsPin, i2ssdPin, i2sckPin, mclkPin);
break;
@@ -3002,6 +3011,11 @@ class AudioReactive : public Usermod {
#else
oappend(SET_F("addOption(dd,'AC101 ☾',8);"));
#endif
+ #if SR_DMTYPE==9
+ oappend(SET_F("addOption(dd,'ES8311 ☾ (⎌)',9);"));
+ #else
+ oappend(SET_F("addOption(dd,'ES8311 ☾',9);"));
+ #endif
#ifdef SR_SQUELCH
oappend(SET_F("addInfo(ux+':config:squelch',1,'⎌ ")); oappendi(SR_SQUELCH); oappend("');"); // 0 is field type, 1 is actual field
#endif
diff --git a/usermods/audioreactive/audio_source.h b/usermods/audioreactive/audio_source.h
index 5e95c6a1..e8bba8ef 100644
--- a/usermods/audioreactive/audio_source.h
+++ b/usermods/audioreactive/audio_source.h
@@ -651,6 +651,106 @@ class ES8388Source : public I2SSource {
};
+/* ES8311 Sound Module
+ This is an I2S sound processing unit that requires initialization over
+ I2C before I2S data can be received.
+*/
+class ES8311Source : public I2SSource {
+ private:
+ // I2C initialization functions for es8311
+ void _es8311I2cBegin() {
+ Wire.setClock(100000);
+ }
+
+ void _es8311I2cWrite(uint8_t reg, uint8_t val) {
+ #ifndef ES8311_ADDR
+ #define ES8311_ADDR 0x18 // default address is... foggy
+ #endif
+ Wire.beginTransmission(ES8311_ADDR);
+ Wire.write((uint8_t)reg);
+ Wire.write((uint8_t)val);
+ uint8_t i2cErr = Wire.endTransmission(); // i2cErr == 0 means OK
+ if (i2cErr != 0) {
+ DEBUGSR_PRINTF("AR: ES8311 I2C write failed with error=%d (addr=0x%X, reg 0x%X, val 0x%X).\n", i2cErr, ES8311_ADDR, reg, val);
+ }
+ }
+
+ void _es8311InitAdc() {
+ //
+ // Currently only tested with the ESP32-P4 EV board with the onboard mic.
+ // Datasheet with I2C commands: https://dl.xkwy2018.com/downloads/RK3588/01_Official%20Release/04_Product%20Line%20Branch_NVR/02_Key%20Device%20Specifications/ES8311%20DS.pdf
+ //
+ _es8311I2cBegin();
+ _es8311I2cWrite(0x00, 0b00011111); // RESET, default value
+ _es8311I2cWrite(0x45, 0b00000000); // GP, default value
+ _es8311I2cWrite(0x01, 0b00111010); // CLOCK MANAGER was 0b00110000 trying 0b00111010 (MCLK enable?)
+
+ _es8311I2cWrite(0x02, 0b00000000); // 22050hz calculated
+ _es8311I2cWrite(0x05, 0b00000000); // 22050hz calculated
+ _es8311I2cWrite(0x03, 0b00010000); // 22050hz calculated
+ _es8311I2cWrite(0x04, 0b00010000); // 22050hz calculated
+ _es8311I2cWrite(0x07, 0b00000000); // 22050hz calculated
+ _es8311I2cWrite(0x08, 0b11111111); // 22050hz calculated
+ _es8311I2cWrite(0x06, 0b11100011); // 22050hz calculated
+
+ _es8311I2cWrite(0x16, 0b00100000); // ADC was 0b00000011 trying 0b00100100 now
+ _es8311I2cWrite(0x0B, 0b00000000); // SYSTEM at default
+ _es8311I2cWrite(0x0C, 0b00100000); // SYSTEM was 0b00001111 trying 0b00100000
+ _es8311I2cWrite(0x10, 0b00010011); // SYSTEM was 0b00011111 trying 0b00010011
+ _es8311I2cWrite(0x11, 0b01111100); // SYSTEM was 0b01111111 trying 0b01111100
+ _es8311I2cWrite(0x00, 0b11000000); // *** RESET (again - seems important?)
+ _es8311I2cWrite(0x01, 0b00111010); // CLOCK MANAGER was 0b00111111 trying 0b00111010 (again??)
+ _es8311I2cWrite(0x14, 0b00010000); // *** SYSTEM was 0b00011010 trying 0b00010000 (or 0b01111010) (PGA gain)
+ _es8311I2cWrite(0x12, 0b00000000); // SYSTEM - DAC, likely don't care
+ _es8311I2cWrite(0x13, 0b00010000); // SYSTEM - output, likely don't cate
+ _es8311I2cWrite(0x09, 0b00001000); // SDP IN (likely don't care) was 0b00001100 (16-bit) - changed to 0b00001000 (I2S 32-bit)
+ _es8311I2cWrite(0x0A, 0b00001000); // *** SDP OUT, was 0b00001100 trying 0b00001000 (I2S 32-bit)
+ _es8311I2cWrite(0x0E, 0b00000010); // *** SYSTEM was 0b00000010 trying 0b00011010 (seems best so far!) (or 0b00000010)
+ _es8311I2cWrite(0x0F, 0b01000100); // SYSTEM was 0b01000100
+ _es8311I2cWrite(0x15, 0b00000000); // ADC soft ramp (disabled)
+ _es8311I2cWrite(0x1B, 0b00000101); // ADC soft-mute was 0b00000101
+ _es8311I2cWrite(0x1C, 0b01100101); // ADC EQ and offset freeze was 0b01100101 (bad at 0b00101100)
+ _es8311I2cWrite(0x17, 0b10111111); // ADC volume was 0b11111111 trying ADC volume 0b10111111 = 0db (maxgain) 0x16
+ _es8311I2cWrite(0x44, 0b00000000); // 0b10000000 - loopback test. on: 0x88; off: 0x00; mic--" speak
+
+ }
+
+ public:
+ ES8311Source(SRate_t sampleRate, int blockSize, float sampleScale = 1.0f, bool i2sMaster=true) :
+ I2SSource(sampleRate, blockSize, sampleScale, i2sMaster) {
+ _config.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT;
+ };
+
+ void initialize(int8_t i2swsPin, int8_t i2ssdPin, int8_t i2sckPin, int8_t mclkPin) {
+ DEBUGSR_PRINTLN("es8311Source:: initialize();");
+
+ // if ((i2sckPin < 0) || (mclkPin < 0)) { // WLEDMM not sure if this check is needed here, too
+ // ERRORSR_PRINTF("\nAR: invalid I2S es8311 pin: SCK=%d, MCLK=%d\n", i2sckPin, mclkPin);
+ // return;
+ // }
+ // BUG: "use global I2C pins" are valid as -1, and -1 is seen as invalid here.
+ // Workaround: Set I2C pins here, which will also set them globally.
+ // Bug also exists in ES7243.
+ if ((i2c_sda < 0) || (i2c_scl < 0)) { // check that global I2C pins are not "undefined"
+ ERRORSR_PRINTF("\nAR: invalid es8311 global I2C pins: SDA=%d, SCL=%d\n", i2c_sda, i2c_scl);
+ return;
+ }
+ if (!pinManager.joinWire(i2c_sda, i2c_scl)) { // WLEDMM specific: start I2C with globally defined pins
+ ERRORSR_PRINTF("\nAR: failed to join I2C bus with SDA=%d, SCL=%d\n", i2c_sda, i2c_scl);
+ return;
+ }
+
+ // First route mclk, then configure ADC over I2C, then configure I2S
+ _es8311InitAdc();
+ I2SSource::initialize(i2swsPin, i2ssdPin, i2sckPin, mclkPin);
+ }
+
+ void deinitialize() {
+ I2SSource::deinitialize();
+ }
+
+};
+
class WM8978Source : public I2SSource {
private:
// I2C initialization functions for WM8978
diff --git a/wled00/FX.cpp b/wled00/FX.cpp
index f44db9da..53d99886 100644
--- a/wled00/FX.cpp
+++ b/wled00/FX.cpp
@@ -1794,6 +1794,61 @@ uint16_t mode_multi_comet(void) {
}
static const char _data_FX_MODE_MULTI_COMET[] PROGMEM = "Multi Comet";
+// audioreactive multi-comet by @softhack007
+uint16_t mode_multi_comet_ar(void) {
+ constexpr unsigned MAX_COMETS = 16; // was 8
+ uint32_t cycleTime = max(1, int((255 - SEGMENT.speed)/4));
+ uint32_t it = strip.now / cycleTime;
+ if (SEGENV.step == it) return FRAMETIME; // too early
+
+ if (!SEGENV.allocateData(sizeof(uint16_t) * MAX_COMETS)) return mode_static(); //allocation failed
+ uint16_t* comets = reinterpret_cast(SEGENV.data);
+ if (SEGENV.call == 0) { // do some initializations
+ SEGMENT.setUpLeds(); SEGMENT.fill(BLACK);
+ for(uint8_t i=0; i < MAX_COMETS; i++) comets[i] = SEGLEN; // WLEDMM make sure comments are started individually
+ SEGENV.aux0 = 0;
+ }
+ SEGMENT.fade_out(254 - SEGMENT.intensity/2);
+
+ um_data_t *um_data;
+ if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) um_data = simulateSound(SEGMENT.soundSim);
+ float volumeSmth = *(float*) um_data->u_data[0];
+ int16_t volumeRaw = *(int16_t*) um_data->u_data[1];
+ uint8_t samplePeak = *(uint8_t*) um_data->u_data[3];
+
+ uint16_t armed = SEGENV.aux0; // allows to delay comet launch
+
+ #if defined(ARDUINO_ARCH_ESP32)
+ random16_add_entropy(esp_random() & 0xFFFF); // improve randomness (esp32)
+ #endif
+ bool shotOne = false; // avoids starting several coments at the same time (invisible due to overlap)
+ for(unsigned i=0; i < MAX_COMETS; i++) {
+ if(comets[i] < SEGLEN) {
+ // draw comet
+ uint16_t index = comets[i];
+ if (SEGCOLOR(2) != 0)
+ SEGMENT.setPixelColor(index, i % 2 ? SEGMENT.color_from_palette(index, true, PALETTE_SOLID_WRAP, 0) : SEGCOLOR(2));
+ else
+ SEGMENT.setPixelColor(index, SEGMENT.color_from_palette(index, true, PALETTE_SOLID_WRAP, 0));
+ comets[i]++; // move
+ } else {
+ // randomly launch a new comet
+ if (random16(min(uint16_t(256), SEGLEN)) < 3) armed++; // new comet loaded and ready
+ if (armed > 2) armed = 2; // max three armed at once (avoid overlap)
+ // delay comet "launch" during silence, and wait until next beat
+ if ( (armed > 0) && (shotOne == false)
+ && (volumeSmth > 1.0f) && ((samplePeak > 0) || (volumeRaw > 104)) ) { // delayed lauch - wait until peak, don't launch in silence
+ comets[i] = 0; // start a new comet!
+ armed--; // un-arm one
+ shotOne = true;
+ }
+ }
+ }
+ SEGENV.aux0 = armed;
+ SEGENV.step = it;
+ return FRAMETIME;
+}
+static const char _data_FX_MODE_MULTI_COMET_AR[] PROGMEM = "Multi Comet audio ☾@Speed,Tail Length;!,!;!;1v;sx=160,ix=32,m12=7,si=1"; // Pinwheel, WeWillRockU
/*
* Running random pixels ("Stream 2")
@@ -2128,12 +2183,16 @@ uint16_t mode_fire_2012() {
const uint8_t ignition = max(3,SEGLEN/10); // ignition area: 10% of segment length or minimum 3 pixels
+ #if defined(ARDUINO_ARCH_ESP32)
+ random16_add_entropy(esp_random() & 0xFFFF); // improves randonmess
+ #endif
+
// Step 1. Cool down every cell a little
for (int i = 0; i < SEGLEN; i++) {
uint8_t cool = (it != SEGENV.step) ? random8((((20 + SEGMENT.speed/3) * 16) / SEGLEN)+2) : random8(4);
uint8_t minTemp = (ixcen = 0.;
julias->ycen = 0.;
julias->xymag = 1.0;
@@ -9012,6 +9078,7 @@ void WS2812FX::setupEffectData() {
addEffect(FX_MODE_LIGHTNING, &mode_lightning, _data_FX_MODE_LIGHTNING);
addEffect(FX_MODE_ICU, &mode_icu, _data_FX_MODE_ICU);
addEffect(FX_MODE_MULTI_COMET, &mode_multi_comet, _data_FX_MODE_MULTI_COMET);
+ addEffect(FX_MODE_MULTI_COMET_AR, &mode_multi_comet_ar, _data_FX_MODE_MULTI_COMET_AR);
addEffect(FX_MODE_DUAL_LARSON_SCANNER, &mode_dual_larson_scanner, _data_FX_MODE_DUAL_LARSON_SCANNER);
addEffect(FX_MODE_RANDOM_CHASE, &mode_random_chase, _data_FX_MODE_RANDOM_CHASE);
addEffect(FX_MODE_OSCILLATE, &mode_oscillate, _data_FX_MODE_OSCILLATE);
diff --git a/wled00/FX.h b/wled00/FX.h
index beba0517..c35c54fb 100644
--- a/wled00/FX.h
+++ b/wled00/FX.h
@@ -330,7 +330,7 @@ bool strip_uses_global_leds(void) __attribute__((pure)); // WLEDMM implemented
// Experimental Audioresponsive modes from WLED-SR
// #define FX_MODE_3DSphereMove 189 // experimental WLED-SR "cube" mode
#define FX_MODE_POPCORN_AR 190 // WLED-SR audioreactive popcorn
-// #define FX_MODE_MULTI_COMET_AR 191 // WLED-SR audioreactive multi-comet
+#define FX_MODE_MULTI_COMET_AR 191 // WLED-SR audioreactive multi-comet
#define FX_MODE_STARBURST_AR 192 // WLED-SR audioreactive fireworks starburst
// #define FX_MODE_PALETTE_AR 193 // WLED-SR audioreactive palette
#define FX_MODE_FIREWORKS_AR 194 // WLED-SR audioreactive fireworks
@@ -380,6 +380,7 @@ typedef struct Segment {
};
uint8_t grouping, spacing;
uint8_t opacity;
+ uint8_t lastBri; // WLEDMM optimization for black-to-black "transitions"
bool needsBlank; // WLEDMM indicates that Segment needs to be blanked (due to change of mirror / reverse / transpose / spacing)
uint32_t colors[NUM_COLORS];
uint8_t cct; //0==1900K, 255==10091K
@@ -490,6 +491,7 @@ typedef struct Segment {
grouping(1),
spacing(0),
opacity(255),
+ lastBri(255),
needsBlank(false),
colors{DEFAULT_COLOR,BLACK,BLACK},
cct(127),
diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp
index 0f750b0f..b2d7162f 100644
--- a/wled00/FX_fcn.cpp
+++ b/wled00/FX_fcn.cpp
@@ -1913,6 +1913,7 @@ void WS2812FX::service() {
seg.resetIfRequired();
if (!seg.isActive()) continue;
+ if (!seg.on && !seg.transitional) continue; // WLEDMM skip disabled segments, unless a crossfade is ongoing
// last condition ensures all solid segments are updated at the same time
if(nowUp >= seg.next_time || _triggered || (doShow && seg.mode == FX_MODE_STATIC)) // WLEDMM ">=" instead of ">"
@@ -1934,6 +1935,7 @@ void WS2812FX::service() {
now = millis() + timebase;
#endif
seg.startFrame(); // WLEDMM
+ if (!_triggered && (seg.currentBri(seg.opacity) == 0) && (seg.lastBri == 0)) continue; // WLEDMM skip totally black segments
// effect blending (execute previous effect)
// actual code may be a bit more involved as effects have runtime data including allocated memory
//if (seg.transitional && seg._modeP) (*_mode[seg._modeP])(progress());
@@ -1943,6 +1945,7 @@ void WS2812FX::service() {
if (seg.mode != FX_MODE_HALLOWEEN_EYES) seg.call++;
if (seg.transitional && frameDelay > FRAMETIME) frameDelay = FRAMETIME; // force faster updates during transition
+ seg.lastBri = seg.currentBri(seg.on ? seg.opacity:0); // WLEDMM remember for next time
seg.handleTransition();
}
diff --git a/wled00/wled.h b/wled00/wled.h
index 28110365..7af6b43c 100644
--- a/wled00/wled.h
+++ b/wled00/wled.h
@@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
-#define VERSION 2411290
+#define VERSION 2412030
// 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_