Skip to content

Commit b320612

Browse files
authored
Merge pull request wled#3942 from gaaat98/audioreactive-analog
Enabled some audioreactive effects for single pixel strips/segments
2 parents 47e1cbd + 5bccb5f commit b320612

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

wled00/FX.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6643,7 +6643,6 @@ static const char _data_FX_MODE_GRAVIMETER[] PROGMEM = "Gravimeter@Rate of fall,
66436643
// * JUGGLES //
66446644
//////////////////////
66456645
uint16_t mode_juggles(void) { // Juggles. By Andrew Tuline.
6646-
if (SEGLEN == 1) return mode_static();
66476646
um_data_t *um_data;
66486647
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
66496648
// add support for no audio
@@ -6655,12 +6654,13 @@ uint16_t mode_juggles(void) { // Juggles. By Andrew Tuline.
66556654
uint16_t my_sampleAgc = fmax(fmin(volumeSmth, 255.0), 0);
66566655

66576656
for (size_t i=0; i<SEGMENT.intensity/32+1U; i++) {
6657+
// if SEGLEN equals 1, we will always set color to the first and only pixel, but the effect is still good looking
66586658
SEGMENT.setPixelColor(beatsin16(SEGMENT.speed/4+i*2,0,SEGLEN-1), color_blend(SEGCOLOR(1), SEGMENT.color_from_palette(strip.now/4+i*2, false, PALETTE_SOLID_WRAP, 0), my_sampleAgc));
66596659
}
66606660

66616661
return FRAMETIME;
66626662
} // mode_juggles()
6663-
static const char _data_FX_MODE_JUGGLES[] PROGMEM = "Juggles@!,# of balls;!,!;!;1v;m12=0,si=0"; // Pixels, Beatsin
6663+
static const char _data_FX_MODE_JUGGLES[] PROGMEM = "Juggles@!,# of balls;!,!;!;01v;m12=0,si=0"; // Pixels, Beatsin
66646664

66656665

66666666
//////////////////////
@@ -6761,7 +6761,7 @@ uint16_t mode_noisefire(void) { // Noisefire. By Andrew Tuline.
67616761

67626762
return FRAMETIME;
67636763
} // mode_noisefire()
6764-
static const char _data_FX_MODE_NOISEFIRE[] PROGMEM = "Noisefire@!,!;;;1v;m12=2,si=0"; // Circle, Beatsin
6764+
static const char _data_FX_MODE_NOISEFIRE[] PROGMEM = "Noisefire@!,!;;;01v;m12=2,si=0"; // Circle, Beatsin
67656765

67666766

67676767
///////////////////////
@@ -6871,7 +6871,7 @@ uint16_t mode_plasmoid(void) { // Plasmoid. By Andrew Tuline.
68716871

68726872
return FRAMETIME;
68736873
} // mode_plasmoid()
6874-
static const char _data_FX_MODE_PLASMOID[] PROGMEM = "Plasmoid@Phase,# of pixels;!,!;!;1v;sx=128,ix=128,m12=0,si=0"; // Pixels, Beatsin
6874+
static const char _data_FX_MODE_PLASMOID[] PROGMEM = "Plasmoid@Phase,# of pixels;!,!;!;01v;sx=128,ix=128,m12=0,si=0"; // Pixels, Beatsin
68756875

68766876

68776877
///////////////////////
@@ -7026,7 +7026,7 @@ static const char _data_FX_MODE_BLURZ[] PROGMEM = "Blurz@Fade rate,Blur;!,Color
70267026
// ** DJLight //
70277027
/////////////////////////
70287028
uint16_t mode_DJLight(void) { // Written by ??? Adapted by Will Tatam.
7029-
if (SEGLEN == 1) return mode_static();
7029+
// No need to prevent from executing on single led strips, only mid will be set (mid = 0)
70307030
const int mid = SEGLEN / 2;
70317031

70327032
um_data_t *um_data;
@@ -7047,13 +7047,14 @@ uint16_t mode_DJLight(void) { // Written by ??? Adapted by Wil
70477047
CRGB color = CRGB(fftResult[15]/2, fftResult[5]/2, fftResult[0]/2); // 16-> 15 as 16 is out of bounds
70487048
SEGMENT.setPixelColor(mid, color.fadeToBlackBy(map(fftResult[4], 0, 255, 255, 4))); // TODO - Update
70497049

7050+
// if SEGLEN equals 1 these loops won't execute
70507051
for (int i = SEGLEN - 1; i > mid; i--) SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i-1)); // move to the left
70517052
for (int i = 0; i < mid; i++) SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i+1)); // move to the right
70527053
}
70537054

70547055
return FRAMETIME;
70557056
} // mode_DJLight()
7056-
static const char _data_FX_MODE_DJLIGHT[] PROGMEM = "DJ Light@Speed;;;1f;m12=2,si=0"; // Circle, Beatsin
7057+
static const char _data_FX_MODE_DJLIGHT[] PROGMEM = "DJ Light@Speed;;;01f;m12=2,si=0"; // Circle, Beatsin
70577058

70587059

70597060
////////////////////
@@ -7097,7 +7098,7 @@ static const char _data_FX_MODE_FREQMAP[] PROGMEM = "Freqmap@Fade rate,Starting
70977098
// ** Freqmatrix //
70987099
///////////////////////
70997100
uint16_t mode_freqmatrix(void) { // Freqmatrix. By Andreas Pleschung.
7100-
if (SEGLEN == 1) return mode_static();
7101+
// No need to prevent from executing on single led strips, we simply change pixel 0 each time and avoid the shift
71017102
um_data_t *um_data;
71027103
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
71037104
// add support for no audio
@@ -7140,12 +7141,13 @@ uint16_t mode_freqmatrix(void) { // Freqmatrix. By Andreas Plesch
71407141

71417142
// shift the pixels one pixel up
71427143
SEGMENT.setPixelColor(0, color);
7144+
// if SEGLEN equals 1 this loop won't execute
71437145
for (int i = SEGLEN - 1; i > 0; i--) SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i-1)); //move to the left
71447146
}
71457147

71467148
return FRAMETIME;
71477149
} // mode_freqmatrix()
7148-
static const char _data_FX_MODE_FREQMATRIX[] PROGMEM = "Freqmatrix@Speed,Sound effect,Low bin,High bin,Sensitivity;;;1f;m12=3,si=0"; // Corner, Beatsin
7150+
static const char _data_FX_MODE_FREQMATRIX[] PROGMEM = "Freqmatrix@Speed,Sound effect,Low bin,High bin,Sensitivity;;;01f;m12=3,si=0"; // Corner, Beatsin
71497151

71507152

71517153
//////////////////////
@@ -7202,7 +7204,7 @@ static const char _data_FX_MODE_FREQPIXELS[] PROGMEM = "Freqpixels@Fade rate,Sta
72027204
// As a compromise between speed and accuracy we are currently sampling with 10240Hz, from which we can then determine with a 512bin FFT our max frequency is 5120Hz.
72037205
// Depending on the music stream you have you might find it useful to change the frequency mapping.
72047206
uint16_t mode_freqwave(void) { // Freqwave. By Andreas Pleschung.
7205-
if (SEGLEN == 1) return mode_static();
7207+
// As before, this effect can also work on single pixels, we just lose the shifting effect
72067208
um_data_t *um_data;
72077209
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
72087210
// add support for no audio
@@ -7246,13 +7248,14 @@ uint16_t mode_freqwave(void) { // Freqwave. By Andreas Pleschun
72467248
SEGMENT.setPixelColor(SEGLEN/2, color);
72477249

72487250
// shift the pixels one pixel outwards
7251+
// if SEGLEN equals 1 these loops won't execute
72497252
for (int i = SEGLEN - 1; i > SEGLEN/2; i--) SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i-1)); //move to the left
72507253
for (int i = 0; i < SEGLEN/2; i++) SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i+1)); // move to the right
72517254
}
72527255

72537256
return FRAMETIME;
72547257
} // mode_freqwave()
7255-
static const char _data_FX_MODE_FREQWAVE[] PROGMEM = "Freqwave@Speed,Sound effect,Low bin,High bin,Pre-amp;;;1f;m12=2,si=0"; // Circle, Beatsin
7258+
static const char _data_FX_MODE_FREQWAVE[] PROGMEM = "Freqwave@Speed,Sound effect,Low bin,High bin,Pre-amp;;;01f;m12=2,si=0"; // Circle, Beatsin
72567259

72577260

