diff options
Diffstat (limited to 'codec2_fft.h')
-rw-r--r-- | codec2_fft.h | 111 |
1 files changed, 53 insertions, 58 deletions
diff --git a/codec2_fft.h b/codec2_fft.h index c741202..1952864 100644 --- a/codec2_fft.h +++ b/codec2_fft.h | |||
@@ -9,96 +9,91 @@ | |||
9 | #define DRIVERS_FREEDV_CODEC2_FFT_H_ | 9 | #define DRIVERS_FREEDV_CODEC2_FFT_H_ |
10 | 10 | ||
11 | #include <assert.h> | 11 | #include <assert.h> |
12 | #include <stdlib.h> | 12 | #include <math.h> |
13 | #include <stdio.h> | 13 | #include <stdio.h> |
14 | #include <stdlib.h> | ||
14 | #include <string.h> | 15 | #include <string.h> |
15 | #include <math.h> | ||
16 | 16 | ||
17 | #ifdef FDV_ARM_MATH | 17 | #ifndef FDV_ARM_MATH |
18 | #include "fdv_arm_math.h" | 18 | #define USE_KISS_FFT |
19 | #else | 19 | #else |
20 | #define USE_KISS_FFT | 20 | #include "arm_const_structs.h" |
21 | #include "arm_math.h" | ||
21 | #endif | 22 | #endif |
22 | 23 | ||
23 | #include "defines.h" | ||
24 | #include "comp.h" | 24 | #include "comp.h" |
25 | #include "defines.h" | ||
25 | 26 | ||
26 | 27 | typedef COMP codec2_fft_cpx; | |
27 | typedef COMP codec2_fft_cpx; | ||
28 | #include "kiss_fftr.h" | 28 | #include "kiss_fftr.h" |
29 | 29 | ||
30 | #ifdef USE_KISS_FFT | 30 | #ifdef USE_KISS_FFT |
31 | #include "kiss_fft.h" | 31 | #include "kiss_fft.h" |
32 | typedef kiss_fftr_cfg codec2_fftr_cfg; | 32 | typedef kiss_fftr_cfg codec2_fftr_cfg; |
33 | typedef kiss_fft_cfg codec2_fft_cfg; | 33 | typedef kiss_fft_cfg codec2_fft_cfg; |
34 | typedef kiss_fft_scalar codec2_fft_scalar; | 34 | typedef kiss_fft_scalar codec2_fft_scalar; |
35 | #else | 35 | #else |
36 | typedef float32_t codec2_fft_scalar; | 36 | typedef float32_t codec2_fft_scalar; |
37 | typedef struct { | 37 | typedef struct { |
38 | arm_rfft_fast_instance_f32* instance; | 38 | arm_rfft_fast_instance_f32* instance; |
39 | int inverse; | 39 | int inverse; |
40 | } codec2_fftr_struct; | 40 | } codec2_fftr_struct; |
41 | 41 | ||
42 | typedef codec2_fftr_struct* codec2_fftr_cfg; | 42 | typedef codec2_fftr_struct* codec2_fftr_cfg; |
43 | 43 | ||
44 | typedef struct { | 44 | typedef struct { |
45 | const arm_cfft_instance_f32* instance; | 45 | const arm_cfft_instance_f32* instance; |
46 | int inverse; | 46 | int inverse; |
47 | } codec2_fft_struct; | 47 | } codec2_fft_struct; |
48 | typedef codec2_fft_struct* codec2_fft_cfg; | 48 | typedef codec2_fft_struct* codec2_fft_cfg; |
49 | #endif | 49 | #endif |
50 | 50 | ||
51 | 51 | static inline void codec2_fftr(codec2_fftr_cfg cfg, codec2_fft_scalar* in, | |
52 | 52 | codec2_fft_cpx* out) { | |
53 | static inline void codec2_fftr(codec2_fftr_cfg cfg, codec2_fft_scalar* in, codec2_fft_cpx* out) | ||
54 | { | ||
55 | |||
56 | #ifdef USE_KISS_FFT | 53 | #ifdef USE_KISS_FFT |
57 | kiss_fftr(cfg, in, (kiss_fft_cpx*)out); | 54 | kiss_fftr(cfg, in, (kiss_fft_cpx*)out); |
58 | #else | 55 | #else |
59 | arm_rfft_fast_f32(cfg->instance,in,(float*)out,cfg->inverse); | 56 | arm_rfft_fast_f32(cfg->instance, in, (float*)out, cfg->inverse); |
60 | out->imag = 0; // remove out[FFT_ENC/2]->real stored in out[0].imag | 57 | out->imag = 0; // remove out[FFT_ENC/2]->real stored in out[0].imag |
61 | #endif | 58 | #endif |
62 | } | 59 | } |
63 | 60 | ||
64 | static inline void codec2_fftri(codec2_fftr_cfg cfg, codec2_fft_cpx* in, codec2_fft_scalar* out) | 61 | static inline void codec2_fftri(codec2_fftr_cfg cfg, codec2_fft_cpx* in, |
65 | { | 62 | codec2_fft_scalar* out) { |
66 | #ifdef USE_KISS_FFT | 63 | #ifdef USE_KISS_FFT |
67 | kiss_fftri(cfg, (kiss_fft_cpx*)in, out); | 64 | kiss_fftri(cfg, (kiss_fft_cpx*)in, out); |
68 | #else | 65 | #else |
69 | arm_rfft_fast_f32(cfg->instance,(float*)in,out,cfg->inverse); | 66 | arm_rfft_fast_f32(cfg->instance, (float*)in, out, cfg->inverse); |
70 | // arm_scale_f32(out,cfg->instance->fftLenRFFT,out,cfg->instance->fftLenRFFT); | 67 | // arm_scale_f32(out,cfg->instance->fftLenRFFT,out,cfg->instance->fftLenRFFT); |
71 | #endif | 68 | #endif |
72 | |||
73 | } | 69 | } |
74 | 70 | ||
75 | codec2_fft_cfg codec2_fft_alloc(int nfft, int inverse_fft, void* mem, size_t* lenmem); | 71 | codec2_fft_cfg codec2_fft_alloc(int nfft, int inverse_fft, void* mem, |
76 | codec2_fftr_cfg codec2_fftr_alloc(int nfft, int inverse_fft, void* mem, size_t* lenmem); | 72 | size_t* lenmem); |
73 | codec2_fftr_cfg codec2_fftr_alloc(int nfft, int inverse_fft, void* mem, | ||
74 | size_t* lenmem); | ||
77 | void codec2_fft_free(codec2_fft_cfg cfg); | 75 | void codec2_fft_free(codec2_fft_cfg cfg); |
78 | void codec2_fftr_free(codec2_fftr_cfg cfg); | 76 | void codec2_fftr_free(codec2_fftr_cfg cfg); |
79 | 77 | ||
80 | 78 | static inline void codec2_fft(codec2_fft_cfg cfg, codec2_fft_cpx* in, | |
81 | static inline void codec2_fft(codec2_fft_cfg cfg, codec2_fft_cpx* in, codec2_fft_cpx* out) | 79 | codec2_fft_cpx* out) { |
82 | { | ||
83 | |||
84 | #ifdef USE_KISS_FFT | 80 | #ifdef USE_KISS_FFT |
85 | kiss_fft(cfg, (kiss_fft_cpx*)in, (kiss_fft_cpx*)out); | 81 | kiss_fft(cfg, (kiss_fft_cpx*)in, (kiss_fft_cpx*)out); |
86 | #else | 82 | #else |
87 | memcpy(out,in,cfg->instance->fftLen*2*sizeof(float)); | 83 | memcpy(out, in, cfg->instance->fftLen * 2 * sizeof(float)); |
88 | arm_cfft_f32(cfg->instance,(float*)out,cfg->inverse, 1); | 84 | arm_cfft_f32(cfg->instance, (float*)out, cfg->inverse, 1); |
89 | // TODO: this is not nice, but for now required to keep changes minimal | 85 | // TODO: this is not nice, but for now required to keep changes minimal |
90 | // however, since main goal is to reduce the memory usage | 86 | // however, since main goal is to reduce the memory usage |
91 | // we should convert to an in place interface | 87 | // we should convert to an in place interface |
92 | // on PC like platforms the overhead of using the "inplace" kiss_fft calls | 88 | // on PC like platforms the overhead of using the "inplace" kiss_fft calls |
93 | // is neglectable compared to the gain in memory usage on STM32 platforms | 89 | // is neglectable compared to the gain in memory usage on STM32 platforms |
94 | if (cfg->inverse) | 90 | if (cfg->inverse) { |
95 | { | 91 | arm_scale_f32((float*)out, cfg->instance->fftLen, (float*)out, |
96 | arm_scale_f32((float*)out,cfg->instance->fftLen,(float*)out,cfg->instance->fftLen*2); | 92 | cfg->instance->fftLen * 2); |
97 | } | 93 | } |
98 | #endif | 94 | #endif |
99 | } | 95 | } |
100 | 96 | ||
101 | void codec2_fft_inplace(codec2_fft_cfg cfg, codec2_fft_cpx* inout); | 97 | void codec2_fft_inplace(codec2_fft_cfg cfg, codec2_fft_cpx* inout); |
102 | 98 | ||
103 | |||
104 | #endif | 99 | #endif |