We probably don’t need to tell the average Hackaday reader that the ESP32 is a powerful and extremely flexible microcontroller. We’ve seen some incredible projects using this affordable chip over the last few years, and by the looks of it, the best is yet to come. That’s because it always takes some time before the community can really figure out how to get the most out of a piece of hardware.
Take for example the Bluetooth audio player that [squix] was recently working on. Getting the music going was no problem with the esp32-a2dp library, but when he wanted to add some visualizations the audio quality took a serious hit. Realizing that his Fast Fourier transform (FFT) code was eating up too much processor power, it seemed like a great time for him to explore using the ESP32’s second core.
[squix] had avoided poking around with the dual-core nature of the ESP32 in the past, believing that the second core was busy handling the WiFi communication. But by using the FreeRTOS queue system, he wrote some code that collects audio data with one core and runs the actual FFT magic on the other. By balancing the workload like this, he’s able to drive the array of 64 WS2812B LEDs on the front of the Icon64 seen in the video after the break.
Even if you’re not terribly interested in running your own microcontroller disco, this project may be just the example you’ve been waiting for to help get your mind wrapped around multitasking on the ESP32. If you want to master a device with this many tricks up its sleeve, you’ll need all the help you can get.
Cool, thanks for post, nice to see more products and research on this platform, thanks
Maybe better to implement a Goertzel algorithm ? https://hackaday.com/2020/11/13/dsp-spreadsheet-the-goertzel-algorithm-is-fouriers-simpler-cousin/
https://github.com/jacobrosenthal/Goertzel
Thank you, I wasn’t aware of the Goertzel algorithm. I was also wondering if sequentially low/high pass filters might accomplish the same but couldn’t find any description for that. FFT is the one hammer I know;-)
The CQT is also a simpler transform which takes powers of 2 frequency bins into account, which maps really well to audio applications like this :)
If a processor running at 160mhz is not able to run your fft algorithm then there is something seriously wrong with that algorithm. A 16 bit uc running at 20mhz runs fft fine at 100hz update rate on the audio spectrum range.
Regardless, its a good experience for how to fire up the second core.
Keep in mind that apart from the FFT you have to:
– Handle WiFi/BT (depends on how the music is streamed)
– Play the audio through analog
– Control the LEDs
> – Handle WiFi/BT (depends on how the music is streamed)
2 core
> – Control the LEDs
Hardware DMA (no cpu usage)
> – Play the audio through analog
Is it so heavy?
A2DP can transport a Mp3 or even AAC stream. Decoding time depends on the bitrate. I could get the ESP8266 working reliably only with 96kbit/s mono mp3. I totally buy that a more intensive AAC stream at possibly even higher bitrate keeps one core of tje ESP32 completely busy.
Not all machine languages are created equal (by far). If my info is correct, the ESP instruction set takes a lot more instructions to do the same things a more normal processor does in few. I also heard there is quite a bit of fooling around with moving things between very slow flash and the operating ram to make the ram look larger. All hidden by the tools, but still there.
I have an unidentified board from something marked as FFT/Micro Board. It has an 80c88 and a 12Mhz crystal, but I was assuming that was halved to 6Mhz. It has some fast ADCs and analog signal conditioning, so I assume it’s actually for Fourier Transforms and not some other FFT. However, it would have been running machine code from ROM, no OS in the way.
Back in the day I had a demo on the Amiga (IFT-Scope) that ran a realtime (50/60Hz) full-screen FFT on either a playing MOD file or sampled audio from a standard parallel port sampler – a standard A1200 is 14MHz / 2Mb RAM including video RAM.
NeoPixelBus will drive WS2812 LEDs on the ESP using hardware support.
Where can get a project files?
I’m too interested in the project files (program script, schematic .. )
Thank-you
Thanks! I’ll follow this path. One thread for ADC and a second for FFT and display. It’s alternativlos.
I’m not sure people are aware that a single thread approach is flawed by default unless your MCU can precess FFT and display faster than “a few” ms.
If processing takes longer than “a few” ms there will be a recording gap which will miss beats. If you want a slow meaningless spectrum display that may be okay, but a real-time visualization capturing the beats and displaying instantly won’t be possible. I tried. For example I acquire 25ms per loop which results in a desired lower cutoff of 40Hz. So I need a parallel thread for display which must be faster than 25ms. My FFT needs ~16ms, IC2 display with bands takes ~36ms and 8 neopixel LEDs need 1ms.