72587261
///////////////////////
@@ -7311,7 +7314,6 @@ static const char _data_FX_MODE_GRAVFREQ[] PROGMEM = "Gravfreq@Rate of fall,Sens
73117314
// ** Noisemove //
73127315
//////////////////////
73137316
uint16_t mode_noisemove(void) { // Noisemove. By: Andrew Tuline
7314-
if (SEGLEN == 1) return mode_static();
73157317
um_data_t *um_data;
73167318
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
73177319
// add support for no audio
@@ -7325,20 +7327,20 @@ uint16_t mode_noisemove(void) { // Noisemove. By: Andrew Tuli
73257327
uint8_t numBins = map(SEGMENT.intensity,0,255,0,16); // Map slider to fftResult bins.
73267328
for (int i=0; i<numBins; i++) { // How many active bins are we using.
73277329
uint16_t locn = inoise16(strip.now*SEGMENT.speed+i*50000, strip.now*SEGMENT.speed); // Get a new pixel location from moving noise.
7330+
// if SEGLEN equals 1 locn will be always 0, hence we set the first pixel only
73287331
locn = map(locn, 7500, 58000, 0, SEGLEN-1); // Map that to the length of the strand, and ensure we don't go over.
73297332
SEGMENT.setPixelColor(locn, color_blend(SEGCOLOR(1), SEGMENT.color_from_palette(i*64, false, PALETTE_SOLID_WRAP, 0), fftResult[i % 16]*4));
73307333
}
73317334

73327335
return FRAMETIME;
73337336
} // mode_noisemove()
7334-
static const char _data_FX_MODE_NOISEMOVE[] PROGMEM = "Noisemove@Speed of perlin movement,Fade rate;!,!;!;1f;m12=0,si=0"; // Pixels, Beatsin
7337+
static const char _data_FX_MODE_NOISEMOVE[] PROGMEM = "Noisemove@Speed of perlin movement,Fade rate;!,!;!;01f;m12=0,si=0"; // Pixels, Beatsin
73357338

73367339

73377340
//////////////////////
73387341
// ** Rocktaves //
73397342
//////////////////////
73407343
uint16_t mode_rocktaves(void) { // Rocktaves. Same note from each octave is same colour. By: Andrew Tuline
7341-
if (SEGLEN == 1) return mode_static();
73427344
um_data_t *um_data;
73437345
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
73447346
// add support for no audio
@@ -7366,21 +7368,22 @@ uint16_t mode_rocktaves(void) { // Rocktaves. Same note from eac
73667368
frTemp = fabsf(frTemp * 2.1f); // Fudge factors to compress octave range starting at 0 and going to 255;
73677369

73687370
uint16_t i = map(beatsin8(8+octCount*4, 0, 255, 0, octCount*8), 0, 255, 0, SEGLEN-1);
7371+
// i will be always constrained between 0 and 0 if SEGLEN equals 1
73697372
i = constrain(i, 0, SEGLEN-1);
73707373
SEGMENT.addPixelColor(i, color_blend(SEGCOLOR(1), SEGMENT.color_from_palette((uint8_t)frTemp, false, PALETTE_SOLID_WRAP, 0), volTemp));
73717374

73727375
return FRAMETIME;
73737376
} // mode_rocktaves()
7374-
static const char _data_FX_MODE_ROCKTAVES[] PROGMEM = "Rocktaves@;!,!;!;1f;m12=1,si=0"; // Bar, Beatsin
7377+
static const char _data_FX_MODE_ROCKTAVES[] PROGMEM = "Rocktaves@;!,!;!;01f;m12=1,si=0"; // Bar, Beatsin
73757378

73767379

73777380
///////////////////////
73787381
// ** Waterfall //
73797382
///////////////////////
73807383
// Combines peak detection with FFT_MajorPeak and FFT_Magnitude.
73817384
uint16_t mode_waterfall(void) { // Waterfall. By: Andrew Tuline
7382-
if (SEGLEN == 1) return mode_static();
7383-
7385+
// effect can work on single pixels, we just lose the shifting effect
7386+
73847387
um_data_t *um_data;
73857388
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
73867389
// add support for no audio
@@ -7417,12 +7420,13 @@ uint16_t mode_waterfall(void) { // Waterfall. By: Andrew Tulin
74177420
} else {
74187421
SEGMENT.setPixelColor(SEGLEN-1, color_blend(SEGCOLOR(1), SEGMENT.color_from_palette(pixCol+SEGMENT.intensity, false, PALETTE_SOLID_WRAP, 0), (int)my_magnitude));
74197422
}
7423+
// loop will not execute if SEGLEN equals 1
74207424
for (int i = 0; i < SEGLEN-1; i++) SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i+1)); // shift left
74217425
}
74227426

74237427
return FRAMETIME;
74247428
} // mode_waterfall()
7425-
static const char _data_FX_MODE_WATERFALL[] PROGMEM = "Waterfall@!,Adjust color,Select bin,Volume (min);!,!;!;1f;c2=0,m12=2,si=0"; // Circles, Beatsin
7429+
static const char _data_FX_MODE_WATERFALL[] PROGMEM = "Waterfall@!,Adjust color,Select bin,Volume (min);!,!;!;01f;c2=0,m12=2,si=0"; // Circles, Beatsin
74267430

74277431

74287432
#ifndef WLED_DISABLE_2D

0 commit comments

Comments
 (0)