commit 9fc73247f43b303617329294ae264613df4dce71
parent c8c4dd005b033dc59079d936ba7b29cf4e697533
Author: d.levin256@gmail.com <d.levin256@gmail.com>
Date: Wed, 28 Apr 2021 18:34:40 +0000
Add KFR_STD_COMPLEX cmake option, fix std::complex issue
Diffstat:
4 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -65,6 +65,7 @@ option(REGENERATE_TESTS "Regenerate auto tests" OFF)
option(DISABLE_CLANG_EXTENSIONS "Disable Clang vector extensions" OFF)
option(KFR_EXTENDED_TESTS "Extended tests (up to hour)" OFF)
option(SKIP_TESTS "Skip tests (only build)" OFF)
+option(KFR_STD_COMPLEX "Use std::complex instead of custom complex type" OFF)
mark_as_advanced(ENABLE_ASMTEST)
mark_as_advanced(REGENERATE_TESTS)
mark_as_advanced(DISABLE_CLANG_EXTENSIONS)
@@ -143,6 +144,9 @@ endif ()
if (DISABLE_CLANG_EXTENSIONS)
target_compile_definitions(kfr INTERFACE -DCMT_DISABLE_CLANG_EXT)
endif ()
+if (KFR_STD_COMPLEX)
+ target_compile_definitions(kfr INTERFACE -DKFR_STD_COMPLEX)
+endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(kfr INTERFACE -Wno-ignored-qualifiers)
endif ()
diff --git a/include/kfr/dsp/sample_rate_conversion.hpp b/include/kfr/dsp/sample_rate_conversion.hpp
@@ -123,7 +123,7 @@ public:
jj = jj - taps + 1;
}
- const T s = reciprocal(sum(filter)) * interpolation_factor * scale;
+ const T s = reciprocal(sum(filter)) * static_cast<ftype>(interpolation_factor * scale);
filter = filter * s;
}
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
@@ -16,6 +16,7 @@
cmake_minimum_required(VERSION 3.1)
+
add_definitions(-DKFR_TESTING=1)
add_definitions(-DKFR_SRC_DIR=\"${CMAKE_SOURCE_DIR}\")
diff --git a/tests/dsp_test.cpp b/tests/dsp_test.cpp
@@ -630,6 +630,23 @@ TEST(resampler_test)
CHECK(rms(slice(out - ref, static_cast<size_t>(ceil(delay * 2)))) < 0.005f);
}
+TEST(resampler_test_complex)
+{
+ using type = complex<fbase>;
+ const int in_sr = 44100;
+ const int out_sr = 48000;
+ const int freq = 100;
+ auto resampler = sample_rate_converter<type>(resample_quality::draft, out_sr, in_sr);
+ double delay = resampler.get_fractional_delay();
+ univector<type> out(out_sr / 10);
+ univector<type> in = truncate(sin(c_pi<fbase> * phasor<fbase>(freq, in_sr, 0)), in_sr / 10);
+ univector<type> ref = truncate(
+ sin(c_pi<fbase> * phasor<fbase>(freq, out_sr, -delay * (static_cast<double>(freq) / out_sr))),
+ out_sr / 10);
+ resampler.process(out, in);
+
+ CHECK(rms(cabs(slice(out - ref, static_cast<size_t>(ceil(delay * 2))))) < 0.005f);
+}
} // namespace CMT_ARCH_NAME
#ifndef KFR_NO_MAIN