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