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