Compiling kiss fft with float and double support in the same app

662 Views Asked by At

I'm trying to get kiss fft to compile both float and double implementations in the same app using visual studio 2013. I see that all I need to do is set the kiss_fft_scalar to double and re-compile to get double.

To this end I put together a header whereby I include the headers with kiss_fft_scalar changed inside 2 different namespaces as follows:

namespace KissFloat
{
    #undef KISS_FFT_H
    #undef KISS_FTR_H
    #define kiss_fft_scalar float
    #include "kiss_fft.h"
    #include "tools/kiss_fftr.h"
};

namespace KissDouble
{
    #undef KISS_FFT_H
    #undef KISS_FTR_H
    #define kiss_fft_scalar double
    #include "kiss_fft.h"
    #include "tools/kiss_fftr.h"
};

I can't however figure out how to include the cpp code. I've tried a seperate KissFloat and KissDouble file. I've then tried a few things in the cpp file but everything I try ends up with compile errors. usually relating to struct redefinition.

Can anyone think of a way to make this work? Or am I just better off re-writing kiss fft using templates?

2

There are 2 best solutions below

0
Goz On BEST ANSWER

So I've discovered that Eigen has done the work of templating kiss FFT for me. Yay to other people doing the hard work! ;)

Eigen is available here:

https://bitbucket.org/eigen/eigen/src

and the kiss fft implementation is under

"unsupported/Eigen/src/FFT/"

1
Mark Borgerding On

Interesting idea, but you might have better luck just hacking on the files e.g. making kiss_fft_scalar a template parameter. One problem is that the header files will be including other header files like stdlib.h. I suppose you could pre-emptively include those files before you do your namespace trick.

I'm guessing the struct redef errors are for the kiss_fft_state in _kiss_fft_guts.h? It might work if you have separate Float/Double .cpp files and using directives before inclusion of the .c files.

If you decide to templatize it, you could take a look at the Eigen (partial) c++ port of kissfft.