From 30325d24d107dbf133da39f7c96d1510fd1c9449 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Fri, 15 Aug 2025 12:42:40 +0200 Subject: Bump to codec2 version 1.2.0 --- codec2_fft.h | 111 ++++++++++++++++++++++++++++------------------------------- 1 file changed, 53 insertions(+), 58 deletions(-) (limited to 'codec2_fft.h') 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 @@ #define DRIVERS_FREEDV_CODEC2_FFT_H_ #include -#include +#include #include +#include #include -#include -#ifdef FDV_ARM_MATH - #include "fdv_arm_math.h" +#ifndef FDV_ARM_MATH +#define USE_KISS_FFT #else - #define USE_KISS_FFT +#include "arm_const_structs.h" +#include "arm_math.h" #endif -#include "defines.h" #include "comp.h" +#include "defines.h" - -typedef COMP codec2_fft_cpx; +typedef COMP codec2_fft_cpx; #include "kiss_fftr.h" #ifdef USE_KISS_FFT - #include "kiss_fft.h" - typedef kiss_fftr_cfg codec2_fftr_cfg; - typedef kiss_fft_cfg codec2_fft_cfg; - typedef kiss_fft_scalar codec2_fft_scalar; +#include "kiss_fft.h" +typedef kiss_fftr_cfg codec2_fftr_cfg; +typedef kiss_fft_cfg codec2_fft_cfg; +typedef kiss_fft_scalar codec2_fft_scalar; #else - typedef float32_t codec2_fft_scalar; - typedef struct { - arm_rfft_fast_instance_f32* instance; - int inverse; - } codec2_fftr_struct; - - typedef codec2_fftr_struct* codec2_fftr_cfg; - - typedef struct { - const arm_cfft_instance_f32* instance; - int inverse; - } codec2_fft_struct; - typedef codec2_fft_struct* codec2_fft_cfg; +typedef float32_t codec2_fft_scalar; +typedef struct { + arm_rfft_fast_instance_f32* instance; + int inverse; +} codec2_fftr_struct; + +typedef codec2_fftr_struct* codec2_fftr_cfg; + +typedef struct { + const arm_cfft_instance_f32* instance; + int inverse; +} codec2_fft_struct; +typedef codec2_fft_struct* codec2_fft_cfg; #endif - - -static inline void codec2_fftr(codec2_fftr_cfg cfg, codec2_fft_scalar* in, codec2_fft_cpx* out) -{ - +static inline void codec2_fftr(codec2_fftr_cfg cfg, codec2_fft_scalar* in, + codec2_fft_cpx* out) { #ifdef USE_KISS_FFT - kiss_fftr(cfg, in, (kiss_fft_cpx*)out); + kiss_fftr(cfg, in, (kiss_fft_cpx*)out); #else - arm_rfft_fast_f32(cfg->instance,in,(float*)out,cfg->inverse); - out->imag = 0; // remove out[FFT_ENC/2]->real stored in out[0].imag + arm_rfft_fast_f32(cfg->instance, in, (float*)out, cfg->inverse); + out->imag = 0; // remove out[FFT_ENC/2]->real stored in out[0].imag #endif } -static inline void codec2_fftri(codec2_fftr_cfg cfg, codec2_fft_cpx* in, codec2_fft_scalar* out) -{ +static inline void codec2_fftri(codec2_fftr_cfg cfg, codec2_fft_cpx* in, + codec2_fft_scalar* out) { #ifdef USE_KISS_FFT - kiss_fftri(cfg, (kiss_fft_cpx*)in, out); + kiss_fftri(cfg, (kiss_fft_cpx*)in, out); #else - arm_rfft_fast_f32(cfg->instance,(float*)in,out,cfg->inverse); - // arm_scale_f32(out,cfg->instance->fftLenRFFT,out,cfg->instance->fftLenRFFT); + arm_rfft_fast_f32(cfg->instance, (float*)in, out, cfg->inverse); + // arm_scale_f32(out,cfg->instance->fftLenRFFT,out,cfg->instance->fftLenRFFT); #endif - } -codec2_fft_cfg codec2_fft_alloc(int nfft, int inverse_fft, void* mem, size_t* lenmem); -codec2_fftr_cfg codec2_fftr_alloc(int nfft, int inverse_fft, void* mem, size_t* lenmem); +codec2_fft_cfg codec2_fft_alloc(int nfft, int inverse_fft, void* mem, + size_t* lenmem); +codec2_fftr_cfg codec2_fftr_alloc(int nfft, int inverse_fft, void* mem, + size_t* lenmem); void codec2_fft_free(codec2_fft_cfg cfg); void codec2_fftr_free(codec2_fftr_cfg cfg); - -static inline void codec2_fft(codec2_fft_cfg cfg, codec2_fft_cpx* in, codec2_fft_cpx* out) -{ - +static inline void codec2_fft(codec2_fft_cfg cfg, codec2_fft_cpx* in, + codec2_fft_cpx* out) { #ifdef USE_KISS_FFT - kiss_fft(cfg, (kiss_fft_cpx*)in, (kiss_fft_cpx*)out); + kiss_fft(cfg, (kiss_fft_cpx*)in, (kiss_fft_cpx*)out); #else - memcpy(out,in,cfg->instance->fftLen*2*sizeof(float)); - arm_cfft_f32(cfg->instance,(float*)out,cfg->inverse, 1); - // TODO: this is not nice, but for now required to keep changes minimal - // however, since main goal is to reduce the memory usage - // we should convert to an in place interface - // on PC like platforms the overhead of using the "inplace" kiss_fft calls - // is neglectable compared to the gain in memory usage on STM32 platforms - if (cfg->inverse) - { - arm_scale_f32((float*)out,cfg->instance->fftLen,(float*)out,cfg->instance->fftLen*2); - } + memcpy(out, in, cfg->instance->fftLen * 2 * sizeof(float)); + arm_cfft_f32(cfg->instance, (float*)out, cfg->inverse, 1); + // TODO: this is not nice, but for now required to keep changes minimal + // however, since main goal is to reduce the memory usage + // we should convert to an in place interface + // on PC like platforms the overhead of using the "inplace" kiss_fft calls + // is neglectable compared to the gain in memory usage on STM32 platforms + if (cfg->inverse) { + arm_scale_f32((float*)out, cfg->instance->fftLen, (float*)out, + cfg->instance->fftLen * 2); + } #endif } void codec2_fft_inplace(codec2_fft_cfg cfg, codec2_fft_cpx* inout); - #endif -- cgit v1.2.3