atuline / WLED

Control WS2812B and many more types of digital RGB LEDs with an ESP32 over WiFi.
GNU General Public License v3.0
866 stars 130 forks source link

Select preset with sound threshold #187

Open hobbypin opened 2 years ago

hobbypin commented 2 years ago

When sound(volume) reaches a set threshold change to preset x. Once sound falls under preset for some delayed period of time return to previous preset. Very much like a button but triggered on sound level.

My use case is using SRWLED in a jukebox. nothing playing I use a simple attract mode. When music starts I would like to use one of the Sound Reactive effects. When music stops return to attract mode.

Wiring a button is possible but sound level trigger would make it a lot easier

pnichols77 commented 2 years ago

When sound(volume) reaches a set threshold change to preset x. Once sound falls under preset for some delayed period of time return to previous preset. Very much like a button but triggered on sound level.

My use case is using SRWLED in a jukebox. nothing playing I use a simple attract mode. When music starts I would like to use one of the Sound Reactive effects. When music stops return to attract mode.

Wiring a button is possible but sound level trigger would make it a lot easier

Providing the media player youre using is visible in Home Assistant, you could use that to automate sound reactive effects when media is playing.

softhack007 commented 2 years ago

I think this is not possible currently. And it would not work with AGC enabled, which will become the new standard.

We take ~50 samples per second from the microphone, and AGC tries to balance input amplification so that samples use 90% of the availeable range which is 0...255 . Chances are very high that every possible value is used within a few seconds.

What could be done in future:

1) once we have a working "noise gate" - raise a trigger when there is silence for some seconds

2) AGC uses an internal gain factor. This factor is highly depending on sound input characteristics, like microphone sensitivity and dynamic range of I2S readings. Currently we don't make the AGC gain value visible to users. We could - in principle - check AGC gain against a user-defined threshold, and then raise some trigger when gain is below threshold for some user-defined time. "Below" as high gain indicates a very low input signal so low gain means there is stronger sound.

actually there are no plans right now to create something like this, but it could be possible from technical perspective.