From 942882a30bd69a8a1bf947f0a63faf63703174e2 Mon Sep 17 00:00:00 2001 From: Alwin Esch Date: Wed, 14 Oct 2015 21:52:24 +0200 Subject: [PATCH] Update kissfft --- CMakeLists.txt | 4 +- src/kissfft/{kiss_fft.cpp => kiss_fft.c} | 2 +- src/kissfft/kiss_fft.h | 34 ++-- src/kissfft/kiss_fftnd.c | 193 +++++++++++++++++++++ src/kissfft/kiss_fftnd.h | 18 ++ src/kissfft/kiss_fftndr.c | 118 +++++++++++++ src/kissfft/kiss_fftndr.h | 47 +++++ src/kissfft/{kiss_fftr.cpp => kiss_fftr.c} | 20 +-- src/kissfft/kiss_fftr.h | 12 +- 9 files changed, 410 insertions(+), 38 deletions(-) rename src/kissfft/{kiss_fft.cpp => kiss_fft.c} (99%) create mode 100644 src/kissfft/kiss_fftnd.c create mode 100644 src/kissfft/kiss_fftnd.h create mode 100644 src/kissfft/kiss_fftndr.c create mode 100644 src/kissfft/kiss_fftndr.h rename src/kissfft/{kiss_fftr.cpp => kiss_fftr.c} (95%) diff --git a/CMakeLists.txt b/CMakeLists.txt index fb37cde..f7e3b1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,8 +16,8 @@ include_directories(${kodiplatform_INCLUDE_DIRS} set(FREESURROUND_SOURCES src/addon.cpp src/GUIDialogFreeSurround.cpp - src/kissfft/kiss_fft.cpp - src/kissfft/kiss_fftr.cpp + src/kissfft/kiss_fft.c + src/kissfft/kiss_fftr.c src/DSPProcessFreeSurround.cpp src/FreeSurroundSettings.cpp src/ChannelMaps.cpp diff --git a/src/kissfft/kiss_fft.cpp b/src/kissfft/kiss_fft.c similarity index 99% rename from src/kissfft/kiss_fft.cpp rename to src/kissfft/kiss_fft.c index 40f8e35..465d6c9 100644 --- a/src/kissfft/kiss_fft.cpp +++ b/src/kissfft/kiss_fft.c @@ -343,7 +343,7 @@ kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem + sizeof(kiss_fft_cpx)*(nfft-1); /* twiddle factors*/ if ( lenmem==NULL ) { - st = ( kiss_fft_cfg)new char[ memneeded ]; + st = ( kiss_fft_cfg)KISS_FFT_MALLOC( memneeded ); }else{ if (mem != NULL && *lenmem >= memneeded) st = (kiss_fft_cfg)mem; diff --git a/src/kissfft/kiss_fft.h b/src/kissfft/kiss_fft.h index a590152..761090e 100644 --- a/src/kissfft/kiss_fft.h +++ b/src/kissfft/kiss_fft.h @@ -5,15 +5,11 @@ #include #include #include -#include #ifdef __cplusplus extern "C" { #endif -// we're using doubles here... -#define kiss_fft_scalar double - /* ATTENTION! If you would like a : @@ -32,23 +28,23 @@ extern "C" { # define kiss_fft_scalar __m128 #define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes,16) #define KISS_FFT_FREE _mm_free -#else +#else #define KISS_FFT_MALLOC malloc #define KISS_FFT_FREE free -#endif +#endif #ifdef FIXED_POINT -#include +#include # if (FIXED_POINT == 32) # define kiss_fft_scalar int32_t -# else +# else # define kiss_fft_scalar int16_t # endif #else # ifndef kiss_fft_scalar /* default is float */ -# define kiss_fft_scalar float +# define kiss_fft_scalar float /* for Extempore */ # endif #endif @@ -59,9 +55,9 @@ typedef struct { typedef struct kiss_fft_state* kiss_fft_cfg; -/* +/* * kiss_fft_alloc - * + * * Initialize a FFT (or IFFT) algorithm's cfg/state buffer. * * typical usage: kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL); @@ -71,18 +67,18 @@ typedef struct kiss_fft_state* kiss_fft_cfg; * * 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 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, * then the function places the cfg in mem and the size used in *lenmem * and returns mem. - * + * * 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. * */ -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(cfg,in_out_buf) @@ -101,16 +97,16 @@ void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout); * */ void 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*/ #define kiss_fft_free 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. */ void kiss_fft_cleanup(void); - + /* * Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5) @@ -122,7 +118,7 @@ int kiss_fft_next_fast_size(int n); (kiss_fft_next_fast_size( ((n)+1)>>1)<<1) #ifdef __cplusplus -} +} #endif #endif diff --git a/src/kissfft/kiss_fftnd.c b/src/kissfft/kiss_fftnd.c new file mode 100644 index 0000000..d6c9124 --- /dev/null +++ b/src/kissfft/kiss_fftnd.c @@ -0,0 +1,193 @@ + + +/* +Copyright (c) 2003-2004, Mark Borgerding + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + * 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_fftnd.h" +#include "_kiss_fft_guts.h" + +struct kiss_fftnd_state{ + int dimprod; /* dimsum would be mighty tasty right now */ + int ndims; + int *dims; + kiss_fft_cfg *states; /* cfg states for each dimension */ + kiss_fft_cpx * tmpbuf; /*buffer capable of hold the entire input */ +}; + +kiss_fftnd_cfg kiss_fftnd_alloc(const int *dims,int ndims,int inverse_fft,void*mem,size_t*lenmem) +{ + kiss_fftnd_cfg st = NULL; + int i; + int dimprod=1; + size_t memneeded = sizeof(struct kiss_fftnd_state); + char * ptr; + + for (i=0;istates[i] */ + dimprod *= dims[i]; + } + memneeded += sizeof(int) * ndims;/* st->dims */ + memneeded += sizeof(void*) * ndims;/* st->states */ + memneeded += sizeof(kiss_fft_cpx) * dimprod; /* st->tmpbuf */ + + if (lenmem == NULL) {/* allocate for the caller*/ + st = (kiss_fftnd_cfg) malloc (memneeded); + } else { /* initialize supplied buffer if big enough */ + if (*lenmem >= memneeded) + st = (kiss_fftnd_cfg) mem; + *lenmem = memneeded; /*tell caller how big struct is (or would be) */ + } + if (!st) + return NULL; /*malloc failed or buffer too small */ + + st->dimprod = dimprod; + st->ndims = ndims; + ptr=(char*)(st+1); + + st->states = (kiss_fft_cfg *)ptr; + ptr += sizeof(void*) * ndims; + + st->dims = (int*)ptr; + ptr += sizeof(int) * ndims; + + st->tmpbuf = (kiss_fft_cpx*)ptr; + ptr += sizeof(kiss_fft_cpx) * dimprod; + + for (i=0;idims[i] = dims[i]; + kiss_fft_alloc (st->dims[i], inverse_fft, NULL, &len); + st->states[i] = kiss_fft_alloc (st->dims[i], inverse_fft, ptr,&len); + ptr += len; + } + /* +Hi there! + +If you're looking at this particular code, it probably means you've got a brain-dead bounds checker +that thinks the above code overwrites the end of the array. + +It doesn't. + +-- Mark + +P.S. +The below code might give you some warm fuzzies and help convince you. + */ + if ( ptr - (char*)st != (int)memneeded ) { + fprintf(stderr, + "################################################################################\n" + "Internal error! Memory allocation miscalculation\n" + "################################################################################\n" + ); + } + return st; +} + +/* + This works by tackling one dimension at a time. + + In effect, + Each stage starts out by reshaping the matrix into a DixSi 2d matrix. + A Di-sized fft is taken of each column, transposing the matrix as it goes. + +Here's a 3-d example: +Take a 2x3x4 matrix, laid out in memory as a contiguous buffer + [ [ [ a b c d ] [ e f g h ] [ i j k l ] ] + [ [ m n o p ] [ q r s t ] [ u v w x ] ] ] + +Stage 0 ( D=2): treat the buffer as a 2x12 matrix + [ [a b ... k l] + [m n ... w x] ] + + FFT each column with size 2. + Transpose the matrix at the same time using kiss_fft_stride. + + [ [ a+m a-m ] + [ b+n b-n] + ... + [ k+w k-w ] + [ l+x l-x ] ] + + Note fft([x y]) == [x+y x-y] + +Stage 1 ( D=3) treats the buffer (the output of stage D=2) as an 3x8 matrix, + [ [ a+m a-m b+n b-n c+o c-o d+p d-p ] + [ e+q e-q f+r f-r g+s g-s h+t h-t ] + [ i+u i-u j+v j-v k+w k-w l+x l-x ] ] + + And perform FFTs (size=3) on each of the columns as above, transposing + the matrix as it goes. The output of stage 1 is + (Legend: ap = [ a+m e+q i+u ] + am = [ a-m e-q i-u ] ) + + [ [ sum(ap) fft(ap)[0] fft(ap)[1] ] + [ sum(am) fft(am)[0] fft(am)[1] ] + [ sum(bp) fft(bp)[0] fft(bp)[1] ] + [ sum(bm) fft(bm)[0] fft(bm)[1] ] + [ sum(cp) fft(cp)[0] fft(cp)[1] ] + [ sum(cm) fft(cm)[0] fft(cm)[1] ] + [ sum(dp) fft(dp)[0] fft(dp)[1] ] + [ sum(dm) fft(dm)[0] fft(dm)[1] ] ] + +Stage 2 ( D=4) treats this buffer as a 4*6 matrix, + [ [ sum(ap) fft(ap)[0] fft(ap)[1] sum(am) fft(am)[0] fft(am)[1] ] + [ sum(bp) fft(bp)[0] fft(bp)[1] sum(bm) fft(bm)[0] fft(bm)[1] ] + [ sum(cp) fft(cp)[0] fft(cp)[1] sum(cm) fft(cm)[0] fft(cm)[1] ] + [ sum(dp) fft(dp)[0] fft(dp)[1] sum(dm) fft(dm)[0] fft(dm)[1] ] ] + + Then FFTs each column, transposing as it goes. + + The resulting matrix is the 3d FFT of the 2x3x4 input matrix. + + Note as a sanity check that the first element of the final + stage's output (DC term) is + sum( [ sum(ap) sum(bp) sum(cp) sum(dp) ] ) + , i.e. the summation of all 24 input elements. + +*/ +void kiss_fftnd(kiss_fftnd_cfg st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout) +{ + int i,k; + const kiss_fft_cpx * bufin=fin; + kiss_fft_cpx * bufout; + + /*arrange it so the last bufout == fout*/ + if ( st->ndims & 1 ) { + bufout = fout; + if (fin==fout) { + memcpy( st->tmpbuf, fin, sizeof(kiss_fft_cpx) * st->dimprod ); + bufin = st->tmpbuf; + } + }else + bufout = st->tmpbuf; + + for ( k=0; k < st->ndims; ++k) { + int curdim = st->dims[k]; + int stride = st->dimprod / curdim; + + for ( i=0 ; istates[k], bufin+i , bufout+i*curdim, stride ); + + /*toggle back and forth between the two buffers*/ + if (bufout == st->tmpbuf){ + bufout = fout; + bufin = st->tmpbuf; + }else{ + bufout = st->tmpbuf; + bufin = fout; + } + } +} diff --git a/src/kissfft/kiss_fftnd.h b/src/kissfft/kiss_fftnd.h new file mode 100644 index 0000000..42e7df5 --- /dev/null +++ b/src/kissfft/kiss_fftnd.h @@ -0,0 +1,18 @@ +#ifndef KISS_FFTND_H +#define KISS_FFTND_H + +#include "kiss_fft.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct kiss_fftnd_state * kiss_fftnd_cfg; + +kiss_fftnd_cfg kiss_fftnd_alloc(const int *dims,int ndims,int inverse_fft,void*mem,size_t*lenmem); +void kiss_fftnd(kiss_fftnd_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/kissfft/kiss_fftndr.c b/src/kissfft/kiss_fftndr.c new file mode 100644 index 0000000..ba550dd --- /dev/null +++ b/src/kissfft/kiss_fftndr.c @@ -0,0 +1,118 @@ +/* +Copyright (c) 2003-2004, Mark Borgerding + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + * 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_fftndr.h" +#include "_kiss_fft_guts.h" +#define MAX(x,y) ( ( (x)<(y) )?(y):(x) ) + +struct kiss_fftndr_state +{ + int dimReal; + int dimOther; + kiss_fftr_cfg cfg_r; + kiss_fftnd_cfg cfg_nd; + void * tmpbuf; +}; + +static int prod(const int *dims, int ndims) +{ + int x=1; + while (ndims--) + x *= *dims++; + return x; +} + +kiss_fftndr_cfg kiss_fftndr_alloc(const int *dims,int ndims,int inverse_fft,void*mem,size_t*lenmem) +{ + kiss_fftndr_cfg st = NULL; + size_t nr=0 , nd=0,ntmp=0; + int dimReal = dims[ndims-1]; + int dimOther = prod(dims,ndims-1); + size_t memneeded; + + (void)kiss_fftr_alloc(dimReal,inverse_fft,NULL,&nr); + (void)kiss_fftnd_alloc(dims,ndims-1,inverse_fft,NULL,&nd); + ntmp = + MAX( 2*dimOther , dimReal+2) * sizeof(kiss_fft_scalar) // freq buffer for one pass + + dimOther*(dimReal+2) * sizeof(kiss_fft_scalar); // large enough to hold entire input in case of in-place + + memneeded = sizeof( struct kiss_fftndr_state ) + nr + nd + ntmp; + + if (lenmem==NULL) { + st = (kiss_fftndr_cfg) malloc(memneeded); + }else{ + if (*lenmem >= memneeded) + st = (kiss_fftndr_cfg)mem; + *lenmem = memneeded; + } + if (st==NULL) + return NULL; + memset( st , 0 , memneeded); + + st->dimReal = dimReal; + st->dimOther = dimOther; + st->cfg_r = kiss_fftr_alloc( dimReal,inverse_fft,st+1,&nr); + st->cfg_nd = kiss_fftnd_alloc(dims,ndims-1,inverse_fft, ((char*) st->cfg_r)+nr,&nd); + st->tmpbuf = (char*)st->cfg_nd + nd; + + return st; +} + +void kiss_fftndr(kiss_fftndr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_cpx *freqdata) +{ + int k1,k2; + int dimReal = st->dimReal; + int dimOther = st->dimOther; + int nrbins = dimReal/2+1; + + kiss_fft_cpx * tmp1 = (kiss_fft_cpx*)st->tmpbuf; + kiss_fft_cpx * tmp2 = tmp1 + MAX(nrbins,dimOther); + + // timedata is N0 x N1 x ... x Nk real + + // take a real chunk of data, fft it and place the output at correct intervals + for (k1=0;k1cfg_r, timedata + k1*dimReal , tmp1 ); // tmp1 now holds nrbins complex points + for (k2=0;k2cfg_nd, tmp2+k2*dimOther, tmp1); // tmp1 now holds dimOther complex points + for (k1=0;k1dimReal; + int dimOther = st->dimOther; + int nrbins = dimReal/2+1; + kiss_fft_cpx * tmp1 = (kiss_fft_cpx*)st->tmpbuf; + kiss_fft_cpx * tmp2 = tmp1 + MAX(nrbins,dimOther); + + for (k2=0;k2cfg_nd, tmp1, tmp2+k2*dimOther); + } + + for (k1=0;k1cfg_r,tmp1,timedata + k1*dimReal); + } +} diff --git a/src/kissfft/kiss_fftndr.h b/src/kissfft/kiss_fftndr.h new file mode 100644 index 0000000..38ec3ab --- /dev/null +++ b/src/kissfft/kiss_fftndr.h @@ -0,0 +1,47 @@ +#ifndef KISS_NDR_H +#define KISS_NDR_H + +#include "kiss_fft.h" +#include "kiss_fftr.h" +#include "kiss_fftnd.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct kiss_fftndr_state *kiss_fftndr_cfg; + + +kiss_fftndr_cfg kiss_fftndr_alloc(const int *dims,int ndims,int inverse_fft,void*mem,size_t*lenmem); +/* + dims[0] must be even + + If you don't care to allocate space, use mem = lenmem = NULL +*/ + + +void kiss_fftndr( + kiss_fftndr_cfg cfg, + const kiss_fft_scalar *timedata, + kiss_fft_cpx *freqdata); +/* + input timedata has dims[0] X dims[1] X ... X dims[ndims-1] scalar points + output freqdata has dims[0] X dims[1] X ... X dims[ndims-1]/2+1 complex points +*/ + +void kiss_fftndri( + kiss_fftndr_cfg cfg, + const kiss_fft_cpx *freqdata, + kiss_fft_scalar *timedata); +/* + input and output dimensions are the exact opposite of kiss_fftndr +*/ + + +#define kiss_fftr_free free + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/kissfft/kiss_fftr.cpp b/src/kissfft/kiss_fftr.c similarity index 95% rename from src/kissfft/kiss_fftr.cpp rename to src/kissfft/kiss_fftr.c index 20add00..302f1cd 100644 --- a/src/kissfft/kiss_fftr.cpp +++ b/src/kissfft/kiss_fftr.c @@ -19,16 +19,16 @@ struct kiss_fftr_state{ kiss_fft_cfg substate; kiss_fft_cpx * tmpbuf; kiss_fft_cpx * super_twiddles; -#ifdef USE_SIMD +#ifdef USE_SIMD void * pad; -#endif +#endif }; kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem) { int i; kiss_fftr_cfg st = NULL; - size_t subsize = 65536*4, memneeded = 0; + size_t subsize, memneeded; if (nfft & 1) { fprintf(stderr,"Real FFT optimization must be even.\n"); @@ -40,7 +40,7 @@ kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem,size_t * lenme memneeded = sizeof(struct kiss_fftr_state) + subsize + sizeof(kiss_fft_cpx) * ( nfft * 3 / 2); if (lenmem == NULL) { - st = (kiss_fftr_cfg) new char[memneeded]; + st = (kiss_fftr_cfg) KISS_FFT_MALLOC (memneeded); } else { if (*lenmem >= memneeded) st = (kiss_fftr_cfg) mem; @@ -83,12 +83,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 * 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 - * 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 */ - + tdc.r = st->tmpbuf[0].r; tdc.i = st->tmpbuf[0].i; C_FIXDIV(tdc,2); @@ -96,14 +96,14 @@ void kiss_fftr(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_cpx *fr CHECK_OVERFLOW_OP(tdc.r ,-, tdc.i); freqdata[0].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); #else freqdata[ncfft].i = freqdata[0].i = 0; #endif for ( k=1;k <= ncfft/2 ; ++k ) { - fpk = st->tmpbuf[k]; + fpk = st->tmpbuf[k]; fpnk.r = st->tmpbuf[ncfft-k].r; fpnk.i = - st->tmpbuf[ncfft-k].i; C_FIXDIV(fpk,2); @@ -149,7 +149,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_ADD (st->tmpbuf[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); #else st->tmpbuf[ncfft - k].i *= -1; diff --git a/src/kissfft/kiss_fftr.h b/src/kissfft/kiss_fftr.h index 72e5a57..222bf95 100644 --- a/src/kissfft/kiss_fftr.h +++ b/src/kissfft/kiss_fftr.h @@ -6,13 +6,13 @@ 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; @@ -22,7 +22,7 @@ kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem, size_t * lenm /* nfft must be even - If you don't care to allocate space, use mem = lenmem = NULL + If you don't care to allocate space, use mem = lenmem = NULL */