atuline/WLED

0D effects for music spotlights

roboraptor opened this issue · 24 comments

Would it be possible to add some effects for single diode spotliights and such?
Effects like some on dmx lights auto or sound modes

  • change to random* color on beat
  • white strobe on beat
  • random* color strobe on beat

( *random or random from like list of 6 or such... red, green, blue, yellow, purple, cyan,.. )

Thank yooou

Hi, currently we do not have specific effects for single (or very few) LEDs.
Hoewever most WLED effects also work on single LEDs, see screenshots below for some examples that might also work for you. They are for my "high power LEDs" segment which has only 3 lights.

I can imagine that some of your ideas could be implemented in SR WLED later, like

  • use a trigger event to "shift" the color map, or pick a new color map at random
  • a possible trigger could be "change on beat", however our beat detection code would need some improvements for this - currently it's not good enough reliably detect "beats".

Hope this helps,
Frank

Example1_Matripix

Example2_FreqWave

Hi, thank you for your answers.

For beat detection im currently waiting for I2C microphones to arrive because using ordinary mic with adc on pin36 wasnt really relayable??? i can probably rewire it to "line input" and send only bass from monitor output or rewire it more to implement bass crossover? so that could be better?

The effect are really simple yeah. It is just a LED spotlight using RGB PWM output.
if you can add at least the "change color on beat" it would be awesome.

Also got me thinking if there could be any workaround like save the colors in presets and create playlist and switch in playlist on the beat ?

Thank you very much
Robo

Damian peckett had a nice beat detection article on his web site a while back, but unfortunately, that site is no longer available. Beat detection, however, is not an easy thing to implement, as is the automatic gain control.

I shlurped most of the information from that article, including the code if @softhack007 is interested.

Hi @atuline, yes I would be interested to see that code - please send it on discord - no hurry. Actually i have something on PC that is based on the "beatroot" algorithm - could look into that topic after summer, ONCE the current dev is stabilized and released. And yes, I completely agree that beat detection is not easy to implement.

@roboraptor - do you mean an I2S microphone, or really an I2C one? These I2S microphones work really well in SR-WLED, however i'm not sure if we support I2C based ones at all. Actually, anything is better than ADC analog input.

About the detection it is cool but I am more interested in the effect that I could use 😅
You know even the basic board in the fixture which detected beats was not perfect.

Yeah it is I2S INMP441

Btw, I think it would be a very simple coding exercise to create a new "mood lighting" effect.
Basically you need a prepared palette with the right "moody colors". A simple effect could cycle through the palette, and fill the complete strip with one of the colors. On next iteration, pick the next color from palette and repeat.
This will work in "zero D" or with any longer strip, and even PWM LEDs.

I tried the palette.... After tedious hours of fighting with platformIO....
{ 0, 255, 0, 0, 36, 255, 0, 0, 37, 0,255, 0, 72, 0,255, 0, 73, 0, 0,255, 108, 0, 0,255, 109, 255,255, 0, 144, 255,255, 0, 145, 0,255,255, 180, 0,255,255, 181, 255, 0,255, 216, 255, 0,255, 217, 255,255,255, 255, 255,255,255};
Just a basic one... But I am not sure about the effects...

I compiled and tried how few effects work and I somehow feel like the efect named "Palette" could be transformed into something i would like to use. Just let the effect know to only move at the beat...

As I dont know how to PR, I tried it Here

Hey, nice to see that you have taken on the 'challenge' to create a new effect 😃

There are a few wiki pages that could help you get started:

good luck, and happy hacking 👍

Im still playing a bit with the LEDFx app which does the FFT and just sends the light effects over E131 but there is also no basic "chabge color on beat" effect 🙄
One would say "what a basic thing" like... every cheapo spotlight has it... It does not work exactly the best but FFT on ESP32 neither for now...

When I get to it I hope someone implements it ❤️

WLED-SR currently does not have a good 'beat detection' algo. Improvements are on our priority list, however this will happen after the next release.

We already have a variable samplePeak that has the value '1' when the volume in one FFT bin (binNum) is above a predefined threshold (maxVol). You can look at the Waterfall effect (FX.cpp, line 6496) for an example how to use it.

Defaults are predefined in audio_reactive.h. They can be changed by any effect for example using UI sliders (see below).

uint8_t maxVol = 10; // Reasonable value for constant volume for 'peak detector', as it won't always trigger
uint8_t binNum = 8; // Used to select the bin for FFT based beat detection.

WLED/wled00/FX.cpp

Lines 6478 to 6506 in 95abf86

uint16_t WS2812FX::mode_waterfall(void) { // Waterfall. By: Andrew Tuline
if (SEGENV.call == 0) fill_solid(leds, 0);
binNum = SEGMENT.custom2; // Select a bin.
maxVol = SEGMENT.custom3/2; // Our volume comparator.
uint8_t secondHand = micros() / (256-SEGMENT.speed)/500 + 1 % 16;
if (SEGENV.aux0 != secondHand) { // Triggered millis timing.
SEGENV.aux0 = secondHand;
float my_magnitude = FFT_Magnitude / 8.0;
if (soundAgc) my_magnitude *= multAgc;
if (sampleAvg < 1 ) my_magnitude = 0.001; // noise gate closed - mute
uint8_t pixCol = (log10((int)FFT_MajorPeak) - 2.26) * 177; // log10 frequency range is from 2.26 to 3.7. Let's scale accordingly.
if (samplePeak) {
leds[realPixelIndex(SEGLEN-1)] = CHSV(92,92,92);
} else {
leds[realPixelIndex(SEGLEN-1)] = color_blend(SEGCOLOR(1), color_from_palette(pixCol+SEGMENT.intensity, false, PALETTE_SOLID_WRAP, 0), (int)my_magnitude);
}
for (int i=0; i<SEGLEN-1; i++) leds[realPixelIndex(i)] = leds[realPixelIndex(i+1)];
}
setPixels(leds);
return FRAMETIME;
} // mode_waterfall()

