Browse Source

AudioBuffer: Fix alignment check on iOS/arm7

On iOS/arm7, double has an alignment of 8 but std::max_align_t has
alignment of 4, so we need to compute our own max_align value.
tags/2021-05-28
reuk 5 years ago
parent
commit
0ac8552a63
1 changed files with 48 additions and 1 deletions
  1. +48
    -1
      modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h

+ 48
- 1
modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h View File

@@ -23,6 +23,53 @@
namespace juce
{
#ifndef DOXYGEN
/** The contents of this namespace are used to implement AudioBuffer and should
not be used elsewhere. Their interfaces (and existence) are liable to change!
*/
namespace detail
{
/** On iOS/arm7 the alignment of `double` is greater than the alignment of
`std::max_align_t`, so we can't trust max_align_t. Instead, we query
lots of primitive types and use the maximum alignment of all of them.
We're putting this stuff outside AudioBuffer itself to avoid creating
unnecessary copies for each distinct template instantiation of
AudioBuffer.
MSVC 2015 doesn't like when we write getMaxAlignment as a loop which
accumulates the max alignment (declarations not allowed in constexpr
function body) so instead we use this recursive version which
instantiates a zillion templates.
*/
template <typename> struct Type {};
constexpr size_t getMaxAlignment() noexcept { return 0; }
template <typename Head, typename... Tail>
constexpr size_t getMaxAlignment (Type<Head>, Type<Tail>... tail) noexcept
{
return jmax (alignof (Head), getMaxAlignment (tail...));
}
constexpr size_t maxAlignment = getMaxAlignment (Type<std::max_align_t>{},
Type<void*>{},
Type<float>{},
Type<double>{},
Type<long double>{},
Type<short int>{},
Type<int>{},
Type<long int>{},
Type<long long int>{},
Type<bool>{},
Type<char>{},
Type<char16_t>{},
Type<char32_t>{},
Type<wchar_t>{});
} // namespace detail
#endif
//==============================================================================
/**
A multi-channel buffer containing floating point audio samples.
@@ -1076,7 +1123,7 @@ private:
void allocateData()
{
#if (! JUCE_GCC) || (__GNUC__ * 100 + __GNUC_MINOR__) >= 409
static_assert (std::alignment_of<Type>::value <= std::alignment_of<std::max_align_t>::value,
static_assert (alignof (Type) <= detail::maxAlignment,
"AudioBuffer cannot hold types with alignment requirements larger than that guaranteed by malloc");
#endif
jassert (size >= 0);


Loading…
Cancel
Save