summaryrefslogtreecommitdiff
path: root/codec2_fft.h
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2025-08-15 12:42:40 +0200
committererdgeist <erdgeist@erdgeist.org>2025-08-15 12:42:40 +0200
commit30325d24d107dbf133da39f7c96d1510fd1c9449 (patch)
tree932baa5b2a4475821f16dccf9e3e05011daa6d92 /codec2_fft.h
parent9022d768021bbe15c7815cc6f8b64218b46f0e10 (diff)
Bump to codec2 version 1.2.0erdgeist-bump-to-1.2.0
Diffstat (limited to 'codec2_fft.h')
-rw-r--r--codec2_fft.h111
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 27typedef COMP codec2_fft_cpx;
27typedef 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; 32typedef kiss_fftr_cfg codec2_fftr_cfg;
33 typedef kiss_fft_cfg codec2_fft_cfg; 33typedef kiss_fft_cfg codec2_fft_cfg;
34 typedef kiss_fft_scalar codec2_fft_scalar; 34typedef kiss_fft_scalar codec2_fft_scalar;
35#else 35#else
36 typedef float32_t codec2_fft_scalar; 36typedef float32_t codec2_fft_scalar;
37 typedef struct { 37typedef 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; 42typedef codec2_fftr_struct* codec2_fftr_cfg;
43 43
44 typedef struct { 44typedef 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; 48typedef codec2_fft_struct* codec2_fft_cfg;
49#endif 49#endif
50 50
51 51static inline void codec2_fftr(codec2_fftr_cfg cfg, codec2_fft_scalar* in,
52 52 codec2_fft_cpx* out) {
53static 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
64static inline void codec2_fftri(codec2_fftr_cfg cfg, codec2_fft_cpx* in, codec2_fft_scalar* out) 61static 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
75codec2_fft_cfg codec2_fft_alloc(int nfft, int inverse_fft, void* mem, size_t* lenmem); 71codec2_fft_cfg codec2_fft_alloc(int nfft, int inverse_fft, void* mem,
76codec2_fftr_cfg codec2_fftr_alloc(int nfft, int inverse_fft, void* mem, size_t* lenmem); 72 size_t* lenmem);
73codec2_fftr_cfg codec2_fftr_alloc(int nfft, int inverse_fft, void* mem,
74 size_t* lenmem);
77void codec2_fft_free(codec2_fft_cfg cfg); 75void codec2_fft_free(codec2_fft_cfg cfg);
78void codec2_fftr_free(codec2_fftr_cfg cfg); 76void codec2_fftr_free(codec2_fftr_cfg cfg);
79 77
80 78static inline void codec2_fft(codec2_fft_cfg cfg, codec2_fft_cpx* in,
81static 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
101void codec2_fft_inplace(codec2_fft_cfg cfg, codec2_fft_cpx* inout); 97void codec2_fft_inplace(codec2_fft_cfg cfg, codec2_fft_cpx* inout);
102 98
103
104#endif 99#endif