Update kissfft to v131.1

This commit is contained in:
Paul Fd 2021-11-10 08:55:44 +01:00
parent 672cede46f
commit f72500dd09
9 changed files with 256 additions and 168 deletions

View file

@ -203,10 +203,8 @@ if (SFIZZ_USE_SYSTEM_KISS_FFT)
else() else()
add_library(sfizz_kissfft STATIC add_library(sfizz_kissfft STATIC
"src/external/kiss_fft/kiss_fft.c" "src/external/kiss_fft/kiss_fft.c"
"src/external/kiss_fft/tools/kiss_fftr.c") "src/external/kiss_fft/kiss_fftr.c")
target_include_directories(sfizz_kissfft target_include_directories(sfizz_kissfft PUBLIC "src/external/kiss_fft")
PUBLIC "src/external/kiss_fft"
PUBLIC "src/external/kiss_fft/tools")
endif() endif()
add_library(sfizz::kissfft ALIAS sfizz_kissfft) add_library(sfizz::kissfft ALIAS sfizz_kissfft)

View file

@ -339,11 +339,10 @@ SFIZZ_SOURCES += src/external/pugixml/src/pugixml.cpp
### Kissfft dependency ### Kissfft dependency
SFIZZ_C_FLAGS += \ SFIZZ_C_FLAGS += \
-I$(SFIZZ_DIR)/src/external/kiss_fft \ -I$(SFIZZ_DIR)/src/external/kiss_fft
-I$(SFIZZ_DIR)/src/external/kiss_fft/tools
SFIZZ_SOURCES += \ SFIZZ_SOURCES += \
src/external/kiss_fft/kiss_fft.c \ src/external/kiss_fft/kiss_fft.c \
src/external/kiss_fft/tools/kiss_fftr.c src/external/kiss_fft/kiss_fftr.c
### Surge tuning library dependency ### Surge tuning library dependency

View file

