Skip to content

Commit ecc9443

Browse files
committed
(0_14 branch only) adding compatibility for building with upstream arduinoFFT 2.xx
support compilation with new arduinoFFT versions 2.x
1 parent 197f47b commit ecc9443

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

usermods/audioreactive/audio_reactive.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,6 @@ constexpr uint16_t samplesFFT_2 = 256; // meaningfull part of FFT resul
177177
// These are the input and output vectors. Input vectors receive computed results from FFT.
178178
static float vReal[samplesFFT] = {0.0f}; // FFT sample inputs / freq output - these are our raw result bins
179179
static float vImag[samplesFFT] = {0.0f}; // imaginary parts
180-
#ifdef UM_AUDIOREACTIVE_USE_NEW_FFT
181-
static float windowWeighingFactors[samplesFFT] = {0.0f};
182-
#endif
183180

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

200197
#ifdef UM_AUDIOREACTIVE_USE_NEW_FFT
201-
static ArduinoFFT<float> FFT = ArduinoFFT<float>( vReal, vImag, samplesFFT, SAMPLE_RATE, windowWeighingFactors);
198+
#if defined(FFT_LIB_REV) && FFT_LIB_REV > 0x19
199+
// arduinoFFT 2.x has a slightly different API
200+
static ArduinoFFT<float> FFT = ArduinoFFT<float>( vReal, vImag, samplesFFT, SAMPLE_RATE, true);
201+
#else
202+
static float windowWeighingFactors[samplesFFT] = {0.0f}; // cache for FFT windowing factors
203+
static ArduinoFFT<float> FFT = ArduinoFFT<float>( vReal, vImag, samplesFFT, SAMPLE_RATE, windowWeighingFactors);
204+
#endif
202205
#else
203-
static arduinoFFT FFT = arduinoFFT(vReal, vImag, samplesFFT, SAMPLE_RATE);
206+
static arduinoFFT FFT = arduinoFFT(vReal, vImag, samplesFFT, SAMPLE_RATE);
204207
#endif
205208

206209
// Helper functions
@@ -300,7 +303,12 @@ void FFTcode(void * parameter)
300303
#endif
301304

302305
#ifdef UM_AUDIOREACTIVE_USE_NEW_FFT
306+
#if defined(FFT_LIB_REV) && FFT_LIB_REV > 0x19
307+
// arduinoFFT 2.x has a slightly different API
308+
FFT.majorPeak(&FFT_MajorPeak, &FFT_Magnitude); // let the effects know which freq was most dominant
309+
#else
303310
FFT.majorPeak(FFT_MajorPeak, FFT_Magnitude); // let the effects know which freq was most dominant
311+
#endif
304312
#else
305313
FFT.MajorPeak(&FFT_MajorPeak, &FFT_Magnitude); // let the effects know which freq was most dominant
306314
#endif

usermods/audioreactive/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Alternatively, you can use the latest arduinoFFT development version.
3838
ArduinoFFT `develop` library is slightly more accurate, and slightly faster than our customised library, however also needs additional 2kB RAM.
3939

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

4343
## Configuration
4444

0 commit comments

Comments
 (0)