@@ -642,45 +642,39 @@ static const char _data_FX_MODE_TWINKLE[] PROGMEM = "Twinkle@!,!;!,!;!;;m12=0";
642642 * Dissolve function
643643 */
644644uint16_t dissolve (uint32_t color) {
645- unsigned dataSize = (SEGLEN+ 7 ) >> 3 ; // 1 bit per LED
645+ unsigned dataSize = sizeof ( uint32_t ) * SEGLEN;
646646 if (!SEGENV.allocateData (dataSize)) return mode_static (); // allocation failed
647+ uint32_t * pixels = reinterpret_cast <uint32_t *>(SEGENV.data );
647648
648649 if (SEGENV.call == 0 ) {
649- memset (SEGMENT. data , 0xFF , dataSize); // start by fading pixels up
650+ for ( unsigned i = 0 ; i < SEGLEN; i++) pixels[i] = SEGCOLOR ( 1 );
650651 SEGENV.aux0 = 1 ;
651652 }
652653
653654 for (unsigned j = 0 ; j <= SEGLEN / 15 ; j++) {
654655 if (hw_random8 () <= SEGMENT.intensity ) {
655656 for (size_t times = 0 ; times < 10 ; times++) { // attempt to spawn a new pixel 10 times
656657 unsigned i = hw_random16 (SEGLEN);
657- unsigned index = i >> 3 ;
658- unsigned bitNum = i & 0x07 ;
659- bool fadeUp = bitRead (SEGENV.data [index], bitNum);
660658 if (SEGENV.aux0 ) { // dissolve to primary/palette
661- if (fadeUp) {
662- if (color == SEGCOLOR (0 )) {
663- SEGMENT.setPixelColor (i, SEGMENT.color_from_palette (i, true , PALETTE_SOLID_WRAP, 0 ));
664- } else {
665- SEGMENT.setPixelColor (i, color);
666- }
667- bitWrite (SEGENV.data [index], bitNum, false );
659+ if (pixels[i] == SEGCOLOR (1 )) {
660+ pixels[i] = color == SEGCOLOR (0 ) ? SEGMENT.color_from_palette (i, true , PALETTE_SOLID_WRAP, 0 ) : color;
668661 break ; // only spawn 1 new pixel per frame per 50 LEDs
669662 }
670663 } else { // dissolve to secondary
671- if (!fadeUp ) {
672- SEGMENT. setPixelColor (i, SEGCOLOR (1 )); break ;
673- bitWrite (SEGENV. data [index], bitNum, true ) ;
664+ if (pixels[i] != SEGCOLOR ( 1 ) ) {
665+ pixels[i] = SEGCOLOR (1 );
666+ break ;
674667 }
675668 }
676669 }
677670 }
678671 }
672+ // fix for #4401
673+ for (unsigned i = 0 ; i < SEGLEN; i++) SEGMENT.setPixelColor (i, pixels[i]);
679674
680675 if (SEGENV.step > (255 - SEGMENT.speed ) + 15U ) {
681676 SEGENV.aux0 = !SEGENV.aux0 ;
682677 SEGENV.step = 0 ;
683- memset (SEGMENT.data , (SEGENV.aux0 ? 0xFF : 0 ), dataSize); // switch fading
684678 } else {
685679 SEGENV.step ++;
686680 }
@@ -6568,23 +6562,31 @@ static const char _data_FX_MODE_JUGGLES[] PROGMEM = "Juggles@!,# of balls;!,!;!;
65686562// * MATRIPIX //
65696563// ////////////////////
65706564uint16_t mode_matripix (void ) { // Matripix. By Andrew Tuline.
6571- if (SEGLEN == 1 ) return mode_static ();
6572- // even with 1D effect we have to take logic for 2D segments for allocation as fill_solid() fills whole segment
6565+ // effect can work on single pixels, we just lose the shifting effect
6566+ unsigned dataSize = sizeof (uint32_t ) * SEGLEN;
6567+ if (!SEGENV.allocateData (dataSize)) return mode_static (); // allocation failed
6568+ uint32_t * pixels = reinterpret_cast <uint32_t *>(SEGENV.data );
65736569
65746570 um_data_t *um_data = getAudioData ();
65756571 int volumeRaw = *(int16_t *)um_data->u_data [1 ];
65766572
65776573 if (SEGENV.call == 0 ) {
6578- SEGMENT. fill (BLACK);
6574+ for ( unsigned i = 0 ; i < SEGLEN; i++) pixels[i] = BLACK; // may not be needed as resetIfRequired() clears buffer
65796575 }
65806576
65816577 uint8_t secondHand = micros ()/(256 -SEGMENT.speed )/500 % 16 ;
65826578 if (SEGENV.aux0 != secondHand) {
65836579 SEGENV.aux0 = secondHand;
65846580
6585- uint8_t pixBri = volumeRaw * SEGMENT.intensity / 64 ;
6586- for (unsigned i = 0 ; i < SEGLEN-1 ; i++) SEGMENT.setPixelColor (i, SEGMENT.getPixelColor (i+1 )); // shift left
6587- SEGMENT.setPixelColor (SEGLEN-1 , color_blend (SEGCOLOR (1 ), SEGMENT.color_from_palette (strip.now , false , PALETTE_SOLID_WRAP, 0 ), pixBri));
6581+ int pixBri = volumeRaw * SEGMENT.intensity / 64 ;
6582+ unsigned k = SEGLEN-1 ;
6583+ // loop will not execute if SEGLEN equals 1
6584+ for (unsigned i = 0 ; i < k; i++) {
6585+ pixels[i] = pixels[i+1 ]; // shift left
6586+ SEGMENT.setPixelColor (i, pixels[i]);
6587+ }
6588+ pixels[k] = color_blend (SEGCOLOR (1 ), SEGMENT.color_from_palette (strip.now , false , PALETTE_SOLID_WRAP, 0 ), pixBri);
6589+ SEGMENT.setPixelColor (k, pixels[k]);
65886590 }
65896591
65906592 return FRAMETIME;
@@ -7139,8 +7141,11 @@ static const char _data_FX_MODE_ROCKTAVES[] PROGMEM = "Rocktaves@;!,!;!;01f;m12=
71397141// Combines peak detection with FFT_MajorPeak and FFT_Magnitude.
71407142uint16_t mode_waterfall (void ) { // Waterfall. By: Andrew Tuline
71417143 // effect can work on single pixels, we just lose the shifting effect
7142-
7143- um_data_t *um_data = getAudioData ();
7144+ unsigned dataSize = sizeof (uint32_t ) * SEGLEN;
7145+ if (!SEGENV.allocateData (dataSize)) return mode_static (); // allocation failed
7146+ uint32_t * pixels = reinterpret_cast <uint32_t *>(SEGENV.data );
7147+
7148+ um_data_t *um_data = getAudioData ();
71447149 uint8_t samplePeak = *(uint8_t *)um_data->u_data [3 ];
71457150 float FFT_MajorPeak = *(float *) um_data->u_data [4 ];
71467151 uint8_t *maxVol = (uint8_t *)um_data->u_data [6 ];
@@ -7150,7 +7155,7 @@ uint16_t mode_waterfall(void) { // Waterfall. By: Andrew Tulin
71507155 if (FFT_MajorPeak < 1 ) FFT_MajorPeak = 1 ; // log10(0) is "forbidden" (throws exception)
71517156
71527157 if (SEGENV.call == 0 ) {
7153- SEGMENT. fill (BLACK);
7158+ for ( unsigned i = 0 ; i < SEGLEN; i++) pixels[i] = BLACK; // may not be needed as resetIfRequired() clears buffer
71547159 SEGENV.aux0 = 255 ;
71557160 SEGMENT.custom1 = *binNum;
71567161 SEGMENT.custom2 = *maxVol * 2 ;
@@ -7167,13 +7172,18 @@ uint16_t mode_waterfall(void) { // Waterfall. By: Andrew Tulin
71677172 uint8_t pixCol = (log10f (FFT_MajorPeak) - 2 .26f ) * 150 ; // 22Khz sampling - log10 frequency range is from 2.26 (182hz) to 3.967 (9260hz). Let's scale accordingly.
71687173 if (FFT_MajorPeak < 182 .0f ) pixCol = 0 ; // handle underflow
71697174
7175+ unsigned k = SEGLEN-1 ;
71707176 if (samplePeak) {
7171- SEGMENT. setPixelColor (SEGLEN- 1 , CHSV (92 ,92 ,92 ));
7177+ pixels[k] = ( uint32_t ) CRGB ( CHSV (92 ,92 ,92 ));
71727178 } else {
7173- SEGMENT. setPixelColor (SEGLEN- 1 , color_blend (SEGCOLOR (1 ), SEGMENT.color_from_palette (pixCol+SEGMENT.intensity , false , PALETTE_SOLID_WRAP, 0 ), (uint8_t )my_magnitude) );
7179+ pixels[k] = color_blend (SEGCOLOR (1 ), SEGMENT.color_from_palette (pixCol+SEGMENT.intensity , false , PALETTE_SOLID_WRAP, 0 ), (uint8_t )my_magnitude);
71747180 }
7181+ SEGMENT.setPixelColor (k, pixels[k]);
71757182 // loop will not execute if SEGLEN equals 1
7176- for (unsigned i = 0 ; i < SEGLEN-1 ; i++) SEGMENT.setPixelColor (i, SEGMENT.getPixelColor (i+1 )); // shift left
7183+ for (unsigned i = 0 ; i < k; i++) {
7184+ pixels[i] = pixels[i+1 ]; // shift left
7185+ SEGMENT.setPixelColor (i, pixels[i]);
7186+ }
71777187 }
71787188
71797189 return FRAMETIME;
0 commit comments