commit 8a969d06cab0633552d6014a65ee5aa0abb0640c
parent 02febf79ec1cff575d3c220126d1746ad6b5e99c
Author: Stephen Larew <[email protected]>
Date: Thu, 20 Feb 2020 12:26:17 -0800
fix std::complex compatibility
Diffstat:
4 files changed, 20 insertions(+), 19 deletions(-)
diff --git a/include/kfr/dft/fft.hpp b/include/kfr/dft/fft.hpp
@@ -430,12 +430,12 @@ struct dct_plan : dft_plan<T>
dft_plan<T>::execute(mirrored_dft.data(), mirrored.data(), temp, cfalse);
for (size_t i = 0; i < halfSize; i++)
{
- out[i * 2 + 0] = mirrored_dft[i].re;
- out[i * 2 + 1] = mirrored_dft[size - 1 - i].re;
+ out[i * 2 + 0] = mirrored_dft[i].real();
+ out[i * 2 + 1] = mirrored_dft[size - 1 - i].real();
}
if (size % 2)
{
- out[size - 1] = mirrored_dft[halfSize].re;
+ out[size - 1] = mirrored_dft[halfSize].real();
}
}
}
diff --git a/include/kfr/dsp/iir_design.hpp b/include/kfr/dsp/iir_design.hpp
@@ -63,7 +63,7 @@ KFR_FUNCTION zpk<T> chebyshev1(int N, identity<T> rp)
univector<T> theta = c_pi<T> * m / (2 * N);
univector<complex<T>> p = -csinh(make_complex(mu, theta));
- T k = product(-p).re;
+ T k = product(-p).real();
if (N % 2 == 0)
k = k / sqrt(1.0 + eps * eps);
return { {}, std::move(p), k };
@@ -98,7 +98,7 @@ KFR_FUNCTION zpk<T> chebyshev2(int N, identity<T> rs)
p = make_complex(sinh(mu) * real(p), cosh(mu) * imag(p));
p = 1.0 / p;
- T k = (product(-p) / product(-z)).re;
+ T k = (product(-p) / product(-z)).real();
return { std::move(z), std::move(p), k };
}
@@ -868,7 +868,7 @@ KFR_FUNCTION zpk<T> bilinear(const zpk<T>& filter, identity<T> fs)
result.z = (fs2 + filter.z) / (fs2 - filter.z);
result.p = (fs2 + filter.p) / (fs2 - filter.p);
result.z.resize(result.p.size(), complex<T>(-1));
- result.k = filter.k * real(product(fs2 - filter.z) / product(fs2 - filter.p));
+ result.k = filter.k * kfr::real(product(fs2 - filter.z) / product(fs2 - filter.p));
return result;
}
@@ -881,7 +881,7 @@ struct zero_pole_pairs
template <typename T>
KFR_FUNCTION vec<T, 3> zpk2tf_poly(const complex<T>& x, const complex<T>& y)
{
- return { T(1), -(x.re + y.re), x.re * y.re - x.im * y.im };
+ return { T(1), -(x.real() + y.real()), x.real() * y.real() - x.imag() * y.imag() };
}
template <typename T>
@@ -897,18 +897,18 @@ template <typename T>
KFR_FUNCTION univector<complex<T>> cplxreal(const univector<complex<T>>& list)
{
univector<complex<T>> x = list;
- std::sort(x.begin(), x.end(), [](const complex<T>& a, const complex<T>& b) { return a.re < b.re; });
+ std::sort(x.begin(), x.end(), [](const complex<T>& a, const complex<T>& b) { return a.real() < b.real(); });
T tol = std::numeric_limits<T>::epsilon() * 100;
univector<complex<T>> result = x;
for (size_t i = result.size(); i > 1; i--)
{
if (!isreal(result[i - 1]) && !isreal(result[i - 2]))
{
- if (abs(result[i - 1].re - result[i - 2].re) < tol &&
- abs(result[i - 1].im + result[i - 2].im) < tol)
+ if (abs(result[i - 1].real() - result[i - 2].real()) < tol &&
+ abs(result[i - 1].imag() + result[i - 2].imag()) < tol)
{
result.erase(result.begin() + i - 1);
- result[i - 2].im = abs(result[i - 2].im);
+ result[i - 2].imag(abs(result[i - 2].imag()));
}
}
}
@@ -951,7 +951,7 @@ KFR_FUNCTION int countreal(const univector<complex<T>>& list)
int nreal = 0;
for (complex<T> c : list)
{
- if (c.im == 0)
+ if (c.imag() == 0)
nreal++;
}
return nreal;
@@ -974,7 +974,7 @@ KFR_FUNCTION zpk<T> lp2hp_zpk(const zpk<T>& filter, identity<T> wo)
result.z = wo / filter.z;
result.p = wo / filter.p;
result.z.resize(result.p.size(), T(0));
- result.k = filter.k * real(product(-filter.z) / product(-filter.p));
+ result.k = filter.k * kfr::real(product(-filter.z) / product(-filter.p));
return result;
}
@@ -1012,7 +1012,7 @@ KFR_FUNCTION zpk<T> lp2bs_zpk(const zpk<T>& filter, identity<T> wo, identity<T>
result.z.resize(result.z.size() + filter.p.size() - filter.z.size(), complex<T>(0, +wo));
result.z.resize(result.z.size() + filter.p.size() - filter.z.size(), complex<T>(0, -wo));
- result.k = filter.k * real(product(-filter.z) / product(-filter.p));
+ result.k = filter.k * kfr::real(product(-filter.z) / product(-filter.p));
return result;
}
diff --git a/include/kfr/simd/complex.hpp b/include/kfr/simd/complex.hpp
@@ -60,13 +60,13 @@ struct complex
constexpr complex(const complex&) CMT_NOEXCEPT = default;
constexpr complex(complex&&) CMT_NOEXCEPT = default;
template <typename U>
- KFR_MEM_INTRINSIC constexpr complex(const complex<U>& other) CMT_NOEXCEPT : re(static_cast<T>(other.re)),
- im(static_cast<T>(other.im))
+ KFR_MEM_INTRINSIC constexpr complex(const complex<U>& other) CMT_NOEXCEPT : re(static_cast<T>(other.real())),
+ im(static_cast<T>(other.imag()))
{
}
template <typename U>
- KFR_MEM_INTRINSIC constexpr complex(complex<U>&& other) CMT_NOEXCEPT : re(std::move(other.re)),
- im(std::move(other.im))
+ KFR_MEM_INTRINSIC constexpr complex(complex<U>&& other) CMT_NOEXCEPT : re(std::move(other.real())),
+ im(std::move(other.imag()))
{
}
#ifdef CMT_COMPILER_GNU
@@ -80,6 +80,7 @@ struct complex
KFR_MEM_INTRINSIC constexpr const T& imag() const CMT_NOEXCEPT { return im; }
KFR_MEM_INTRINSIC constexpr void real(T value) CMT_NOEXCEPT { re = value; }
KFR_MEM_INTRINSIC constexpr void imag(T value) CMT_NOEXCEPT { im = value; }
+private:
T re;
T im;
};
diff --git a/tests/dsp_test.cpp b/tests/dsp_test.cpp
@@ -444,7 +444,7 @@ inline std::complex<T> from_std(const std::complex<T>& c)
template <typename T>
inline std::complex<T> to_std(const kfr::complex<T>& c)
{
- return { c.re, c.im };
+ return { c.real(), c.imag() };
}
template <typename T>