aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--al/buffer.cpp22
-rw-r--r--common/albyte.h52
2 files changed, 11 insertions, 63 deletions
diff --git a/al/buffer.cpp b/al/buffer.cpp
index 6436ea3c..7aa8edfd 100644
--- a/al/buffer.cpp
+++ b/al/buffer.cpp
@@ -118,10 +118,10 @@ void DecodeIMA4Block(int16_t *dst, const al::byte *src, size_t numchans, size_t
for(size_t c{0};c < numchans;c++)
{
- sample[c] = al::to_integer<int>(src[0]) | (al::to_integer<int>(src[1])<<8);
+ sample[c] = src[0] | (src[1]<<8);
sample[c] = (sample[c]^0x8000) - 32768;
src += 2;
- index[c] = al::to_integer<int>(src[0]) | (al::to_integer<int>(src[1])<<8);
+ index[c] = src[0] | (src[1]<<8);
index[c] = clampi((index[c]^0x8000) - 32768, 0, 88);
src += 2;
@@ -134,8 +134,8 @@ void DecodeIMA4Block(int16_t *dst, const al::byte *src, size_t numchans, size_t
{
for(size_t c{0};c < numchans;c++)
{
- code[c] = al::to_integer<ALuint>(src[0]) | (al::to_integer<ALuint>(src[1])<< 8) |
- (al::to_integer<ALuint>(src[2])<<16) | (al::to_integer<ALuint>(src[3])<<24);
+ code[c] = ALuint{src[0]} | (ALuint{src[1]}<< 8) | (ALuint{src[2]}<<16)
+ | (ALuint{src[3]}<<24);
src += 4;
}
}
@@ -164,25 +164,23 @@ void DecodeMSADPCMBlock(int16_t *dst, const al::byte *src, size_t numchans, size
for(size_t c{0};c < numchans;c++)
{
- blockpred[c] = std::min<ALubyte>(al::to_integer<ALubyte>(src[0]), 6);
+ blockpred[c] = std::min<ALubyte>(src[0], 6);
++src;
}
for(size_t c{0};c < numchans;c++)
{
- delta[c] = al::to_integer<int>(src[0]) | (al::to_integer<int>(src[1])<<8);
+ delta[c] = src[0] | (src[1]<<8);
delta[c] = (delta[c]^0x8000) - 32768;
src += 2;
}
for(size_t c{0};c < numchans;c++)
{
- samples[c][0] = static_cast<ALshort>(al::to_integer<int>(src[0]) |
- (al::to_integer<int>(src[1])<<8));
+ samples[c][0] = static_cast<ALshort>(src[0] | (src[1]<<8));
src += 2;
}
for(size_t c{0};c < numchans;c++)
{
- samples[c][1] = static_cast<ALshort>(al::to_integer<int>(src[0]) |
- (al::to_integer<int>(src[1])<<8));
+ samples[c][1] = static_cast<ALshort>(src[0] | (src[1]<<8));
src += 2;
}
@@ -206,13 +204,13 @@ void DecodeMSADPCMBlock(int16_t *dst, const al::byte *src, size_t numchans, size
int pred{(samples[c][0]*MSADPCMAdaptionCoeff[blockpred[c]][0] +
samples[c][1]*MSADPCMAdaptionCoeff[blockpred[c]][1]) / 256};
- pred += (al::to_integer<int>(nibble^0x08) - 0x08) * delta[c];
+ pred += ((nibble^0x08) - 0x08) * delta[c];
pred = clampi(pred, -32768, 32767);
samples[c][1] = samples[c][0];
samples[c][0] = static_cast<int16_t>(pred);
- delta[c] = (MSADPCMAdaption[al::to_integer<ALubyte>(nibble)] * delta[c]) / 256;
+ delta[c] = (MSADPCMAdaption[nibble] * delta[c]) / 256;
delta[c] = maxi(16, delta[c]);
*(dst++) = static_cast<int16_t>(pred);
diff --git a/common/albyte.h b/common/albyte.h
index b871164d..be586869 100644
--- a/common/albyte.h
+++ b/common/albyte.h
@@ -10,57 +10,7 @@ using uint = unsigned int;
namespace al {
-/* The "canonical" way to store raw byte data. Like C++17's std::byte, it's not
- * treated as a character type and does not work with arithmatic ops. Only
- * bitwise ops are allowed.
- */
-enum class byte : unsigned char { };
-
-template<typename T>
-constexpr std::enable_if_t<std::is_integral<T>::value,T>
-to_integer(al::byte b) noexcept { return T(b); }
-
-
-template<typename T>
-constexpr std::enable_if_t<std::is_integral<T>::value,al::byte>
-operator<<(al::byte lhs, T rhs) noexcept { return al::byte(to_integer<uint>(lhs) << rhs); }
-
-template<typename T>
-constexpr std::enable_if_t<std::is_integral<T>::value,al::byte>
-operator>>(al::byte lhs, T rhs) noexcept { return al::byte(to_integer<uint>(lhs) >> rhs); }
-
-template<typename T>
-constexpr std::enable_if_t<std::is_integral<T>::value,al::byte&>
-operator<<=(al::byte &lhs, T rhs) noexcept { lhs = lhs << rhs; return lhs; }
-
-template<typename T>
-constexpr std::enable_if_t<std::is_integral<T>::value,al::byte&>
-operator>>=(al::byte &lhs, T rhs) noexcept { lhs = lhs >> rhs; return lhs; }
-
-#define AL_DECL_OP(op, opeq) \
-template<typename T> \
-constexpr std::enable_if_t<std::is_integral<T>::value,al::byte> \
-operator op (al::byte lhs, T rhs) noexcept \
-{ return al::byte(to_integer<uint>(lhs) op static_cast<uint>(rhs)); } \
- \
-template<typename T> \
-constexpr std::enable_if_t<std::is_integral<T>::value,al::byte&> \
-operator opeq (al::byte &lhs, T rhs) noexcept { lhs = lhs op rhs; return lhs; } \
- \
-constexpr al::byte operator op (al::byte lhs, al::byte rhs) noexcept \
-{ return al::byte(lhs op to_integer<uint>(rhs)); } \
- \
-constexpr al::byte& operator opeq (al::byte &lhs, al::byte rhs) noexcept \
-{ lhs = lhs op rhs; return lhs; }
-
-AL_DECL_OP(|, |=)
-AL_DECL_OP(&, &=)
-AL_DECL_OP(^, ^=)
-
-#undef AL_DECL_OP
-
-constexpr al::byte operator~(al::byte b) noexcept
-{ return al::byte(~to_integer<uint>(b)); }
+using byte = unsigned char;
} // namespace al