Repository navigation
Fix Audio advanced.h drawSpectrumBars() - #2089
Conversation
|
thank you. |
|
It's a little rough in this part of the codebase. Any changes you propose for fixups is greatly appreciated. |
|
You're welcome. I've been plugging away trying to figure out how to use various parts of the audio functionality library you're putting together, which I know is very much a work in progress. (I've read https://github.com/FastLED/FastLED/blob/master/FEATURE.md, which I believe was behind much of the new audio_reactive stuff.) What I've done so far in my test/prototype project (ESP32-S3 with INMP441) is:
What I've started most recently is refactoring each of the Audio Advanced visualizers to pull data from AudioReactive::AudioData objects instead of audio.h-based AudioSample objects. I've looked quite a bit at https://github.com/FastLED/FastLED/blob/master/tests/test_audio_reactive_simple.cpp to help me discover what some of the AudioReactive capabilities are and take a stab at using them. And I've gotten a lot of help from Claude. But it's been somewhat slow going. One thing that would be helpful is to know a bit more about the status of the AudioReactive. Are you planning to spend much/any time on this over the next few weeks/months? One thing in particular... I see that the AudioReactive::AudioReactiveConfig struct includes a I will be more than happy to share what I've been working on. Thanks, |
|
Audio reactive is essentially an algorithm port of WLED's version without the copyright/licensing issues. The WLED version of audio reactive code is an absolute mess but works great. What do I mean by this? WLED's AR code is strongly coupled with the hardware implementation of the esp32. You'll see task delay interleaved with sampling. This means it can't be unit tested at all. FastLED's re-write does a clean room re-implementation that works on an audio sampled buffer. Right now I've set that buffer at 512 samples, but the goal is too allow flexible sizes. The fact that FastLED's version works only with data means that it can be unit tested and continually improved without regressions, and is also cross platform. Audio reactive code has been stop and go. At first it was only working in the simulator, now with the INMP441 port to FastLED it's finally able to work with a physical device. The audio reactive code was working with the dBFS scale that I used with mp3s. This is a digital scale used by your computer where the max value is 0, and the min value is something like -70. The physical devices don't use this, they use actual sound pressure which is measured dB in the range of 30 -> 120 (typical). You'll see a conversion function in there specific for the INMP441. The big question I have is do I literally have a dB function for each microphone? Or do I go the route of auto detecting relative sound pressure so it works universally with all microphones and line inputs? I'm leaning towards the latter which is why the audio stuff hasn't been announced yet. The flex design is more complicated but essentially "just works" on everything. If you are in a hurry to get sound reactive mode working for you, then I encourage you to download my custom front end for Right now the stable parts of the audio pipeline will be the low level stuff like the audio buffer, the FFT (which is super fast). If you want to use the audio reactive code and not break, then I suggest you copy relative parts of the audio reactive pipeline into your sketch and use that so it doesn't break. If you make significant progress, please send a PR with your changes. |
|
Thanks, Zach. This info is super helpful!
While this may well be a big question, I don't know that it needs to be a gating/threshold/critical path one for progress on the FastLED AudioReactive (perhaps "flAudio"? or "FLAiR"?) library. The way I am starting to see things, various parts of the flAudio library can be organized (at least conceptually) into three main groups:
It seems to me that a good "focal point" for moving things forward might be a to set (1) an initial/default baseline/reference dbSPL for the input into the MIDDLE / AUDIO PROCESSING stage, and (2) an initial/default "conceptual scale" (e.g., linear from 0 to 255, or logarithmic from 1 to 100, etc.) for input into the AUDIO APPLICATION stage to help coders more easily mentally map audio levels to something they can work into visualizations. Later we can add optional alternative conversion methods so people can select other output->input levels/scales/whatever between the AUDIO INTERFACE and AUDIO PROCESSING stages, and the AUDIO PROCESSING and AUDIO APPLICATION stages. But we'd have some basic anchor points to that we can parallel path development now in each of the three stages. I don't know if this makes any sense or how it comports with software development best practices, FastLED principles, etc. Thoughts? |
|
https://youtu.be/SM-4ZamYaYM |
You pretty much nailed it exactly. Do you have thoughts on where the the db conversion tuning for INMP411 should go? |
This is UNBELIEVABLE awesome to see. Good work!! You may notice that the Animartrix examples have a global time value that you can adjust in the wasm demos. It either feeds into the FxEngine's time value or it modifies Animartrix's time value directory, i think it's then former. If you connect these two concepts, then you already know how to make animartrix audio reactive. |
|
This is an old video of the FFT when it was in a broken state (it was missing audio frames and you'll see this in the missed percussion hits, but this has been subsquently fixed). But if you don't mind looking at an old broken impl of FFT, this might inspire you: |
|
Interesting about the Animartrix global speed setting. I was never sure exactly what that did or how it related to other speed factors in the sketch; so my current implementation simply has a fixed As far as where to put the db conversion tuning for INMP411, I need to learn more about how some of the back end stuff is currently working. I believe what you're asking about is the inmp441_rms_to_dB() function in platforms/esp/32/audio/sound_util.h and sound_util.cpp. Is that correct? I may circle back with some specific questions on this. Thx for sharing your FFT video. Very cool! And indeed inspiring. We definitely need some good audio-enabled scrolling visualizers like that! |
Correct.
Check out |
|
FYI, I am giving myself a deep-dive crash course on audio and digital signal processing basics (things like PCM, RMS, FFT, spectral density, etc.) Figured I really need to get my head around some of this stuff in order to make much progress here. Many things are starting to make a lot more sense! |
|
I went down this rabbit hole too and figured out that the body of science around the most impactful strategy is simply sound-to-midi. My AI is on a loop to integrate this now. I'm glad things are making a lot more sense now! |
|
Holy shit! This is game-changing! |
I noticed that the sound-to-midi module was deprecated and removed. What happened? Is there a plan to bring that back, or should I proceed with the work I was doing to implement the original audio library? Thx. |
|
Oh... yeah. It's coming back. The previous api was just an experiment to figure out where i needed to go. It turns out that sound2midi doesn't have a good general algorithm for all instruments in complex music. It needs to have a collection of highly specialized algorithms. Vocals, beat detection, down beat, spectrum, spectral flux, attack, plus sound to midi for simple polyphonic types. There's 8 basic types and 30+ extended types, at least in theory. The issue here is that these sound detectors have a lot of overlapping attributes, like FFT, that are expensive to compute. You only want to compute them once. The the ideal api is registering callbacks for event handling. Its solves all the goals allows the smallest program size if you only use a subset. You can find it in the branch, I'll come back to it once i get the builds straightened out and the Software SPI 32 and Octo HW spi released. |
|
Awesome! I see you've been devoting a few cycles to this over the past several days. I'm looking forward to turning my attention back to this shortly. Thanks! |
…ly the handshake timeout (FastLED#5293) * ci(fbuild): require fbuild 2.5.52, drop the LPC8xx core pin, retry only the handshake timeout fbuild 2.5.52 builds the LPC8xx core at 547b5a7 itself (FastLED/fbuild#2078), so ci/boards.py no longer needs the framework-arduino-lpc8xx platform_packages override on the five LPC boards. 2.5.52 also fixes the 'session closed' serial attach of FastLED#5271 (FastLED/fbuild#2083, FastLED#2084, FastLED#2089): the client now reports the daemon's reason, so the retry's 'session closed' match was dead. What remains on a CPU-starved host is the client's 5 s handshake timeout (FastLED/fbuild#2095): 0 of 133 attaches failed at this host's own load (18-97), 11 of 16 at load 73-106 and 54 of 56 at 106-148 with CPU hogs added. NativeFbuildSerialAdapter now retries that timeout once without restarting the daemon, and a lost daemon still gets its own single restart. Also silence an unused-variable warning in SlimBridgeController on targets where FL_WARN_EVERY compiles out (seen in the lpc845 Blink build). Refs FastLED#5268, FastLED#5271, FastLED#5264 * fix: address CodeRabbit review feedback - Attach the retried handshake-timeout note to the error when the lost-daemon restart (ensure_fbuild_daemon) itself raises, so RpcBench still reports the first attempt; regression test added. * ci(serial): mark the daemon-restart try as KBI-handled by connect()
If matrix WIDTH < (2 x NUM_BINS) , then
int barWidth = WIDTH / NUM_BANDS= 1 (or even 0).So
barWidth - 1= 0,So the loop at line 198
for (int x = 0; x < barWidth - 1; x++)never executes.