# Fixes compilation errors when using the devkitARM toolchain to compile OpenAL Soft. # For some reason, there's no implicit casting between `int` and `int32_t` and between `unsigned int` and `uint32_t` in devkitARM even though they're the same size, so we have to do this whole song and dance to appease the compiler. --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -2120,7 +2120,7 @@ inline T SampleConv(float) noexcept; template<> inline float SampleConv(float val) noexcept { return val; } -template<> inline int32_t SampleConv(float val) noexcept +template<> inline int SampleConv(float val) noexcept { /* Floats have a 23-bit mantissa, plus an implied 1 bit and a sign bit. * This means a normalized float has at most 25 bits of signed precision. @@ -2129,13 +2129,16 @@ template<> inline int32_t SampleConv(float val) noexcept */ return fastf2i(std::clamp(val*2147483648.0f, -2147483648.0f, 2147483520.0f)); } +#ifdef __DEVKITARM__ +template<> inline long SampleConv(float val) noexcept { return (long)SampleConv(val); } +#endif template<> inline int16_t SampleConv(float val) noexcept { return static_cast(fastf2i(std::clamp(val*32768.0f, -32768.0f, 32767.0f))); } template<> inline int8_t SampleConv(float val) noexcept { return static_cast(fastf2i(std::clamp(val*128.0f, -128.0f, 127.0f))); } /* Define unsigned output variations. */ -template<> inline uint32_t SampleConv(float val) noexcept +template<> inline unsigned int SampleConv(float val) noexcept { return static_cast(SampleConv(val)) + 2147483648u; } template<> inline uint16_t SampleConv(float val) noexcept { return static_cast(SampleConv(val) + 32768); } --- a/core/converter.cpp +++ b/core/converter.cpp @@ -83,16 +83,16 @@ inline DevFmtType_t StoreSample(float) noexcept; template<> inline float StoreSample(float val) noexcept { return val; } -template<> inline int32_t StoreSample(float val) noexcept -{ return fastf2i(std::clamp(val*2147483648.0f, -2147483648.0f, 2147483520.0f)); } +template<> inline int StoreSample(float val) noexcept +{ static_assert(sizeof(int) == sizeof(int32_t), "`int` should be a 32-bit integer"); return fastf2i(std::clamp(val*2147483648.0f, -2147483648.0f, 2147483520.0f)); } template<> inline int16_t StoreSample(float val) noexcept { return static_cast(fastf2i(std::clamp(val*32768.0f, -32768.0f, 32767.0f))); } template<> inline int8_t StoreSample(float val) noexcept { return static_cast(fastf2i(std::clamp(val*128.0f, -128.0f, 127.0f))); } /* Define unsigned output variations. */ -template<> inline uint32_t StoreSample(float val) noexcept -{ return static_cast(StoreSample(val)) + 2147483648u; } +template<> inline unsigned int StoreSample(float val) noexcept +{ static_assert(sizeof(unsigned int) == sizeof(uint32_t), "`unsigned int` should be a 32-bit integer"); return static_cast(StoreSample(val)) + 2147483648u; } template<> inline uint16_t StoreSample(float val) noexcept { return static_cast(StoreSample(val) + 32768); } template<> inline uint8_t StoreSample(float val) noexcept --- a/core/devformat.h +++ b/core/devformat.h @@ -94,9 +94,9 @@ struct DevFmtTypeTraits { using Type = int16_t; }; template<> struct DevFmtTypeTraits { using Type = uint16_t; }; template<> -struct DevFmtTypeTraits { using Type = int32_t; }; +struct DevFmtTypeTraits { static_assert(sizeof(int) == sizeof(int32_t), "`int` should be a 32-bit integer"); using Type = int; }; template<> -struct DevFmtTypeTraits { using Type = uint32_t; }; +struct DevFmtTypeTraits { static_assert(sizeof(unsigned int) == sizeof(uint32_t), "`unsigned int` should be a 32-bit integer"); using Type = unsigned int; }; template<> struct DevFmtTypeTraits { using Type = float; };