diff --git a/modules/dsp/chowdsp_buffers/Buffers/chowdsp_BufferView.h b/modules/dsp/chowdsp_buffers/Buffers/chowdsp_BufferView.h index a36a329d8..12711039b 100644 --- a/modules/dsp/chowdsp_buffers/Buffers/chowdsp_BufferView.h +++ b/modules/dsp/chowdsp_buffers/Buffers/chowdsp_BufferView.h @@ -261,4 +261,113 @@ class BufferView static constexpr int maxNumChannels = CHOWDSP_BUFFER_MAX_NUM_CHANNELS; std::array channelPointers {}; }; + +#ifndef DOXYGEN +namespace detail +{ + template + struct is_static_buffer + { + static constexpr bool value = false; + }; + + template + struct is_static_buffer, T> + { + static constexpr bool value = true; + }; + + template + constexpr auto is_static_buffer_v = is_static_buffer::value; + + static_assert (is_static_buffer_v, float> == true); + static_assert (is_static_buffer_v, double> != true); +} // namespace detail +#endif // DOXYGEN + +/** Template deduction guide for Buffer -> BufferView */ +template > || detail::is_static_buffer_v +#if CHOWDSP_USING_JUCE + || std::is_same_v> +#if JUCE_MODULE_AVAILABLE_juce_dsp + || std::is_same_v> +#endif +#endif + >> +BufferView (BufferType&, Ts...) -> BufferView; + +/** Template deduction guide for const Buffer -> BufferView */ +template > || (std::is_const_v && detail::is_static_buffer_v, float>) +#if CHOWDSP_USING_JUCE + || std::is_same_v> +#if JUCE_MODULE_AVAILABLE_juce_dsp + || std::is_same_v, juce::dsp::AudioBlock> +#endif +#endif + >> +BufferView (BufferType&, Ts...) -> BufferView; + +/** Template deduction guide for Buffer -> BufferView */ +template > || detail::is_static_buffer_v +#if CHOWDSP_USING_JUCE + || std::is_same_v> +#if JUCE_MODULE_AVAILABLE_juce_dsp + || std::is_same_v> +#endif +#endif + >> +BufferView (BufferType&, Ts...) -> BufferView; + +/** Template deduction guide for const Buffer -> BufferView */ +template > || (std::is_const_v && detail::is_static_buffer_v, double>) +#if CHOWDSP_USING_JUCE + || std::is_same_v> +#if JUCE_MODULE_AVAILABLE_juce_dsp + || std::is_same_v, juce::dsp::AudioBlock> +#endif +#endif + >> +BufferView (BufferType&, Ts...) -> BufferView; + +#if ! CHOWDSP_NO_XSIMD +/** Template deduction guide for Buffer> -> BufferView> */ +template >> || detail::is_static_buffer_v>>> +BufferView (BufferType&, Ts...) -> BufferView>; + +/** Template deduction guide for const Buffer> -> BufferView> */ +template >> || (std::is_const_v && detail::is_static_buffer_v, xsimd::batch>)>> +BufferView (BufferType&, Ts...) -> BufferView>; + +/** Template deduction guide for Buffer> -> BufferView> */ +template >> || detail::is_static_buffer_v>>> +BufferView (BufferType&, Ts...) -> BufferView>; + +/** Template deduction guide for const Buffer> -> BufferView> */ +template >> || (std::is_const_v && detail::is_static_buffer_v, xsimd::batch>)>> +BufferView (BufferType&, Ts...) -> BufferView>; +#endif // ! CHOWDSP_NO_XSIMD } // namespace chowdsp diff --git a/tests/dsp_tests/chowdsp_buffers_test/BufferViewTest.cpp b/tests/dsp_tests/chowdsp_buffers_test/BufferViewTest.cpp index 265f4c186..a5938f5bb 100644 --- a/tests/dsp_tests/chowdsp_buffers_test/BufferViewTest.cpp +++ b/tests/dsp_tests/chowdsp_buffers_test/BufferViewTest.cpp @@ -141,3 +141,73 @@ TEMPLATE_TEST_CASE ("Buffer View Test", "[dsp][buffers][simd]", float, double, x } } JUCE_END_IGNORE_WARNINGS_GCC_LIKE + +TEMPLATE_TEST_CASE ("Buffer View Template Deduction Test", "[dsp][buffers][simd]", float, double, xsimd::batch, xsimd::batch) +{ + SECTION ("1D Raw Data") + { + TestType* data = nullptr; + chowdsp::BufferView buffer_view { data, 0 }; + STATIC_REQUIRE (std::is_same_v>); + + const TestType* data_const = nullptr; + chowdsp::BufferView buffer_view_const { data_const, 0 }; + STATIC_REQUIRE (std::is_same_v>); + } + + SECTION ("2D Raw Data") + { + TestType* const* data = nullptr; + chowdsp::BufferView buffer_view { data, 0, 0 }; + STATIC_REQUIRE (std::is_same_v>); + + const TestType* const* data_const = nullptr; + chowdsp::BufferView buffer_view_const { data_const, 0, 0 }; + STATIC_REQUIRE (std::is_same_v>); + } + + SECTION ("chowdsp::Buffer") + { + chowdsp::Buffer buffer; + chowdsp::BufferView buffer_view { buffer }; + STATIC_REQUIRE (std::is_same_v>); + + chowdsp::BufferView buffer_view_const { std::as_const (buffer), 0, -1, 0, -1 }; + STATIC_REQUIRE (std::is_same_v>); + } + + SECTION ("chowdsp::StaticBuffer") + { + chowdsp::StaticBuffer buffer; + chowdsp::BufferView buffer_view { buffer }; + STATIC_REQUIRE (std::is_same_v>); + + const chowdsp::StaticBuffer buffer_const; + chowdsp::BufferView buffer_view_const { buffer_const }; + STATIC_REQUIRE (std::is_same_v>); + } + + if constexpr (std::is_floating_point_v) + { + SECTION ("juce::AudioBuffer") + { + juce::AudioBuffer buffer; + chowdsp::BufferView buffer_view { buffer }; + STATIC_REQUIRE (std::is_same_v>); + + chowdsp::BufferView buffer_view_const { std::as_const (buffer), 0, -1, 0, -1 }; + STATIC_REQUIRE (std::is_same_v>); + } + + SECTION ("juce::dsp::AudioBlock") + { + juce::dsp::AudioBlock buffer; + chowdsp::BufferView buffer_view { buffer }; + STATIC_REQUIRE (std::is_same_v>); + + juce::dsp::AudioBlock buffer_const; + chowdsp::BufferView buffer_view_const { std::as_const (buffer_const), 0, -1, 0, -1 }; + STATIC_REQUIRE (std::is_same_v>); + } + } +}