WLED/wled00/FX.h

Line 1415 in 95abf86

" ♫ Waterfall@!,Adjust color,,Select bin, Volume (minimum);!,!;!",

Just took at closer look at the "Palette" effect.
Now that you mastered platformIO, you could try your first 'dirty hack' and modify the source code of uint16_t WS2812FX::mode_palette() in FX.cpp.

Try to replace the first few lines of the function - everything before bool noWrap = ... - with the code sniplet below. Then recompile & upload to your device.

Result: If you select the "Palette" effect and move the "Speed" slider to zero (or any low value < 32 ), then you can see how the colors only changes when a "beat" is ongoing. Speed > 31 will give you the normal, non-SR behaviour.

Cheers and happy hacking,
Frank.

uint16_t WS2812FX::mode_palette()
{
  uint16_t counter = SEGENV.aux0;
  if (SEGMENT.speed > 32)
  {
    counter = (now * ((SEGMENT.speed >> 3) +1)) & 0xFFFF;
    counter = counter >> 8;
  } 
  else {
    if ((samplePeak==1) && (sampleAgc > 1)) {
      counter += SEGMENT.speed +1;
      if (counter > 255) counter -= 256;
    }
  }
  SEGENV.aux0 = counter;


  // rest of the function remains unchanged ....

Of course that's just a quick try, but it might already be what you are looking for.
You can learn more about "persistent variables" here: https://github.com/atuline/WLED/wiki/Persistent-Variables-and-WLED#enter-wled---

It is all good that there is a lot effects but I cannot imagine how should they look when working properly 😭
Like is there any test button which triggers the "beat" ? Without me needing the proper setup and FFT? That would be awesome.

Going to look at the coding in few hours! Looks like we have solution pretty close!

Without me needing the proper setup and FFT? That would be awesome.

Actually it's just plain soundreactiveWLED (dev branch)- not LEDFx app for FFT.
So once you have changed the code, recompiled & uploaded, you can try it out.

Only setup needed is the basic sound settings in WLED.
Squelch should be high enough so effects can detect silence (in my home, I use Squelch=8).
Then set AGC to "Normal". That's all.

Test trigger: in a silent room, you can drop a few pencils onto the desk near the microphone, that should count as a "beat".

OMG OMG OMG ❤️
I had to move the whole palette thingy under your sampleAgc definition but it looks like it works! 🎉
Still need to wait for I2S microphones 🎤
(Because the thing I have connected to pin 34 is only working when I blow on it or smack it with something...)

Also, you can set AGC more than just on/off ? I have only checkbox there.

How do I know that I2S microphone is detected?
But I cant make it work... I fiddle with squelch and gain but still nothing agc on or off no change...
Serial outpul says

ts Jun  8�AS: Generic I2S Microphone.
Ada

We have a guide in our wiki, maybe this helps:

https://github.com/atuline/WLED/wiki/Digital-Microphone-Hookup

Actually you can now use the web UI for changing I2S pins, so the part that suggest to change #defines in source code is a bit outdated.

The INMP441 is very sensitive; I would start with gain=60 and squelch=8. If you have a LED strip (size don't matter), the 'gravimeter' effect should react once the mic is connected properly.

P.S. be careful when soldering pins to the INMP441 - we had people here who accidentally got solder flux into the mic hole. Basically makes the device unusable until you clean out the flux.

Also, you can set AGC more than just on/off ? I have only checkbox there.

Please use source code from the 'dev' branch, don't use 'master'. We have made many improvements for AGC in dev .

https://github.com/atuline/WLED/tree/dev

Also, hitting CTRL + F5 in your browser might help to clean the cache and remove old/outdated UI data.

Please use source code from the 'dev' branch, don't use 'master'. We have made many improvements for AGC in dev .

Im so sorry... never used github much... Will try tonight ❤️ Thank you

Im sorry but still not working... i bought 5 of them and none is doing anything...
I even tried to remap pins to something different sck26 ws25 sd33 but still no avail...

Did you connect the "L/R" pin to GND, as described in our wiki?
If yes, then maybe you can try to put this pin to 3.3v, just to see if left/right are swapped.

Also it's worth to try and use the pins suggested in the wiki page, in case they are available on your ESP32: sd=32 ws=15 sck=14. Please also double-check if you simply swapped ws and sck.

if still not working, you could join our Discord and ask in the "support" channel. https://discord.gg/4CQRmfR

If asking on discord, you may want to add a screenshot of your Sound Settings page, LED Preferences page, and a picture that shows the wiring between mic and ESP32.

You can also compare your setup to this: #184 (comment)

Does it work now?

Closing, as no activity for some months now.

"Zero D" effects are nothing special - any effect that works with "PWM LEDs" is actually "0D" as the same color will be shown on each LEDs connected to PWM pins.

@roboraptor you might also want to check out the audio responsive color palettes I've added to the MM fork