FastLED 3.9.15
Loading...
Searching...
No Matches
kiss_fft.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2003-2010, Mark Borgerding. All rights reserved.
3 * This file is part of KISS FFT - https://github.com/mborgerding/kissfft
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 * See COPYING file for more information.
7 */
8
9#ifndef KISS_FFT_H
10#define KISS_FFT_H
11
12#include "fl/stl/cstdlib.h"
13#include "fl/stl/stdio.h"
14#include "fl/stl/stdint.h"
15#include "fl/math/math.h"
16#include "fl/stl/string.h"
17#include "fl/stl/malloc.h"
18#include "fft_precision.h"
19
20// Configure FIXED_POINT based on precision mode
21#if FASTLED_FFT_PRECISION == FASTLED_FFT_FIXED16
22 #define FIXED_POINT 1
23#elif FASTLED_FFT_PRECISION == FASTLED_FFT_FLOAT
24 // No FIXED_POINT for float mode
25#elif FASTLED_FFT_PRECISION == FASTLED_FFT_DOUBLE
26 // No FIXED_POINT for double mode
27#endif
28
29// WROVER and WROOM have 4MB of PSRAM or more.
30#if KISS_FFT_USE_ESP32_PSRAM
31#include "esp_heap_caps.h"
32#endif
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38/*
39 ATTENTION!
40 If you would like a :
41 -- a utility that will handle the caching of fft objects
42 -- real-only (no imaginary time component ) FFT
43 -- a multi-dimensional FFT
44 -- a command-line utility to perform ffts
45 -- a command-line utility to perform fast-convolution filtering
46
47 Then see kfc.h kiss_fftr.h kiss_fftnd.h fftutil.c kiss_fastfir.c
48 in the tools/ directory.
49*/
50
51#if KISS_FFT_USE_ESP32_PSRAM
52#define KISS_FFT_MALLOC(nbytes) heap_caps_malloc(nbytes, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT)
53#define KISS_FFT_FREE free
54#elif defined(USE_SIMD)
55# include <xmmintrin.h>
56# define kiss_fft_scalar __m128
57#define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes,16)
58#define KISS_FFT_FREE _mm_free
59#else
60#define KISS_FFT_MALLOC(nbytes) fl::malloc(nbytes)
61#define KISS_FFT_FREE(ptr) fl::free(ptr)
62#endif
63
64
65#ifdef FIXED_POINT
66# if (FIXED_POINT == 32)
67# define kiss_fft_scalar int32_t
68# else
69# define kiss_fft_scalar int16_t
70# endif
71#else
72# ifndef kiss_fft_scalar
73// Use precision-aware float type from fft_precision.h
74# if FASTLED_FFT_PRECISION == FASTLED_FFT_FLOAT
75# define kiss_fft_scalar float
76# elif FASTLED_FFT_PRECISION == FASTLED_FFT_DOUBLE
77# define kiss_fft_scalar double
78# else
79# define kiss_fft_scalar float // default fallback
80# endif
81# endif
82#endif
83
88
90
91/*
92 * kiss_fft_alloc
93 *
94 * Initialize a FFT (or IFFT) algorithm's cfg/state buffer.
95 *
96 * typical usage: kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL);
97 *
98 * The return value from fft_alloc is a cfg buffer used internally
99 * by the fft routine or NULL.
100 *
101 * If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc.
102 * The returned value should be free()d when done to avoid memory leaks.
103 *
104 * The state can be placed in a user supplied buffer 'mem':
105 * If lenmem is not NULL and mem is not NULL and *lenmem is large enough,
106 * then the function places the cfg in mem and the size used in *lenmem
107 * and returns mem.
108 *
109 * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough),
110 * then the function returns NULL and places the minimum cfg
111 * buffer size in *lenmem.
112 * */
113
114kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem);
115
116/*
117 * kiss_fft(cfg,in_out_buf)
118 *
119 * Perform an FFT on a complex input buffer.
120 * for a forward FFT,
121 * fin should be f[0] , f[1] , ... ,f[nfft-1]
122 * fout will be F[0] , F[1] , ... ,F[nfft-1]
123 * Note that each element is complex and can be accessed like
124 f[k].r and f[k].i
125 * */
126void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
127
128/*
129 A more generic version of the above function. It reads its input from every Nth sample.
130 * */
131void kiss_fft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride);
132
133/* If kiss_fft_alloc allocated a buffer, it is one contiguous
134 buffer and can be simply free()d when no longer needed*/
135#define kiss_fft_free KISS_FFT_FREE
136
137/*
138 Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up
139 your compiler output to call this before you exit.
140*/
141void kiss_fft_cleanup(void);
142
143
144/*
145 * Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5)
146 */
147int kiss_fft_next_fast_size(int n);
148
149/* for real ffts, we need an even size */
150#define kiss_fftr_next_fast_size_real(n) \
151 (kiss_fft_next_fast_size( ((n)+1)>>1)<<1)
152
153#ifdef __cplusplus
154}
155#endif
156
157#endif
void kiss_fft_stride(kiss_fft_cfg cfg, const kiss_fft_cpx *fin, kiss_fft_cpx *fout, int fin_stride)
int kiss_fft_next_fast_size(int n)
#define kiss_fft_scalar
Definition kiss_fft.h:69
void kiss_fft_cleanup(void)
void kiss_fft(kiss_fft_cfg cfg, const kiss_fft_cpx *fin, kiss_fft_cpx *fout)
kiss_fft_cfg kiss_fft_alloc(int nfft, int inverse_fft, void *mem, size_t *lenmem)
struct kiss_fft_state * kiss_fft_cfg
Definition kiss_fft.h:89
kiss_fft_scalar r
Definition kiss_fft.h:85
kiss_fft_scalar i
Definition kiss_fft.h:86