Skip to content

Fix Audio advanced.h drawSpectrumBars() - #2089

Merged
zackees merged 1 commit into
FastLED:masterfrom
4wheeljive:patch-2
Sep 25, 2025
Merged

zackees merged 1 commit into
FastLED:masterfrom
4wheeljive:patch-2

Conversation

@4wheeljive

Copy link
Copy Markdown
Contributor

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.

@zackees
zackees merged commit 09cad6a into FastLED:master Sep 25, 2025
@zackees

zackees commented Sep 25, 2025

Copy link
Copy Markdown
Member

thank you.

@zackees

zackees commented Sep 25, 2025

Copy link
Copy Markdown
Member

It's a little rough in this part of the codebase. Any changes you propose for fixups is greatly appreciated.

@4wheeljive

Copy link
Copy Markdown
Contributor Author

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:

  1. Begin more or less with the Audio Advanced example
  2. Figure out how to insert portions of the AudioInput example (and the audio_input library) to use I2S for audio capture
  3. Add in hooks to the AudioReactive library

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 bool noiseGate element; but as far as I can tell, this is purely a placeholder at the moment. In my project, I would like to employ an early-in-the-chain noise gate/filter/floor of some sort, and I'm wondering: Do you have any percolating thoughts about how you might incorporate noise filtering into AudioReactive? If so, I'd love to learn about that. Otherwise, I'll just keep working on rolling my own solution that I will place between currentSample = audioSource->read() and audio.processSample(currentSample)

I will be more than happy to share what I've been working on.

Thanks,
Jeff

@zackees

zackees commented Sep 29, 2025

Copy link
Copy Markdown
Member

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 claude code called clud and use that to develop, which will trigger god mode by default.

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.

@4wheeljive

4wheeljive commented Oct 1, 2025 •

Copy link
Copy Markdown
Contributor Author

Thanks, Zach. This info is super helpful!

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?

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:

  • BACKEND / AUDIO INTERFACE:

    • captures input from potentially any analog or digital audio source

      • can receive audio in a "generic" way from any device (with auto and/or manual input settings)
      • can optionally be pre-configured for specific devices (e.g., INMP441)
    • may perform simple signal processing (e.g., noise floor/filtering, gain adjustment)

    • [any reason for optional pass-through of analog signal also?]

    • outputs a standardized sampled audio buffer (pcm)

      <---> specific characteristics TBD <--->

  • MIDDLE / AUDIO PROCESSING:

    • Parses and transforms raw aggregate pcm stream into more usable audio data objects

    • FFT/frequency bin creation

    • Scales/normalizes gain/levels

    • Smoothing

    • Enhanced processing

      • Beat detection (enhanced/multi-band)
      • Spectral weighting
    • Outputs a comprehensive, standardized set of integral and optional data, methods, functions

      <---> specific characteristics TBD <--->

  • AUDIO APPLICATION:

    • Class structure, methods, parameters, data, getters, setters, helpers, etc. for using the output from AUDIO PROCESSING in a standardized, normalized, predictable way

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?

@4wheeljive

Copy link
Copy Markdown
Contributor Author

https://youtu.be/SM-4ZamYaYM
FYI, here's a video I shot last night of my test project in action. This is using the I2S input, going through FL Audio Reactive processing, and into a refactored Radial Spectrum visualizer from the Audio Advanced example. A good place to jump in for a quick view might be around 1:45.

@zackees

zackees commented Oct 1, 2025

Copy link
Copy Markdown
Member

Thanks, Zach. This info is super helpful!

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?

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:

  • BACKEND / AUDIO INTERFACE:

    • captures input from potentially any analog or digital audio source

      • can receive audio in a "generic" way from any device (with auto and/or manual input settings)
      • can optionally be pre-configured for specific devices (e.g., INMP441)
    • may perform simple signal processing (e.g., noise floor/filtering, gain adjustment)

    • [any reason for optional pass-through of analog signal also?]

    • outputs a standardized sampled audio buffer (pcm)
      <---> specific characteristics TBD <--->

  • MIDDLE / AUDIO PROCESSING:

    • Parses and transforms raw aggregate pcm stream into more usable audio data objects

    • FFT/frequency bin creation

    • Scales/normalizes gain/levels

    • Smoothing

    • Enhanced processing

      • Beat detection (enhanced/multi-band)
      • Spectral weighting
    • Outputs a comprehensive, standardized set of integral and optional data, methods, functions
      <---> specific characteristics TBD <--->

  • AUDIO APPLICATION:

    • Class structure, methods, parameters, data, getters, setters, helpers, etc. for using the output from AUDIO ANALYSIS in a standardized, normalized, predictable way

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 audio 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?

You pretty much nailed it exactly.

Do you have thoughts on where the the db conversion tuning for INMP411 should go?

@zackees

zackees commented Oct 1, 2025

Copy link
Copy Markdown
Member

https://youtu.be/SM-4ZamYaYM FYI, here's a video I shot last night of my test project in action. This is using the I2S input, going through FL Audio Reactive processing, and into a refactored Radial Spectrum visualizer from the Audio Advanced example. A good place to jump in for a quick view might be around 1:45.

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.

@zackees

zackees commented Oct 1, 2025

Copy link
Copy Markdown
Member

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:

https://www.youtube.com/watch?v=_6Msl1PyyRU

@4wheeljive

Copy link
Copy Markdown
Contributor Author

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 animartrixEngine.setSpeed(1). I'll definitely need to explore this further (especially as timing becomes more important with audio elements)!

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!

@zackees

zackees commented Oct 2, 2025

Copy link
Copy Markdown
Member

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.

Correct.

Thx for sharing your FFT video. Very cool! And indeed inspiring. We definitely need some good audio-enabled scrolling visualizers like that!

Check out examples/Audio/simple/** this is where the FFT demo lives.

@4wheeljive

Copy link
Copy Markdown
Contributor Author

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!

@zackees

zackees commented Oct 4, 2025 •

Copy link
Copy Markdown
Member

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!

@4wheeljive

Copy link
Copy Markdown
Contributor Author

Holy shit! This is game-changing!

@4wheeljive

Copy link
Copy Markdown
Contributor Author

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!

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.

@zackees

zackees commented Oct 24, 2025 •

Copy link
Copy Markdown
Member

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, audio

I'll come back to it once i get the builds straightened out and the Software SPI 32 and Octo HW spi released.

@4wheeljive

Copy link
Copy Markdown
Contributor Author

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!

sutaburosu pushed a commit to sutaburosu/FastLED that referenced this pull request Nov 19, 2026
…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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants