@@ -6,28 +6,32 @@ The float FFT implementation is come from esp-dsp. And we further optimized the
66For int16 FFT, we recommend to use ` dl_fft_s16_hp_run ` or ` dl_rfft_s16_hp_run ` interface. ` hp ` means "high precision".
77
88## Get Started
9+
10+ ### C interface
911```
1012
1113#include "dl_fft.h"
1214#include "dl_rfft.h"
1315
1416// float fft
1517float x[nfft*2];
18+
19+ float *x = (float *)heap_caps_aligned_alloc(16, nfft * sizeof(float) *2, MALLOC_CAP_8BIT);
1620dl_fft_f32_t *fft_handle = dl_fft_f32_init(nfft, MALLOC_CAP_8BIT);
1721dl_fft_f32_run(fft_handle, x);
1822dl_ifft_f32_run(fft_handle, x);
1923dl_fft_f32_deinit(fft_handle);
2024
2125// float rfft
22- float x[ nfft] ;
26+ float *x = (float *)heap_caps_aligned_alloc(16, nfft * sizeof(float), MALLOC_CAP_8BIT) ;
2327dl_fft_f32_t *fft_handle = dl_rfft_f32_init(nfft, MALLOC_CAP_8BIT);
2428dl_rfft_f32_run(fft_handle, x);
2529dl_irfft_f32_run(fft_handle, x);
2630dl_rfft_f32_deinit(fft_handle);
2731
2832// int16 fft
29- int16_t x[ nfft*2] ;
30- float y[ nfft*2] ;
33+ int16_t *x= (float *)heap_caps_aligned_alloc(16, nfft * sizeof(int16_t) * 2, MALLOC_CAP_8BIT) ;
34+ float *y = (float *)heap_caps_aligned_alloc(16, nfft * sizeof(float) *2, MALLOC_CAP_8BIT) ;
3135int in_exponent = -15; // float y = x * 2^in_exponent;
3236int fft_exponent;
3337int ifft_exponent;
@@ -38,8 +42,8 @@ dl_short_to_float(x, nfft, ifft_exponent, y); // convert output from int16_t to
3842dl_fft_s16_deinit(fft_handle);
3943
4044// int16 rfft
41- int16_t x[ nfft] ;
42- float y[ nfft] ;
45+ int16_t *x= (float *)heap_caps_aligned_alloc(16, nfft * sizeof(int16_t), MALLOC_CAP_8BIT) ;
46+ float *y = (float *)heap_caps_aligned_alloc(16, nfft * sizeof(float), MALLOC_CAP_8BIT) ;
4347int in_exponent = -15; // float y = x * 2^in_exponent;
4448int fft_exponent;
4549int ifft_exponent;
@@ -53,6 +57,32 @@ dl_rfft_s16_deinit(fft_handle);
5357```
5458Please refer to [ dl_fft.h] ( ./dl_fft.h ) and [ dl_rfft.h] ( ./dl_rfft.h ) for more details.
5559
60+
61+ ### C++ interface:
62+ ```
63+ float *x1 = (float *)heap_caps_aligned_alloc(16, nfft * sizeof(float) *2, MALLOC_CAP_8BIT);
64+ int16_t *x2= (float *)heap_caps_aligned_alloc(16, nfft * sizeof(int16_t)*2, MALLOC_CAP_8BIT);
65+ FFT *fft = FFT::get_instance();
66+
67+ # float
68+ fft->fft(x1, nfft);
69+ fft->ifft(x1, nfft);
70+ fft->rfft(x1, nfft);
71+ fft->irfft(x1, nfft);
72+
73+ #int16_t
74+ int in_exponent=-15;
75+ int out_exponent;
76+ fft->fft_hp(x2, nfft, in_exponent, &out_exponent);
77+ fft->ifft_hp(x2, nfft, in_exponent, &out_exponent);
78+ fft->rfft_hp(x2, nfft, in_exponent, &out_exponent);
79+ fft->irfft_hp(x2, nfft, in_exponent, &out_exponent);
80+ ```
81+ Please refer to [ dl_fft.hpp] ( ./dl_fft.hpp ) for more details.
82+
83+ > Note: The input array x must be allocated with heap_caps_aligned_alloc and aligned to 16 bytes.
84+
85+
5686## FAQ:
5787
5888#### 1. Why not just use esp-dsp directly?
0 commit comments