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

datatype conversion #69

Closed genGoblin closed 4 years ago

genGoblin commented 4 years ago

i have a "std::vector<std::complex> samples;" I want to convert this to a univector but when I do "univector<complex> temp = make_univector(&samples.front(), samples.size());"

i get an error stating no viable conversion type. What would be the best way to convert my complex vector to the univector?

dancazarin commented 4 years ago

Hi, you have to use the same numeric type for the vector or do a conversion manually. You have std::complex and complex (kfr::complex). This is different but fully compatible types . Use reinterpret_cast to convert the pointer to proper type.

genGoblin commented 4 years ago

I am trying to do the following:

kfr::complex<float> *iQKFR = reinterpret_cast<kfr::complex<float>*>(&iQ);
size_t iqSize = sizeof(iQKFR);
univector<kfr::complex<float>> iq = make_univector(iQKFR, iQ.size());
std::cout << iq[0] << std::endl;

I want to see the first element in iq to make sure it is what I expect it to be. When I do the cout I get compiler error " error: invalid operands to binary expression ". What am I doing wronG?

dancazarin commented 4 years ago
size_t iqSize = sizeof(iQKFR);

This code retrieves size of the pointer, not the data and gives wrong results if iqSize is used somewhere. Try to change the last line to

println(iq[0]);

because std::cout does not support printing complex numbers. println is KFR function and does support complex numbers.

More details about your compiler output (full text of the error) would help to identify problem much quicker.

dancazarin commented 4 years ago

Reopen if still actual.