@ -1,26 +1,25 @@
/* /*
Copyright (c) 2003-2010, Mark Borgerding * Copyright (c) 2003-2010, Mark Borgerding. All rights reserved.
* This file is part of KISS FFT - https://github.com/mborgerding/kissfft
All rights reserved. *
* SPDX-License-Identifier: BSD-3-Clause
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * See COPYING file for more information.
*/
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* kiss_fft.h /* kiss_fft.h
defines kiss_fft_scalar as either short or a float type defines kiss_fft_scalar as either short or a float type
and defines and defines
typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */ typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */
#ifndef _kiss_fft_guts_h
#define _kiss_fft_guts_h
#include "kiss_fft.h" #include "kiss_fft.h"
#include "kiss_fft_log.h"
#include <limits.h> #include <limits.h>
#define MAXFACTORS 32 #define MAXFACTORS 32
/* e.g. an fft of length 128 has 4 factors /* e.g. an fft of length 128 has 4 factors
as far as kissfft is concerned as far as kissfft is concerned
4*4*4*2 4*4*4*2
*/ */
@ -42,22 +41,23 @@ struct kiss_fft_state{
C_ADDTO( res , a) : res += a C_ADDTO( res , a) : res += a
* */ * */
#ifdef FIXED_POINT #ifdef FIXED_POINT
#include <stdint.h>
#if (FIXED_POINT==32) #if (FIXED_POINT==32)
# define FRACBITS 31 # define FRACBITS 31
# define SAMPPROD int64_t # define SAMPPROD int64_t
#define SAMP_MAX 2147483647 #define SAMP_MAX INT32_MAX
#define SAMP_MIN INT32_MIN
#else #else
# define FRACBITS 15 # define FRACBITS 15
# define SAMPPROD int32_t # define SAMPPROD int32_t
#define SAMP_MAX 32767 #define SAMP_MAX INT16_MAX
#define SAMP_MIN INT16_MIN
#endif #endif
#define SAMP_MIN -SAMP_MAX
#if defined(CHECK_OVERFLOW) #if defined(CHECK_OVERFLOW)
# define CHECK_OVERFLOW_OP(a,op,b) \ # define CHECK_OVERFLOW_OP(a,op,b) \
if ( (SAMPPROD)(a) op (SAMPPROD)(b) > SAMP_MAX || (SAMPPROD)(a) op (SAMPPROD)(b) < SAMP_MIN ) { \ if ( (SAMPPROD)(a) op (SAMPPROD)(b) > SAMP_MAX || (SAMPPROD)(a) op (SAMPPROD)(b) < SAMP_MIN ) { \
fprintf(stderr,"WARNING:overflow @ " __FILE__ "(%d): (%d " #op" %d) = %ld\n",__LINE__,(a),(b),(SAMPPROD)(a) op (SAMPPROD)(b) ); } KISS_FFT_WARNING("overflow (%d " #op" %d) = %ld", (a),(b),(SAMPPROD)(a) op (SAMPPROD)(b)); }
#endif #endif
@ -71,11 +71,11 @@ struct kiss_fft_state{
(m).i = sround( smul((a).r,(b).i) + smul((a).i,(b).r) ); }while(0) (m).i = sround( smul((a).r,(b).i) + smul((a).i,(b).r) ); }while(0)
# define DIVSCALAR(x,k) \ # define DIVSCALAR(x,k) \
(x) = sround( smul( x, SAMP_MAX/k ) ) (x) = sround( smul( x, SAMP_MAX/k ) )
# define C_FIXDIV(c,div) \ # define C_FIXDIV(c,div) \
do { DIVSCALAR( (c).r , div); \ do { DIVSCALAR( (c).r , div); \
DIVSCALAR( (c).i , div); }while (0) DIVSCALAR( (c).i , div); }while (0)
# define C_MULBYSCALAR( c, s ) \ # define C_MULBYSCALAR( c, s ) \
do{ (c).r = sround( smul( (c).r , s ) ) ;\ do{ (c).r = sround( smul( (c).r , s ) ) ;\
@ -99,28 +99,28 @@ struct kiss_fft_state{
#define C_ADD( res, a,b)\ #define C_ADD( res, a,b)\
do { \ do { \
CHECK_OVERFLOW_OP((a).r,+,(b).r)\ CHECK_OVERFLOW_OP((a).r,+,(b).r)\
CHECK_OVERFLOW_OP((a).i,+,(b).i)\ CHECK_OVERFLOW_OP((a).i,+,(b).i)\
(res).r=(a).r+(b).r; (res).i=(a).i+(b).i; \ (res).r=(a).r+(b).r; (res).i=(a).i+(b).i; \
}while(0) }while(0)
#define C_SUB( res, a,b)\ #define C_SUB( res, a,b)\
do { \ do { \
CHECK_OVERFLOW_OP((a).r,-,(b).r)\ CHECK_OVERFLOW_OP((a).r,-,(b).r)\
CHECK_OVERFLOW_OP((a).i,-,(b).i)\ CHECK_OVERFLOW_OP((a).i,-,(b).i)\
(res).r=(a).r-(b).r; (res).i=(a).i-(b).i; \ (res).r=(a).r-(b).r; (res).i=(a).i-(b).i; \
}while(0) }while(0)
#define C_ADDTO( res , a)\ #define C_ADDTO( res , a)\
do { \ do { \
CHECK_OVERFLOW_OP((res).r,+,(a).r)\ CHECK_OVERFLOW_OP((res).r,+,(a).r)\
CHECK_OVERFLOW_OP((res).i,+,(a).i)\ CHECK_OVERFLOW_OP((res).i,+,(a).i)\
(res).r += (a).r; (res).i += (a).i;\ (res).r += (a).r; (res).i += (a).i;\
}while(0) }while(0)
#define C_SUBFROM( res , a)\ #define C_SUBFROM( res , a)\
do {\ do {\
CHECK_OVERFLOW_OP((res).r,-,(a).r)\ CHECK_OVERFLOW_OP((res).r,-,(a).r)\
CHECK_OVERFLOW_OP((res).i,-,(a).i)\ CHECK_OVERFLOW_OP((res).i,-,(a).i)\
(res).r -= (a).r; (res).i -= (a).i; \ (res).r -= (a).r; (res).i -= (a).i; \
}while(0) }while(0)
@ -135,30 +135,33 @@ struct kiss_fft_state{
#else #else
# define KISS_FFT_COS(phase) (kiss_fft_scalar) cos(phase) # define KISS_FFT_COS(phase) (kiss_fft_scalar) cos(phase)
# define KISS_FFT_SIN(phase) (kiss_fft_scalar) sin(phase) # define KISS_FFT_SIN(phase) (kiss_fft_scalar) sin(phase)
# define HALF_OF(x) ((x)*.5) # define HALF_OF(x) ((x)*((kiss_fft_scalar).5))
#endif #endif
#define kf_cexp(x,phase) \ #define kf_cexp(x,phase) \
do{ \ do{ \
(x)->r = KISS_FFT_COS(phase);\ (x)->r = KISS_FFT_COS(phase);\
(x)->i = KISS_FFT_SIN(phase);\ (x)->i = KISS_FFT_SIN(phase);\
}while(0) }while(0)
/* a debugging function */ /* a debugging function */
#define pcpx(c)\ #define pcpx(c)\
fprintf(stderr,"%g + %gi\n",(double)((c)->r),(double)((c)->i) ) KISS_FFT_DEBUG("%g + %gi\n",(double)((c)->r),(double)((c)->i))
#ifdef KISS_FFT_USE_ALLOCA #ifdef KISS_FFT_USE_ALLOCA
// define this to allow use of alloca instead of malloc for temporary buffers // define this to allow use of alloca instead of malloc for temporary buffers
// Temporary buffers are used in two case: // Temporary buffers are used in two case:
// 1. FFT sizes that have "bad" factors. i.e. not 2,3 and 5 // 1. FFT sizes that have "bad" factors. i.e. not 2,3 and 5
// 2. "in-place" FFTs. Notice the quotes, since kissfft does not really do an in-place transform. // 2. "in-place" FFTs. Notice the quotes, since kissfft does not really do an in-place transform.
#include <alloca.h> #include <alloca.h>
#define KISS_FFT_TMP_ALLOC(nbytes) alloca(nbytes) #define KISS_FFT_TMP_ALLOC(nbytes) alloca(nbytes)
#define KISS_FFT_TMP_FREE(ptr) #define KISS_FFT_TMP_FREE(ptr)
#else #else
#define KISS_FFT_TMP_ALLOC(nbytes) KISS_FFT_MALLOC(nbytes) #define KISS_FFT_TMP_ALLOC(nbytes) KISS_FFT_MALLOC(nbytes)
#define KISS_FFT_TMP_FREE(ptr) KISS_FFT_FREE(ptr) #define KISS_FFT_TMP_FREE(ptr) KISS_FFT_FREE(ptr)
#endif #endif
#endif /* _kiss_fft_guts_h */

View file

@ -1,16 +1,10 @@
/* /*
Copyright (c) 2003-2010, Mark Borgerding * Copyright (c) 2003-2010, Mark Borgerding. All rights reserved.
* This file is part of KISS FFT - https://github.com/mborgerding/kissfft
All rights reserved. *
* SPDX-License-Identifier: BSD-3-Clause
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * See COPYING file for more information.
*/
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "_kiss_fft_guts.h" #include "_kiss_fft_guts.h"
@ -209,6 +203,10 @@ static void kf_bfly_generic(
int Norig = st->nfft; int Norig = st->nfft;
kiss_fft_cpx * scratch = (kiss_fft_cpx*)KISS_FFT_TMP_ALLOC(sizeof(kiss_fft_cpx)*p); kiss_fft_cpx * scratch = (kiss_fft_cpx*)KISS_FFT_TMP_ALLOC(sizeof(kiss_fft_cpx)*p);
if (scratch == NULL){
KISS_FFT_ERROR("Memory allocation failed.");
return;
}
for ( u=0; u<m; ++u ) { for ( u=0; u<m; ++u ) {
k=u; k=u;
@ -250,23 +248,23 @@ void kf_work(
const kiss_fft_cpx * Fout_end = Fout + p*m; const kiss_fft_cpx * Fout_end = Fout + p*m;
#ifdef _OPENMP #ifdef _OPENMP
// use openmp extensions at the // use openmp extensions at the
// top-level (not recursive) // top-level (not recursive)
if (fstride==1 && p<=5) if (fstride==1 && p<=5 && m!=1)
{ {
int k; int k;
// execute the p different work units in different threads // execute the p different work units in different threads
# pragma omp parallel for # pragma omp parallel for
for (k=0;k<p;++k) for (k=0;k<p;++k)
kf_work( Fout +k*m, f+ fstride*in_stride*k,fstride*p,in_stride,factors,st); kf_work( Fout +k*m, f+ fstride*in_stride*k,fstride*p,in_stride,factors,st);
// all threads have joined by this point // all threads have joined by this point
switch (p) { switch (p) {
case 2: kf_bfly2(Fout,fstride,st,m); break; case 2: kf_bfly2(Fout,fstride,st,m); break;
case 3: kf_bfly3(Fout,fstride,st,m); break; case 3: kf_bfly3(Fout,fstride,st,m); break;
case 4: kf_bfly4(Fout,fstride,st,m); break; case 4: kf_bfly4(Fout,fstride,st,m); break;
case 5: kf_bfly5(Fout,fstride,st,m); break; case 5: kf_bfly5(Fout,fstride,st,m); break;
default: kf_bfly_generic(Fout,fstride,st,m,p); break; default: kf_bfly_generic(Fout,fstride,st,m,p); break;
} }
return; return;
@ -282,7 +280,7 @@ void kf_work(
do{ do{
// recursive call: // recursive call:
// DFT of size m*p performed by doing // DFT of size m*p performed by doing
// p instances of smaller DFTs of size m, // p instances of smaller DFTs of size m,
// each one takes a decimated version of the input // each one takes a decimated version of the input
kf_work( Fout , f, fstride*p, in_stride, factors,st); kf_work( Fout , f, fstride*p, in_stride, factors,st);
f += fstride*in_stride; f += fstride*in_stride;
@ -291,21 +289,21 @@ void kf_work(
Fout=Fout_beg; Fout=Fout_beg;
// recombine the p smaller DFTs // recombine the p smaller DFTs
switch (p) { switch (p) {
case 2: kf_bfly2(Fout,fstride,st,m); break; case 2: kf_bfly2(Fout,fstride,st,m); break;
case 3: kf_bfly3(Fout,fstride,st,m); break; case 3: kf_bfly3(Fout,fstride,st,m); break;
case 4: kf_bfly4(Fout,fstride,st,m); break; case 4: kf_bfly4(Fout,fstride,st,m); break;
case 5: kf_bfly5(Fout,fstride,st,m); break; case 5: kf_bfly5(Fout,fstride,st,m); break;
default: kf_bfly_generic(Fout,fstride,st,m,p); break; default: kf_bfly_generic(Fout,fstride,st,m,p); break;
} }
} }
/* facbuf is populated by p1,m1,p2,m2, ... /* facbuf is populated by p1,m1,p2,m2, ...
where where
p[i] * m[i] = m[i-1] p[i] * m[i] = m[i-1]
m0 = n */ m0 = n */
static static
void kf_factor(int n,int * facbuf) void kf_factor(int n,int * facbuf)
{ {
int p=4; int p=4;
@ -338,9 +336,11 @@ void kf_factor(int n,int * facbuf)
* */ * */
kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem ) kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem )
{ {
KISS_FFT_ALIGN_CHECK(mem)
kiss_fft_cfg st=NULL; kiss_fft_cfg st=NULL;
size_t memneeded = sizeof(struct kiss_fft_state) size_t memneeded = KISS_FFT_ALIGN_SIZE_UP(sizeof(struct kiss_fft_state)
+ sizeof(kiss_fft_cpx)*(nfft-1); /* twiddle factors*/ + sizeof(kiss_fft_cpx)*(nfft-1)); /* twiddle factors*/
if ( lenmem==NULL ) { if ( lenmem==NULL ) {
st = ( kiss_fft_cfg)KISS_FFT_MALLOC( memneeded ); st = ( kiss_fft_cfg)KISS_FFT_MALLOC( memneeded );
@ -373,7 +373,19 @@ void kiss_fft_stride(kiss_fft_cfg st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,
if (fin == fout) { if (fin == fout) {
//NOTE: this is not really an in-place FFT algorithm. //NOTE: this is not really an in-place FFT algorithm.
//It just performs an out-of-place FFT into a temp buffer //It just performs an out-of-place FFT into a temp buffer
if (fout == NULL){
KISS_FFT_ERROR("fout buffer NULL.");
return;
}
kiss_fft_cpx * tmpbuf = (kiss_fft_cpx*)KISS_FFT_TMP_ALLOC( sizeof(kiss_fft_cpx)*st->nfft); kiss_fft_cpx * tmpbuf = (kiss_fft_cpx*)KISS_FFT_TMP_ALLOC( sizeof(kiss_fft_cpx)*st->nfft);
if (tmpbuf == NULL){
KISS_FFT_ERROR("Memory allocation error.");
return;
}
kf_work(tmpbuf,fin,1,in_stride, st->factors,st); kf_work(tmpbuf,fin,1,in_stride, st->factors,st);
memcpy(fout,tmpbuf,sizeof(kiss_fft_cpx)*st->nfft); memcpy(fout,tmpbuf,sizeof(kiss_fft_cpx)*st->nfft);
KISS_FFT_TMP_FREE(tmpbuf); KISS_FFT_TMP_FREE(tmpbuf);

View file

@ -1,3 +1,11 @@
/*
* Copyright (c) 2003-2010, Mark Borgerding. All rights reserved.
* This file is part of KISS FFT - https://github.com/mborgerding/kissfft
*
* SPDX-License-Identifier: BSD-3-Clause
* See COPYING file for more information.
*/
#ifndef KISS_FFT_H #ifndef KISS_FFT_H
#define KISS_FFT_H #define KISS_FFT_H
@ -6,6 +14,21 @@
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
// Define KISS_FFT_SHARED macro to properly export symbols
#ifdef KISS_FFT_SHARED
# ifdef _WIN32
# ifdef KISS_FFT_BUILD
# define KISS_FFT_API __declspec(dllexport)
# else
# define KISS_FFT_API __declspec(dllimport)
# endif
# else
# define KISS_FFT_API __attribute__ ((visibility ("default")))
# endif
#else
# define KISS_FFT_API
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -23,22 +46,35 @@ extern "C" {
in the tools/ directory. in the tools/ directory.
*/ */
/* User may override KISS_FFT_MALLOC and/or KISS_FFT_FREE. */
#ifdef USE_SIMD #ifdef USE_SIMD
# include <xmmintrin.h> # include <xmmintrin.h>
# define kiss_fft_scalar __m128 # define kiss_fft_scalar __m128
#define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes,16) # ifndef KISS_FFT_MALLOC
#define KISS_FFT_FREE _mm_free # define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes,16)
#else # define KISS_FFT_ALIGN_CHECK(ptr)
#define KISS_FFT_MALLOC malloc # define KISS_FFT_ALIGN_SIZE_UP(size) ((size + 15UL) & ~0xFUL)
#define KISS_FFT_FREE free # endif
#endif # ifndef KISS_FFT_FREE
# define KISS_FFT_FREE _mm_free
# endif
#else
# define KISS_FFT_ALIGN_CHECK(ptr)
# define KISS_FFT_ALIGN_SIZE_UP(size) (size)
# ifndef KISS_FFT_MALLOC
# define KISS_FFT_MALLOC malloc
# endif
# ifndef KISS_FFT_FREE
# define KISS_FFT_FREE free
# endif
#endif
#ifdef FIXED_POINT #ifdef FIXED_POINT
#include <sys/types.h> #include <stdint.h>
# if (FIXED_POINT == 32) # if (FIXED_POINT == 32)
# define kiss_fft_scalar int32_t # define kiss_fft_scalar int32_t
# else # else
# define kiss_fft_scalar int16_t # define kiss_fft_scalar int16_t
# endif # endif
#else #else
@ -55,9 +91,9 @@ typedef struct {
typedef struct kiss_fft_state* kiss_fft_cfg; typedef struct kiss_fft_state* kiss_fft_cfg;
/* /*
* kiss_fft_alloc * kiss_fft_alloc
* *
* Initialize a FFT (or IFFT) algorithm's cfg/state buffer. * Initialize a FFT (or IFFT) algorithm's cfg/state buffer.
* *
* typical usage: kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL); * typical usage: kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL);
@ -67,18 +103,18 @@ typedef struct kiss_fft_state* kiss_fft_cfg;
* *
* If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc. * If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc.
* The returned value should be free()d when done to avoid memory leaks. * The returned value should be free()d when done to avoid memory leaks.
* *
* The state can be placed in a user supplied buffer 'mem': * The state can be placed in a user supplied buffer 'mem':
* If lenmem is not NULL and mem is not NULL and *lenmem is large enough, * If lenmem is not NULL and mem is not NULL and *lenmem is large enough,
* then the function places the cfg in mem and the size used in *lenmem * then the function places the cfg in mem and the size used in *lenmem
* and returns mem. * and returns mem.
* *
* If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough), * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough),
* then the function returns NULL and places the minimum cfg * then the function returns NULL and places the minimum cfg
* buffer size in *lenmem. * buffer size in *lenmem.
* */ * */
kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem); kiss_fft_cfg KISS_FFT_API kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem);
/* /*
* kiss_fft(cfg,in_out_buf) * kiss_fft(cfg,in_out_buf)
@ -90,35 +126,35 @@ kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem)
* Note that each element is complex and can be accessed like * Note that each element is complex and can be accessed like
f[k].r and f[k].i f[k].r and f[k].i
* */ * */
void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout); void KISS_FFT_API kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
/* /*
A more generic version of the above function. It reads its input from every Nth sample. A more generic version of the above function. It reads its input from every Nth sample.
* */ * */
void kiss_fft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride); void KISS_FFT_API kiss_fft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride);
/* If kiss_fft_alloc allocated a buffer, it is one contiguous /* If kiss_fft_alloc allocated a buffer, it is one contiguous
buffer and can be simply free()d when no longer needed*/ buffer and can be simply free()d when no longer needed*/
#define kiss_fft_free free #define kiss_fft_free KISS_FFT_FREE
/* /*
Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up
your compiler output to call this before you exit. your compiler output to call this before you exit.
*/ */
void kiss_fft_cleanup(void); void KISS_FFT_API kiss_fft_cleanup(void);
/* /*
* Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5) * Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5)
*/ */
int kiss_fft_next_fast_size(int n); int KISS_FFT_API kiss_fft_next_fast_size(int n);
/* for real ffts, we need an even size */ /* for real ffts, we need an even size */
#define kiss_fftr_next_fast_size_real(n) \ #define kiss_fftr_next_fast_size_real(n) \
(kiss_fft_next_fast_size( ((n)+1)>>1)<<1) (kiss_fft_next_fast_size( ((n)+1)>>1)<<1)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif

36
src/external/kiss_fft/kiss_fft_log.h vendored Normal file
View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2003-2010, Mark Borgerding. All rights reserved.
* This file is part of KISS FFT - https://github.com/mborgerding/kissfft
*
* SPDX-License-Identifier: BSD-3-Clause
* See COPYING file for more information.
*/
#ifndef kiss_fft_log_h
#define kiss_fft_log_h
#define ERROR 1
#define WARNING 2
#define INFO 3
#define DEBUG 4
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#if defined(NDEBUG)
# define KISS_FFT_LOG_MSG(severity, ...) ((void)0)
#else
# define KISS_FFT_LOG_MSG(severity, ...) \
fprintf(stderr, "[" #severity "] " __FILE__ ":" TOSTRING(__LINE__) " "); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n")
#endif
#define KISS_FFT_ERROR(...) KISS_FFT_LOG_MSG(ERROR, __VA_ARGS__)
#define KISS_FFT_WARNING(...) KISS_FFT_LOG_MSG(WARNING, __VA_ARGS__)
#define KISS_FFT_INFO(...) KISS_FFT_LOG_MSG(INFO, __VA_ARGS__)
#define KISS_FFT_DEBUG(...) KISS_FFT_LOG_MSG(DEBUG, __VA_ARGS__)
#endif /* kiss_fft_log_h */

View file

@ -1,16 +1,10 @@
/* /*
Copyright (c) 2003-2004, Mark Borgerding * Copyright (c) 2003-2004, Mark Borgerding. All rights reserved.
* This file is part of KISS FFT - https://github.com/mborgerding/kissfft
All rights reserved. *
* SPDX-License-Identifier: BSD-3-Clause
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * See COPYING file for more information.
*/
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "kiss_fftr.h" #include "kiss_fftr.h"
#include "_kiss_fft_guts.h" #include "_kiss_fft_guts.h"
@ -26,12 +20,14 @@ struct kiss_fftr_state{
kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem) kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem)
{ {
KISS_FFT_ALIGN_CHECK(mem)
int i; int i;
kiss_fftr_cfg st = NULL; kiss_fftr_cfg st = NULL;
size_t subsize, memneeded; size_t subsize = 0, memneeded;
if (nfft & 1) { if (nfft & 1) {
fprintf(stderr,"Real FFT optimization must be even.\n"); KISS_FFT_ERROR("Real FFT optimization must be even.");
return NULL; return NULL;
} }
nfft >>= 1; nfft >>= 1;
@ -71,8 +67,8 @@ void kiss_fftr(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_cpx *fr
kiss_fft_cpx fpnk,fpk,f1k,f2k,tw,tdc; kiss_fft_cpx fpnk,fpk,f1k,f2k,tw,tdc;
if ( st->substate->inverse) { if ( st->substate->inverse) {
fprintf(stderr,"kiss fft usage error: improper alloc\n"); KISS_FFT_ERROR("kiss fft usage error: improper alloc");
exit(1); return;/* The caller did not call the correct function */
} }
ncfft = st->substate->nfft; ncfft = st->substate->nfft;
@ -83,12 +79,12 @@ void kiss_fftr(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_cpx *fr
* contains the sum of the even-numbered elements of the input time sequence * contains the sum of the even-numbered elements of the input time sequence
* The imag part is the sum of the odd-numbered elements * The imag part is the sum of the odd-numbered elements
* *
* The sum of tdc.r and tdc.i is the sum of the input time sequence. * The sum of tdc.r and tdc.i is the sum of the input time sequence.
* yielding DC of input time sequence * yielding DC of input time sequence
* The difference of tdc.r - tdc.i is the sum of the input (dot product) [1,-1,1,-1... * The difference of tdc.r - tdc.i is the sum of the input (dot product) [1,-1,1,-1...
* yielding Nyquist bin of input time sequence * yielding Nyquist bin of input time sequence
*/ */
tdc.r = st->tmpbuf[0].r; tdc.r = st->tmpbuf[0].r;
tdc.i = st->tmpbuf[0].i; tdc.i = st->tmpbuf[0].i;
C_FIXDIV(tdc,2); C_FIXDIV(tdc,2);
@ -96,14 +92,14 @@ void kiss_fftr(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_cpx *fr
CHECK_OVERFLOW_OP(tdc.r ,-, tdc.i); CHECK_OVERFLOW_OP(tdc.r ,-, tdc.i);
freqdata[0].r = tdc.r + tdc.i; freqdata[0].r = tdc.r + tdc.i;
freqdata[ncfft].r = tdc.r - tdc.i; freqdata[ncfft].r = tdc.r - tdc.i;
#ifdef USE_SIMD #ifdef USE_SIMD
freqdata[ncfft].i = freqdata[0].i = _mm_set1_ps(0); freqdata[ncfft].i = freqdata[0].i = _mm_set1_ps(0);
#else #else
freqdata[ncfft].i = freqdata[0].i = 0; freqdata[ncfft].i = freqdata[0].i = 0;
#endif #endif
for ( k=1;k <= ncfft/2 ; ++k ) { for ( k=1;k <= ncfft/2 ; ++k ) {
fpk = st->tmpbuf[k]; fpk = st->tmpbuf[k];
fpnk.r = st->tmpbuf[ncfft-k].r; fpnk.r = st->tmpbuf[ncfft-k].r;
fpnk.i = - st->tmpbuf[ncfft-k].i; fpnk.i = - st->tmpbuf[ncfft-k].i;
C_FIXDIV(fpk,2); C_FIXDIV(fpk,2);
@ -126,8 +122,8 @@ void kiss_fftri(kiss_fftr_cfg st,const kiss_fft_cpx *freqdata,kiss_fft_scalar *t
int k, ncfft; int k, ncfft;
if (st->substate->inverse == 0) { if (st->substate->inverse == 0) {
fprintf (stderr, "kiss fft usage error: improper alloc\n"); KISS_FFT_ERROR("kiss fft usage error: improper alloc");
exit (1); return;/* The caller did not call the correct function */
} }
ncfft = st->substate->nfft; ncfft = st->substate->nfft;
@ -149,7 +145,7 @@ void kiss_fftri(kiss_fftr_cfg st,const kiss_fft_cpx *freqdata,kiss_fft_scalar *t
C_MUL (fok, tmp, st->super_twiddles[k-1]); C_MUL (fok, tmp, st->super_twiddles[k-1]);
C_ADD (st->tmpbuf[k], fek, fok); C_ADD (st->tmpbuf[k], fek, fok);
C_SUB (st->tmpbuf[ncfft - k], fek, fok); C_SUB (st->tmpbuf[ncfft - k], fek, fok);
#ifdef USE_SIMD #ifdef USE_SIMD
st->tmpbuf[ncfft - k].i *= _mm_set1_ps(-1.0); st->tmpbuf[ncfft - k].i *= _mm_set1_ps(-1.0);
#else #else
st->tmpbuf[ncfft - k].i *= -1; st->tmpbuf[ncfft - k].i *= -1;

54
src/external/kiss_fft/kiss_fftr.h vendored Normal file
View file

@ -0,0 +1,54 @@
/*
* Copyright (c) 2003-2004, Mark Borgerding. All rights reserved.
* This file is part of KISS FFT - https://github.com/mborgerding/kissfft
*
* SPDX-License-Identifier: BSD-3-Clause
* See COPYING file for more information.
*/
#ifndef KISS_FTR_H
#define KISS_FTR_H
#include "kiss_fft.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
Real optimized version can save about 45% cpu time vs. complex fft of a real seq.
*/
typedef struct kiss_fftr_state *kiss_fftr_cfg;
kiss_fftr_cfg KISS_FFT_API kiss_fftr_alloc(int nfft,int inverse_fft,void * mem, size_t * lenmem);
/*
nfft must be even
If you don't care to allocate space, use mem = lenmem = NULL
*/
void KISS_FFT_API kiss_fftr(kiss_fftr_cfg cfg,const kiss_fft_scalar *timedata,kiss_fft_cpx *freqdata);
/*
input timedata has nfft scalar points
output freqdata has nfft/2+1 complex points
*/
void KISS_FFT_API kiss_fftri(kiss_fftr_cfg cfg,const kiss_fft_cpx *freqdata,kiss_fft_scalar *timedata);
/*
input freqdata has nfft/2+1 complex points
output timedata has nfft scalar points
*/
#define kiss_fftr_free KISS_FFT_FREE
#ifdef __cplusplus
}
#endif
#endif

View file

@ -1,46 +0,0 @@
#ifndef KISS_FTR_H
#define KISS_FTR_H
#include "kiss_fft.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
Real optimized version can save about 45% cpu time vs. complex fft of a real seq.
*/
typedef struct kiss_fftr_state *kiss_fftr_cfg;
kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem, size_t * lenmem);
/*
nfft must be even
If you don't care to allocate space, use mem = lenmem = NULL
*/
void kiss_fftr(kiss_fftr_cfg cfg,const kiss_fft_scalar *timedata,kiss_fft_cpx *freqdata);
/*
input timedata has nfft scalar points
output freqdata has nfft/2+1 complex points
*/
void kiss_fftri(kiss_fftr_cfg cfg,const kiss_fft_cpx *freqdata,kiss_fft_scalar *timedata);
/*
input freqdata has nfft/2+1 complex points
output timedata has nfft scalar points
*/
#define kiss_fftr_free free
#ifdef __cplusplus
}
#endif
#endif