From a478fd4b2506ab5105c7e759762786a9f855cf3e Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 11 Jun 2019 14:59:06 -0700 Subject: Fix unsigned short/int sample converters And add const/noexcept in some places --- Alc/converter.cpp | 53 ++++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/Alc/converter.cpp b/Alc/converter.cpp index 5535fd42..a6a5f2c4 100644 --- a/Alc/converter.cpp +++ b/Alc/converter.cpp @@ -15,27 +15,28 @@ namespace { * chokes on that given the inline specializations. */ template -inline ALfloat LoadSample(typename DevFmtTypeTraits::Type val); +inline ALfloat LoadSample(typename DevFmtTypeTraits::Type val) noexcept; -template<> inline ALfloat LoadSample(DevFmtTypeTraits::Type val) +template<> inline ALfloat LoadSample(DevFmtTypeTraits::Type val) noexcept { return val * (1.0f/128.0f); } -template<> inline ALfloat LoadSample(DevFmtTypeTraits::Type val) +template<> inline ALfloat LoadSample(DevFmtTypeTraits::Type val) noexcept { return val * (1.0f/32768.0f); } -template<> inline ALfloat LoadSample(DevFmtTypeTraits::Type val) +template<> inline ALfloat LoadSample(DevFmtTypeTraits::Type val) noexcept { return val * (1.0f/2147483648.0f); } -template<> inline ALfloat LoadSample(DevFmtTypeTraits::Type val) +template<> inline ALfloat LoadSample(DevFmtTypeTraits::Type val) noexcept { return val; } -template<> inline ALfloat LoadSample(DevFmtTypeTraits::Type val) +template<> inline ALfloat LoadSample(DevFmtTypeTraits::Type val) noexcept { return LoadSample(val - 128); } -template<> inline ALfloat LoadSample(DevFmtTypeTraits::Type val) -{ return LoadSample(val - 32768); } -template<> inline ALfloat LoadSample(DevFmtTypeTraits::Type val) -{ return LoadSample(val - 2147483648u); } +template<> inline ALfloat LoadSample(DevFmtTypeTraits::Type val) noexcept +{ return LoadSample(val - 32768); } +template<> inline ALfloat LoadSample(DevFmtTypeTraits::Type val) noexcept +{ return LoadSample(val - 2147483648u); } template -inline void LoadSampleArray(ALfloat *RESTRICT dst, const void *src, size_t srcstep, ALsizei samples) +inline void LoadSampleArray(ALfloat *RESTRICT dst, const void *src, const size_t srcstep, + const ALsizei samples) noexcept { using SampleType = typename DevFmtTypeTraits::Type; @@ -44,7 +45,8 @@ inline void LoadSampleArray(ALfloat *RESTRICT dst, const void *src, size_t srcst dst[i] = LoadSample(ssrc[i*srcstep]); } -void LoadSamples(ALfloat *dst, const ALvoid *src, size_t srcstep, DevFmtType srctype, ALsizei samples) +void LoadSamples(ALfloat *dst, const ALvoid *src, const size_t srcstep, const DevFmtType srctype, + const ALsizei samples) noexcept { #define HANDLE_FMT(T) \ case T: LoadSampleArray(dst, src, srcstep, samples); break @@ -63,28 +65,28 @@ void LoadSamples(ALfloat *dst, const ALvoid *src, size_t srcstep, DevFmtType src template -inline typename DevFmtTypeTraits::Type StoreSample(ALfloat); +inline typename DevFmtTypeTraits::Type StoreSample(ALfloat) noexcept; -template<> inline ALfloat StoreSample(ALfloat val) +template<> inline ALfloat StoreSample(ALfloat val) noexcept { return val; } -template<> inline ALint StoreSample(ALfloat val) +template<> inline ALint StoreSample(ALfloat val) noexcept { return fastf2i(clampf(val*2147483648.0f, -2147483648.0f, 2147483520.0f)); } -template<> inline ALshort StoreSample(ALfloat val) +template<> inline ALshort StoreSample(ALfloat val) noexcept { return fastf2i(clampf(val*32768.0f, -32768.0f, 32767.0f)); } -template<> inline ALbyte StoreSample(ALfloat val) +template<> inline ALbyte StoreSample(ALfloat val) noexcept { return fastf2i(clampf(val*128.0f, -128.0f, 127.0f)); } /* Define unsigned output variations. */ -template<> inline ALuint StoreSample(ALfloat val) +template<> inline ALuint StoreSample(ALfloat val) noexcept { return StoreSample(val) + 2147483648u; } -template<> inline ALushort StoreSample(ALfloat val) +template<> inline ALushort StoreSample(ALfloat val) noexcept { return StoreSample(val) + 32768; } -template<> inline ALubyte StoreSample(ALfloat val) +template<> inline ALubyte StoreSample(ALfloat val) noexcept { return StoreSample(val) + 128; } template -inline void StoreSampleArray(void *dst, const ALfloat *RESTRICT src, size_t dststep, - ALsizei samples) +inline void StoreSampleArray(void *dst, const ALfloat *RESTRICT src, const size_t dststep, + const ALsizei samples) noexcept { using SampleType = typename DevFmtTypeTraits::Type; @@ -94,7 +96,8 @@ inline void StoreSampleArray(void *dst, const ALfloat *RESTRICT src, size_t dsts } -void StoreSamples(ALvoid *dst, const ALfloat *src, size_t dststep, DevFmtType dsttype, ALsizei samples) +void StoreSamples(ALvoid *dst, const ALfloat *src, const size_t dststep, const DevFmtType dsttype, + const ALsizei samples) noexcept { #define HANDLE_FMT(T) \ case T: StoreSampleArray(dst, src, dststep, samples); break @@ -113,7 +116,7 @@ void StoreSamples(ALvoid *dst, const ALfloat *src, size_t dststep, DevFmtType ds template -void Mono2Stereo(ALfloat *RESTRICT dst, const void *src, ALsizei frames) +void Mono2Stereo(ALfloat *RESTRICT dst, const void *src, const ALsizei frames) noexcept { using SampleType = typename DevFmtTypeTraits::Type; @@ -123,7 +126,7 @@ void Mono2Stereo(ALfloat *RESTRICT dst, const void *src, ALsizei frames) } template -void Stereo2Mono(ALfloat *RESTRICT dst, const void *src, ALsizei frames) +void Stereo2Mono(ALfloat *RESTRICT dst, const void *src, const ALsizei frames) noexcept { using SampleType = typename DevFmtTypeTraits::Type; -- cgit v1.2.3