commit 4e2e8253b304381ed95ea70cd2d73742be40bb67
parent 1873310b8db3a0c2f0c6f86516c95cd824741002
Author: d.levin256@gmail.com <d.levin256@gmail.com>
Date: Sun, 5 Mar 2023 10:20:54 +0000
Fix gen_sin
Diffstat:
2 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/include/kfr/base/generators.hpp b/include/kfr/base/generators.hpp
@@ -102,7 +102,8 @@ private:
KFR_MEM_INTRINSIC vec<T, width> call_get_value() const { return ptr_cast<Class>(this)->get_value(); }
- KFR_MEM_INTRINSIC std::enable_if_t<std::is_same_v<T, Twork>, vec<T, width>> get_value() const
+ template <typename U = T, KFR_ENABLE_IF(std::is_same_v<U, Twork>)>
+ KFR_MEM_INTRINSIC vec<T, width> get_value() const
{
return value;
}
@@ -236,18 +237,15 @@ struct generator_sin : public generator<T, VecWidth, generator_sin<T, VecWidth>,
KFR_MEM_INTRINSIC void next() const CMT_NOEXCEPT
{
- const vec<T, 2 * VecWidth> cs = flatten(this->value);
+ vec<T, 2 * VecWidth> cs = flatten(this->value);
cs = cs - addsub(alpha * cs, beta * swap<2>(cs));
this->value = vec<vec<T, 2>, VecWidth>::from_flatten(cs);
-
- // const vec<T, VecWidth> c = even(flatten(this->value));
- // const vec<T, VecWidth> s = odd(flatten(this->value));
- // const vec<T, VecWidth> cc = alpha * c + beta * s;
- // const vec<T, VecWidth> ss = alpha * s - beta * c;
- // this->cos_value = c - cc;
- // this->value = s - ss;
+ }
+ KFR_MEM_INTRINSIC vec<T, VecWidth> get_value() const
+ {
+ return odd(flatten(this->value));
}
protected:
diff --git a/tests/dsp_test.cpp b/tests/dsp_test.cpp
@@ -69,7 +69,7 @@ TEST(mixdown_stereo)
TEST(sine_type)
{
double ph = 0.0;
- using T = decltype(sine(ph));
+ using T = decltype(sine(ph));
static_assert(std::is_same_v<T, double>);
}
@@ -89,6 +89,22 @@ void test_ir(E&& e, const univector<T, size>& test_vector)
println(absmaxof(ir - test_vector));
}
+TEST(gen_sin)
+{
+ kfr::univector<kfr::fbase> x;
+ constexpr size_t size = 132;
+ kfr::fbase step = kfr::c_pi<kfr::fbase> / (size + 1);
+ kfr::univector<kfr::fbase> up;
+ up = kfr::truncate(kfr::gen_sin<kfr::fbase>(kfr::c_pi<kfr::fbase> / 2, step), size);
+
+ kfr::univector<kfr::fbase> up2(size);
+ for (int i = 0; i < size; ++i)
+ {
+ up2[i] = std::sin(kfr::c_pi<kfr::fbase> / 2 + i * step);
+ }
+ CHECK(rms(up - up2) < 0.00001);
+}
+
} // namespace CMT_ARCH_NAME
#ifndef KFR_NO_MAIN