arduino-audio-tools
AudioESP32FFT.h
1 #pragma once
2 
3 #include "AudioFFT.h"
4 #include "fft.h"
5 
13 namespace audio_tools {
14 
21 class FFTDriverESP32FFT : public FFTDriver {
22  public:
23  bool begin(int len) override {
24  this->len = len;
25  if (p_fft_object==nullptr) p_fft_object = fft_init(len, FFT_REAL, FFT_FORWARD, NULL, NULL);
26  assert(p_fft_object!=nullptr);
27  return p_fft_object!=nullptr;
28  }
29  void end()override{
30  if (p_fft_object!=nullptr) fft_destroy(p_fft_object);
31  }
32  void setValue(int idx, int value) override{
33  p_fft_object->input[idx] = value;
34  }
35 
36  void fft() override{
37  fft_execute(p_fft_object);
38  };
39 
40  float magnitude(int idx) override {
41  return sqrt(pow(p_fft_object->output[2*idx],2) + pow(p_fft_object->output[2*idx+1],2));
42  }
43 
45  float magnitudeFast(int idx) override {
46  return (pow(p_fft_object->output[2*idx],2) + pow(p_fft_object->output[2*idx+1],2));
47  }
48 
49  virtual bool isValid() override{ return p_fft_object!=nullptr; }
50 
51  fft_config_t *p_fft_object=nullptr;
52  int len;
53 
54 };
55 
63 class AudioESP32FFT : public AudioFFTBase {
64  public:
66 
68  float* array() {
69  return driverEx()->p_fft_object->output;
70  }
71 
72  FFTDriverESP32FFT* driverEx() {
73  return (FFTDriverESP32FFT*)driver();
74  }
75 };
76 
77 }
AudioFFT using RealFFT.
Definition: AudioESP32FFT.h:63
float * array()
Provides the result array returned by the FFT: The real part of a magnitude at a frequency is followe...
Definition: AudioESP32FFT.h:68
Executes FFT using audio data. The Driver which is passed in the constructor selects a specifc FFT im...
Definition: AudioFFT.h:82
AudioFFTBase(FFTDriver *driver)
Default Constructor. The len needs to be of the power of 2 (e.g. 512, 1024, 2048, 4096,...
Definition: AudioFFT.h:85
FFTDriver * driver()
provides access to the FFTDriver which implements the basic FFT functionality
Definition: AudioFFT.h:240
Driver for ESP32-FFT https://github.com/pschatzmann/esp32-fft
Definition: AudioESP32FFT.h:21
float magnitudeFast(int idx) override
magnitude w/o sqrt
Definition: AudioESP32FFT.h:45
Abstract Class which defines the basic FFT functionality.
Definition: AudioFFT.h:65
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition: AnalogAudio.h:10