FastLED 3.9.15
Loading...
Searching...
No Matches
fft_precision.h
Go to the documentation of this file.
1/*
2 * FFT Precision Configuration
3 *
4 * This header defines the precision mode for the FFT implementation.
5 *
6 * Usage:
7 * Define FASTLED_FFT_PRECISION before including this header to select precision mode:
8 *
9 * FASTLED_FFT_FLOAT (1) - 32-bit floating point (faster, moderate precision)
10 * FASTLED_FFT_DOUBLE (2) - 64-bit floating point (slower, high precision)
11 * FASTLED_FFT_FIXED16 (3) - 16-bit fixed point (default, memory efficient)
12 *
13 * Example:
14 * #define FASTLED_FFT_PRECISION FASTLED_FFT_FLOAT
15 * #include "fft_precision.h"
16 */
17
18#ifndef FFT_PRECISION_H
19#define FFT_PRECISION_H
20
21#include "fl/math/math.h"
22
23// Define precision mode constants
24#define FASTLED_FFT_FLOAT 1
25#define FASTLED_FFT_DOUBLE 2
26#define FASTLED_FFT_FIXED16 3
27
28// Default to FIXED16 if not specified (maintains backward compatibility)
29#ifndef FASTLED_FFT_PRECISION
30#define FASTLED_FFT_PRECISION FASTLED_FFT_FIXED16
31#endif
32
33// Define the floating point type used for math operations based on precision mode
34#if FASTLED_FFT_PRECISION == FASTLED_FFT_FLOAT
35 typedef float fft_float_t;
36#elif FASTLED_FFT_PRECISION == FASTLED_FFT_DOUBLE
37 typedef double fft_float_t;
38#elif FASTLED_FFT_PRECISION == FASTLED_FFT_FIXED16
39 typedef double fft_float_t; // Fixed point uses double for high precision internal math
40#else
41 #error "Invalid FASTLED_FFT_PRECISION value"
42#endif
43
44// Precision-aware math function macros
45// These select the appropriate float or double version based on the precision mode
46// Note: FIXED16 uses standard library (::) functions for backward compatibility with existing test expectations
47#if FASTLED_FFT_PRECISION == FASTLED_FFT_FLOAT
48 #define FFT_COS(x) fl::cosf((float)(x))
49 #define FFT_SIN(x) fl::sinf((float)(x))
50 #define FFT_EXP(x) fl::expf((float)(x))
51 #define FFT_LOG(x) fl::logf((float)(x))
52 #define FFT_SQRT(x) fl::sqrtf((float)(x))
53 #define FFT_POW(x,y) fl::powf((float)(x), (float)(y))
54#elif FASTLED_FFT_PRECISION == FASTLED_FFT_DOUBLE
55 #define FFT_COS(x) fl::cos((double)(x))
56 #define FFT_SIN(x) fl::sin((double)(x))
57 #define FFT_EXP(x) fl::exp((double)(x))
58 #define FFT_LOG(x) fl::log((double)(x))
59 #define FFT_SQRT(x) fl::sqrt((double)(x))
60 #define FFT_POW(x,y) fl::pow((double)(x), (double)(y))
61#elif FASTLED_FFT_PRECISION == FASTLED_FFT_FIXED16
62 // Use fl:: namespace functions for consistency with FastLED conventions
63 #define FFT_COS(x) fl::cos((double)(x))
64 #define FFT_SIN(x) fl::sin((double)(x))
65 #define FFT_EXP(x) fl::exp((double)(x))
66 #define FFT_LOG(x) fl::log((double)(x))
67 #define FFT_SQRT(x) fl::sqrt((double)(x))
68 #define FFT_POW(x,y) fl::pow((double)(x), (double)(y))
69#endif
70
71#endif // FFT_PRECISION_H
float fft_float_t