Skip to content

Commit

Permalink
(0_14 branch only) adding compatibility for building with upstream ar…
Browse files Browse the repository at this point in the history
…duinoFFT 2.xx

support compilation with new arduinoFFT versions 2.x
  • Loading branch information
softhack007 committed May 11, 2024
1 parent 197f47b commit ecc9443
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions usermods/audioreactive/audio_reactive.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,6 @@ constexpr uint16_t samplesFFT_2 = 256; // meaningfull part of FFT resul
// These are the input and output vectors. Input vectors receive computed results from FFT.
static float vReal[samplesFFT] = {0.0f}; // FFT sample inputs / freq output - these are our raw result bins
static float vImag[samplesFFT] = {0.0f}; // imaginary parts
#ifdef UM_AUDIOREACTIVE_USE_NEW_FFT
static float windowWeighingFactors[samplesFFT] = {0.0f};
#endif

// Create FFT object
#ifdef UM_AUDIOREACTIVE_USE_NEW_FFT
Expand All @@ -198,9 +195,15 @@ static float windowWeighingFactors[samplesFFT] = {0.0f};
#include <arduinoFFT.h>

#ifdef UM_AUDIOREACTIVE_USE_NEW_FFT
static ArduinoFFT<float> FFT = ArduinoFFT<float>( vReal, vImag, samplesFFT, SAMPLE_RATE, windowWeighingFactors);
#if defined(FFT_LIB_REV) && FFT_LIB_REV > 0x19
// arduinoFFT 2.x has a slightly different API
static ArduinoFFT<float> FFT = ArduinoFFT<float>( vReal, vImag, samplesFFT, SAMPLE_RATE, true);
#else
static float windowWeighingFactors[samplesFFT] = {0.0f}; // cache for FFT windowing factors
static ArduinoFFT<float> FFT = ArduinoFFT<float>( vReal, vImag, samplesFFT, SAMPLE_RATE, windowWeighingFactors);
#endif
#else
static arduinoFFT FFT = arduinoFFT(vReal, vImag, samplesFFT, SAMPLE_RATE);
static arduinoFFT FFT = arduinoFFT(vReal, vImag, samplesFFT, SAMPLE_RATE);
#endif

// Helper functions
Expand Down Expand Up @@ -300,7 +303,12 @@ void FFTcode(void * parameter)
#endif

#ifdef UM_AUDIOREACTIVE_USE_NEW_FFT
#if defined(FFT_LIB_REV) && FFT_LIB_REV > 0x19
// arduinoFFT 2.x has a slightly different API
FFT.majorPeak(&FFT_MajorPeak, &FFT_Magnitude); // let the effects know which freq was most dominant
#else
FFT.majorPeak(FFT_MajorPeak, FFT_Magnitude); // let the effects know which freq was most dominant
#endif
#else
FFT.MajorPeak(&FFT_MajorPeak, &FFT_Magnitude); // let the effects know which freq was most dominant
#endif
Expand Down
2 changes: 1 addition & 1 deletion usermods/audioreactive/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Alternatively, you can use the latest arduinoFFT development version.
ArduinoFFT `develop` library is slightly more accurate, and slightly faster than our customised library, however also needs additional 2kB RAM.

* `build_flags` = `-D USERMOD_AUDIOREACTIVE` `-D UM_AUDIOREACTIVE_USE_NEW_FFT`
* `lib_deps`= `https://github.com/kosme/arduinoFFT#develop @ 1.9.2`
* `lib_deps`= `https://github.com/kosme/arduinoFFT#419d7b0`

## Configuration

Expand Down

2 comments on commit ecc9443

@blazoncek
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@softhack007 are these changes relevant for 0_15 branch? They cause conflicts when I try to merge main into 0_15.

@softhack007
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blazoncek you can ignore this commit for 0_15. Its only for 0_14 to allow compiling with the latest compatible arduinoFFT.

Please sign in to comment.