Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Padding the size of buffers from make_temp_buffer #547

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion modules/dsp/chowdsp_buffers/Buffers/chowdsp_BufferView.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,17 @@ BufferView (BufferType&, Ts...) -> BufferView<const xsimd::batch<double>>;
template <typename T>
BufferView<T> make_temp_buffer (ArenaAllocatorView arena, int num_channels, int num_samples)
{
int num_samples_padded = num_samples;
#if ! CHOWDSP_NO_XSIMD
static constexpr auto vec_size = (int) xsimd::batch<T>::size;
if constexpr (std::is_floating_point_v<T>)
num_samples_padded = buffers_detail::ceiling_divide (num_samples, vec_size) * vec_size;
#endif

std::array<T*, CHOWDSP_BUFFER_MAX_NUM_CHANNELS> channel_pointers {};
for (size_t ch = 0; ch < static_cast<size_t> (num_channels); ++ch)
{
channel_pointers[ch] = arena.allocate<T> (num_samples, SIMDUtils::defaultSIMDAlignment);
channel_pointers[ch] = arena.allocate<T> (num_samples_padded, SIMDUtils::defaultSIMDAlignment);
jassert (channel_pointers[ch] != nullptr);
}
return { channel_pointers.data(), num_channels, num_samples };
Expand Down
11 changes: 11 additions & 0 deletions tests/dsp_tests/chowdsp_buffers_test/BufferViewTest.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <chowdsp_buffers/chowdsp_buffers.h>
#include <chowdsp_data_structures/chowdsp_data_structures.h>

JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wfloat-equal")
#include <CatchUtils.h>
Expand Down Expand Up @@ -139,6 +140,16 @@ TEMPLATE_TEST_CASE ("Buffer View Test", "[dsp][buffers][simd]", float, double, x
REQUIRE (buffer_view.getReadPointer (0) == buffer_view_copy.getReadPointer (0));
}
}

if constexpr (std::is_floating_point_v<TestType>)
{
SECTION ("make_temp_buffer")
{
chowdsp::ArenaAllocator<> arena { 1 << 10 };
chowdsp::make_temp_buffer<float> (arena, 2, 61);
REQUIRE (arena.get_bytes_used() == 64 * 2 * sizeof (float));
}
}
}
JUCE_END_IGNORE_WARNINGS_GCC_LIKE

Expand Down
Loading