Skip to content

Commit

Permalink
DRAFT FFT update
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Aug 6, 2024
1 parent ec00cc1 commit c9ae03f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
31 changes: 30 additions & 1 deletion src/AudioLibs/AudioEspressifFFT.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,34 @@ class FFTDriverEspressifFFT : public FFTDriver {
}
};

void rfft() override {
conjugate();
ret = dsps_fft2r_fc32(p_data, len);
if (ret != ESP_OK){
LOGE("dsps_fft2r_fc32 %d", ret);
}
conjugate();
// Bit reverse
ret = dsps_bit_rev_fc32(p_data, len);
if (ret != ESP_OK){
LOGE("dsps_bit_rev_fc32 %d", ret);
}
// Convert one complex vector to two complex vectors
ret = dsps_cplx2reC_fc32(p_data, len);
if (ret != ESP_OK){
LOGE("dsps_cplx2reC_fc32 %d", ret);
}
}

void conjugate(){
FFTBin bin;
for (int j=0;j<len;j++){
getBin(j, bin);
bin.conjugate();
setBin(j, bin);
}
}

float magnitude(int idx) override {
return sqrt(magnitudeFast(idx));
}
Expand All @@ -88,8 +116,9 @@ class FFTDriverEspressifFFT : public FFTDriver {
return true;
}

bool isReverseFFT() override {return true;}

virtual bool isValid() override{ return p_data!=nullptr && ret==ESP_OK; }
bool isValid() override{ return p_data!=nullptr && ret==ESP_OK; }

esp_err_t ret;
float *p_data = nullptr;
Expand Down
13 changes: 13 additions & 0 deletions src/AudioLibs/AudioFFT.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ struct FFTBin {
real *= f;
img *= f;
}

void conjugate(){
img = -img;
}

void clear() {
real = img = 0.0f;
}
Expand Down Expand Up @@ -320,6 +325,14 @@ class AudioFFTBase : public AudioOutput {
return p_magnitudes;
}

/// sets the value of a bin
bool setBin(int idx, float real, float img) {return p_driver->setBin(idx, real, img);}
/// sets the value of a bin
bool setBin(int pos, FFTBin &bin) { return p_driver->setBin(pos, bin.real, bin.img);}
/// gets the value of a bin
bool getBin(int pos, FFTBin &bin) { return p_driver->getBin(pos, bin);}


/// Provides the actual configuration
AudioFFTConfig &config() {
return cfg;
Expand Down
2 changes: 1 addition & 1 deletion src/AudioLibs/AudioRealFFT.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class FFTDriverRealFFT : public FFTDriver {
return (p_x[idx] * p_x[idx] + p_f[idx] * p_f[idx]);
}

virtual bool isValid() override{ return p_fft_object!=nullptr; }
bool isValid() override{ return p_fft_object!=nullptr; }

/// get Real value
float getValue(int idx) override { return p_x[idx];}
Expand Down
2 changes: 1 addition & 1 deletion src/AudioLibs/SDDirect.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace audio_tools {
/**
* @brief We access the files directy with an index. The index is determined by
* a recurseve tree walk thru the directory. Unfortunatly the SDTFAT library has
* it's own API which is incompatible with the SDT API
* it's own API which is incompatible with the SD API
*/
template <class SDT, class FileT>
class SDDirect {
Expand Down

0 comments on commit c9ae03f

Please sign in to comment.