commit aeb509db3e72d19ead122b6034f44df44369c1dc
parent 6364aaecf3e7dc3bc3f76fbe4f87bbde5224cd58
Author: [email protected] <[email protected]>
Date: Wed, 21 Aug 2019 05:53:04 +0000
make_univector for containers and arrays
Diffstat:
3 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
@@ -85,7 +85,7 @@ mkdocs/
.idea/
# VSCode
-.vs-code/
+.vscode/
.vs/
*.code-workspace
diff --git a/examples/biquads.cpp b/examples/biquads.cpp
@@ -67,6 +67,22 @@ int main()
plot_save("biquad_bandpass", output, options + ", title='Biquad band pass (0.25, 0.2)'");
{
+ biquad_params<fbase> bq[] = { biquad_bandpass(0.25, 0.2) };
+ std::vector<fbase> data(output.size(), 0.f);
+ data[0] = 1.f;
+ output = biquad(bq, make_univector(data));
+ }
+ plot_save("biquad_bandpass_stdvector", output, options + ", title='Biquad band pass (0.25, 0.2)'");
+
+ {
+ biquad_params<fbase> bq[] = { biquad_bandpass(0.25, 0.2) };
+ fbase data[output.size()] = { 0 }; // .size() is constexpr
+ data[0] = 1.f;
+ output = biquad(bq, make_univector(data));
+ }
+ plot_save("biquad_bandpass_carray", output, options + ", title='Biquad band pass (0.25, 0.2)'");
+
+ {
// filter initialization
biquad_params<fbase> bq[] = { biquad_lowpass(0.2, 0.9) };
expression_filter<fbase> filter = to_filter(biquad(bq, placeholder<fbase>()));
diff --git a/include/kfr/base/univector.hpp b/include/kfr/base/univector.hpp
@@ -505,6 +505,36 @@ KFR_INTRINSIC univector_ref<const T> make_univector(const T* data, size_t size)
return univector_ref<const T>(data, size);
}
+/// @brief Creates univector from a container (must have data() and size() methods)
+template <typename Container, KFR_ENABLE_IF(kfr::has_data_size<Container>::value),
+ typename T = value_type_of<Container>>
+KFR_INTRINSIC univector_ref<const T> make_univector(const Container& container)
+{
+ return univector_ref<const T>(container.data(), container.size());
+}
+
+/// @brief Creates univector from a container (must have data() and size() methods)
+template <typename Container, KFR_ENABLE_IF(kfr::has_data_size<Container>::value),
+ typename T = value_type_of<Container>>
+KFR_INTRINSIC univector_ref<T> make_univector(Container& container)
+{
+ return univector_ref<T>(container.data(), container.size());
+}
+
+/// @brief Creates univector from a sized array
+template <typename T, size_t N>
+KFR_INTRINSIC univector_ref<T> make_univector(T (&arr)[N])
+{
+ return univector_ref<T>(arr, N);
+}
+
+/// @brief Creates univector from a sized array
+template <typename T, size_t N>
+KFR_INTRINSIC univector_ref<const T> make_univector(const T (&arr)[N])
+{
+ return univector_ref<const T>(arr, N);
+}
+
/// @brief Single producer single consumer lock-free ring buffer
template <typename T>
struct lockfree_ring_buffer