From d0c28c652f10856f3f1eadbbe8f362be6224355d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 14 Feb 2023 00:00:46 -0800 Subject: Support IMA4 ADPCM as a mixing voice format --- common/alnumeric.h | 21 +++++++++++++++------ common/alspan.h | 8 +------- common/altraits.h | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 common/altraits.h (limited to 'common') diff --git a/common/alnumeric.h b/common/alnumeric.h index 13e61645..a426763f 100644 --- a/common/alnumeric.h +++ b/common/alnumeric.h @@ -12,6 +12,7 @@ #include #endif +#include "altraits.h" #include "opthelpers.h" @@ -97,12 +98,20 @@ inline uint32_t NextPowerOf2(uint32_t value) noexcept return value+1; } -/** Round up a value to the next multiple. */ -inline size_t RoundUp(size_t value, size_t r) noexcept -{ - value += r-1; - return value - (value%r); -} +/** + * If the value is not already a multiple of r, round down to the next + * multiple. + */ +template +constexpr T RoundDown(T value, al::type_identity_t r) noexcept +{ return value - (value%r); } + +/** + * If the value is not already a multiple of r, round up to the next multiple. + */ +template +constexpr T RoundUp(T value, al::type_identity_t r) noexcept +{ return RoundDown(value + r-1, r); } /** diff --git a/common/alspan.h b/common/alspan.h index 519f22e4..1d6cdfe5 100644 --- a/common/alspan.h +++ b/common/alspan.h @@ -8,6 +8,7 @@ #include #include "almalloc.h" +#include "altraits.h" namespace al { @@ -37,13 +38,6 @@ constexpr const T* data(std::initializer_list list) noexcept { return list.begin(); } -template -struct type_identity { using type = T; }; - -template -using type_identity_t = typename type_identity::type; - - constexpr size_t dynamic_extent{static_cast(-1)}; template diff --git a/common/altraits.h b/common/altraits.h new file mode 100644 index 00000000..7ce0422e --- /dev/null +++ b/common/altraits.h @@ -0,0 +1,14 @@ +#ifndef COMMON_ALTRAITS_H +#define COMMON_ALTRAITS_H + +namespace al { + +template +struct type_identity { using type = T; }; + +template +using type_identity_t = typename type_identity::type; + +} // namespace al + +#endif /* COMMON_ALTRAITS_H */ -- cgit v1.2.3