diff options
author | Chris Robinson <[email protected]> | 2023-02-14 00:00:46 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2023-02-14 02:32:07 -0800 |
commit | d0c28c652f10856f3f1eadbbe8f362be6224355d (patch) | |
tree | 93fc754d14acb8f89f595e62a1672e3be1a05354 /common | |
parent | c10df8ab545320e636404a8ed5f81b2c08c565b3 (diff) |
Support IMA4 ADPCM as a mixing voice format
Diffstat (limited to 'common')
-rw-r--r-- | common/alnumeric.h | 21 | ||||
-rw-r--r-- | common/alspan.h | 8 | ||||
-rw-r--r-- | common/altraits.h | 14 |
3 files changed, 30 insertions, 13 deletions
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 <xmmintrin.h> #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<typename T> +constexpr T RoundDown(T value, al::type_identity_t<T> r) noexcept +{ return value - (value%r); } + +/** + * If the value is not already a multiple of r, round up to the next multiple. + */ +template<typename T> +constexpr T RoundUp(T value, al::type_identity_t<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 <type_traits> #include "almalloc.h" +#include "altraits.h" namespace al { @@ -37,13 +38,6 @@ constexpr const T* data(std::initializer_list<T> list) noexcept { return list.begin(); } -template<typename T> -struct type_identity { using type = T; }; - -template<typename T> -using type_identity_t = typename type_identity<T>::type; - - constexpr size_t dynamic_extent{static_cast<size_t>(-1)}; template<typename T, size_t E=dynamic_extent> 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<typename T> +struct type_identity { using type = T; }; + +template<typename T> +using type_identity_t = typename type_identity<T>::type; + +} // namespace al + +#endif /* COMMON_ALTRAITS_H */ |