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.c | 112 +++++++++++++++++++++++++++-------------------------------- 1 file changed, 52 insertions(+), 60 deletions(-) (limited to 'codec2_fft.c') diff --git a/codec2_fft.c b/codec2_fft.c index 14b8670..7a75062 100644 --- a/codec2_fft.c +++ b/codec2_fft.c @@ -61,66 +61,63 @@ static const arm_cfft_instance_f32* arm_fft_cache_get(const arm_cfft_instance_f3 #endif #endif -void codec2_fft_free(codec2_fft_cfg cfg) -{ +void codec2_fft_free(codec2_fft_cfg cfg) { #ifdef USE_KISS_FFT - KISS_FFT_FREE(cfg); + KISS_FFT_FREE(cfg); #else - FREE(cfg); + FREE(cfg); #endif } -codec2_fft_cfg codec2_fft_alloc(int nfft, int inverse_fft, void* mem, size_t* lenmem) -{ - codec2_fft_cfg retval; +codec2_fft_cfg codec2_fft_alloc(int nfft, int inverse_fft, void* mem, + size_t* lenmem) { + codec2_fft_cfg retval; #ifdef USE_KISS_FFT - retval = kiss_fft_alloc(nfft, inverse_fft, mem, lenmem); + retval = kiss_fft_alloc(nfft, inverse_fft, mem, lenmem); #else - retval = MALLOC(sizeof(codec2_fft_struct)); - retval->inverse = inverse_fft; - switch(nfft) - { + retval = MALLOC(sizeof(codec2_fft_struct)); + retval->inverse = inverse_fft; + switch (nfft) { case 128: - retval->instance = &arm_cfft_sR_f32_len128; - break; + retval->instance = &arm_cfft_sR_f32_len128; + break; case 256: - retval->instance = &arm_cfft_sR_f32_len256; - break; + retval->instance = &arm_cfft_sR_f32_len256; + break; case 512: - retval->instance = &arm_cfft_sR_f32_len512; - break; -// case 1024: -// retval->instance = &arm_cfft_sR_f32_len1024; -// break; + retval->instance = &arm_cfft_sR_f32_len512; + break; + // case 1024: + // retval->instance = &arm_cfft_sR_f32_len1024; + // break; default: - abort(); - } + abort(); + } // retval->instance = arm_fft_cache_get(retval->instance); #endif - return retval; + return retval; } -codec2_fftr_cfg codec2_fftr_alloc(int nfft, int inverse_fft, void* mem, size_t* lenmem) -{ - codec2_fftr_cfg retval; +codec2_fftr_cfg codec2_fftr_alloc(int nfft, int inverse_fft, void* mem, + size_t* lenmem) { + codec2_fftr_cfg retval; #ifdef USE_KISS_FFT - retval = kiss_fftr_alloc(nfft, inverse_fft, mem, lenmem); + retval = kiss_fftr_alloc(nfft, inverse_fft, mem, lenmem); #else - retval = MALLOC(sizeof(codec2_fftr_struct)); - retval->inverse = inverse_fft; - retval->instance = MALLOC(sizeof(arm_rfft_fast_instance_f32)); - arm_rfft_fast_init_f32(retval->instance,nfft); - // memcpy(&retval->instance->Sint,arm_fft_cache_get(&retval->instance->Sint),sizeof(arm_cfft_instance_f32)); + retval = MALLOC(sizeof(codec2_fftr_struct)); + retval->inverse = inverse_fft; + retval->instance = MALLOC(sizeof(arm_rfft_fast_instance_f32)); + arm_rfft_fast_init_f32(retval->instance, nfft); + // memcpy(&retval->instance->Sint,arm_fft_cache_get(&retval->instance->Sint),sizeof(arm_cfft_instance_f32)); #endif - return retval; + return retval; } -void codec2_fftr_free(codec2_fftr_cfg cfg) -{ +void codec2_fftr_free(codec2_fftr_cfg cfg) { #ifdef USE_KISS_FFT - KISS_FFT_FREE(cfg); + KISS_FFT_FREE(cfg); #else - FREE(cfg->instance); - FREE(cfg); + FREE(cfg->instance); + FREE(cfg); #endif } @@ -129,30 +126,25 @@ void codec2_fftr_free(codec2_fftr_cfg cfg) // not noticeable // the reduced usage of RAM and increased performance on STM32 platforms // should be worth it. -void codec2_fft_inplace(codec2_fft_cfg cfg, codec2_fft_cpx* inout) -{ - +void codec2_fft_inplace(codec2_fft_cfg cfg, codec2_fft_cpx* inout) { #ifdef USE_KISS_FFT + // decide whether to use the local stack based buffer for in + // or to allow kiss_fft to allocate RAM + // second part is just to play safe since first method + // is much faster and uses less RAM + if (cfg->nfft <= 512) { kiss_fft_cpx in[512]; - // decide whether to use the local stack based buffer for in - // or to allow kiss_fft to allocate RAM - // second part is just to play safe since first method - // is much faster and uses less RAM - if (cfg->nfft <= 512) - { - memcpy(in,inout,cfg->nfft*sizeof(kiss_fft_cpx)); - kiss_fft(cfg, in, (kiss_fft_cpx*)inout); - } - else - { - kiss_fft(cfg, (kiss_fft_cpx*)inout, (kiss_fft_cpx*)inout); - } + memcpy(in, inout, cfg->nfft * sizeof(kiss_fft_cpx)); + kiss_fft(cfg, in, (kiss_fft_cpx*)inout); + } else { + kiss_fft(cfg, (kiss_fft_cpx*)inout, (kiss_fft_cpx*)inout); + } #else - arm_cfft_f32(cfg->instance,(float*)inout,cfg->inverse,1); - if (cfg->inverse) - { - arm_scale_f32((float*)inout,cfg->instance->fftLen,(float*)inout,cfg->instance->fftLen*2); - } + arm_cfft_f32(cfg->instance, (float*)inout, cfg->inverse, 1); + if (cfg->inverse) { + arm_scale_f32((float*)inout, cfg->instance->fftLen, (float*)inout, + cfg->instance->fftLen * 2); + } #endif } -- cgit v1.2.3