kfrlib / kfr

Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
https://www.kfrlib.com
GNU General Public License v2.0
1.65k stars 253 forks source link

Is it possible to change DFT size at the run time? #93

Closed kakyoism closed 3 years ago

kakyoism commented 4 years ago

It seems to me that kfr's univector size is fixed at the compile time. For instance, this is how to initialize a univector if I'm not mistaken.

using namespace kfr;

const int nFFT = 2048;
univector<complex<fbase>, nFFT> spectrum = scalar(qnan);

then later when you compute the spectrum,

myDft.execute(spectrum, timeDomainVec, myWorkBuf);

So it seems that the sizes must be fixed at the compile time. After all univector is an std::array.

Then it's unclear to me how to achieve on-the-fly FFT size update. Should I hack it with creating a large enough univector and only down-size it by taking a portion of it when necessary?

Am I missing anything obvious?

samuelriddle commented 4 years ago

Hi, univector size is not fixed at runtime if you omit size parameter in the template.

univector<float> u1(1024); // dynamic size, like std::vector and inherited from it
univector<float, 1024> u2; // compile-time size, like std::array and inherited from it
univector<float, 0> u3(ptr_to_float, your_size); // creates array that references your data (not owns)

All kfr functions take all three options, so you are free to create dynamic, compile-time arrays or pass your pointer to avoid any data copying.