新建会话
Ctrl
K
  • 网站
  • 文档
  • PPT
  • 表格
  • 深度研究
Kimi Code Kimi Claw
历史会话
查看手机应用
  • 关于我们
    • 探索月之暗面
    • 开放平台
    • 社会招聘
    • 校园招聘
    • 用户协议
    • 隐私协议
  • Language
  • 用户反馈

ESP32 audio FFT library

One of the advantages of Teensy seems to be the audio design tool that allows quick and easy access and manipulation of the audio streams. So, I was looking for an ESP32 library to pop in that could perform FFT on received Bluetooth audio. It seems like some have done it, but it’s a little convoluted (e,g, this example). I admit that I have been spoiled by working in the Arduino ecosystem where everything is de-boned and soft for easy consumption! Do you offhand know of a similarly easy library or method to the Teensy one to work with for the ESP32?
搜索
ESP32 FFT implementation for Bluetooth audio
20 个结果
There is nothing quite as “drag-and-drop” as the Teensy Audio System Design Tool, but you can get surprisingly close on an ESP32 if you pick the right combination of libraries.
Here is the shortest path that the community has settled on:
  1. Get the audio into the chip – use Phil Schatzmann’s ESP32-A2DP sink.
    • Install it from the Library Manager (“ESP32-A2DP”).
    • With one line (a2dp_sink.start("MyESP")) you have a working A2DP receiver that hands you every decoded PCM sample through a user callback.
    • The data arrive as 16-bit 44.1 kHz stereo interleaved, so you already have the same format the Teensy audio tool uses.
  2. Run the FFT – use the official esp-dsp library (works in Arduino, not only ESP-IDF).
    • Install it from the Library Manager (“ESP-DSP”).
    • It gives you an optimized radix-4 FFT that takes a float vector and returns magnitude/phase.
    • No fixed block size, so you can choose 256/512/1024 points to match your animation or latency needs.
  3. Glue the two together – literally 20 lines of code:
cpp
复制
#include <BluetoothA2DPSink.h>
#include <dsplib.h>

BluetoothA2DPSink a2dp;
constexpr int FFT_N = 512;
float   fft_in[FFT_N];
float   fft_out[FFT_N];
int     sampleCnt = 0;

// called for every 4 bytes (L+R) of A2DP data
void read_data_stream(const uint8_t *data, uint32_t len) {
  for (uint32_t i = 0; i < len; i += 4) {
    int16_t L = (int16_t)(data[i+1]<<8 | data[i]);
    int16_t R = (int16_t)(data[i+3]<<8 | data[i+2]);
    fft_in[sampleCnt++] = (L + R) * 0.5f;        // mono mix

    if (sampleCnt == FFT_N) {                    // buffer full → FFT
      dsps_fft2r_fc32(fft_in, FFT_N);
      dsps_bit_rev2r_fc32(fft_in, FFT_N);
      dsps_cplx2real_fc32(fft_in, FFT_N);
      // fft_in now holds FFT_N/2 magnitude bins
      sampleCnt = 0;
      // …update your LEDs here…
    }
  }
}

void setup() {
  dsps_fft2r_init_fc32(NULL, FFT_N);   // init DSP-FFT once
  a2dp.start("ESP32-Spectrum");
  a2dp.set_stream_reader(read_data_stream);
}

void loop() {}
That is the entire “audio system”: A2DP feeds samples → buffer → FFT → LED buffer.
No DMA fiddling, no I²S configuration, no external codec needed if you only want the spectrum.
Need a ready-made spectrum analyzer example?
Grab the one in the Elektor book archive () – it already combines the two libraries and prints the dominant frequency to the Serial monitor; swap the print for your LED routine and you are done.
If you later want more audio blocks (filters, peak detectors, VU meters…) the same author’s arduino-audio-tools collection () gives you a “pipeline” class that feels very Teensy-like: you just addStream(fft) or addStream(lowpass) and call copy() in loop.
So while the ESP32 world is still more “lego bricks” than a single GUI, the bricks above are essentially the Teensy audio library ported and ready; you can have Bluetooth audio → FFT → pretty lights running in under five minutes once the libraries are installed.