From 3bc9490fd2861bdb28951bae5af37500e93de7ad Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 4 Aug 2019 17:45:46 -0700 Subject: [PATCH] Move some structs to where they're used --- al/buffer.h | 17 --------------- alc/mixvoice.cpp | 57 +++++++++++++++++++++++++++++++----------------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/al/buffer.h b/al/buffer.h index e5149bb1..2c01aae2 100644 --- a/al/buffer.h +++ b/al/buffer.h @@ -63,23 +63,6 @@ enum FmtChannels : unsigned char { }; #define MAX_INPUT_CHANNELS (8) -/* DevFmtType traits, providing the type, etc given a DevFmtType. */ -template -struct FmtTypeTraits { }; - -template<> -struct FmtTypeTraits { using Type = ALubyte; }; -template<> -struct FmtTypeTraits { using Type = ALshort; }; -template<> -struct FmtTypeTraits { using Type = ALfloat; }; -template<> -struct FmtTypeTraits { using Type = ALdouble; }; -template<> -struct FmtTypeTraits { using Type = ALubyte; }; -template<> -struct FmtTypeTraits { using Type = ALubyte; }; - ALsizei BytesFromFmt(FmtType type); ALsizei ChannelsFromFmt(FmtChannels chans); diff --git a/alc/mixvoice.cpp b/alc/mixvoice.cpp index 8c54b706..0c644344 100644 --- a/alc/mixvoice.cpp +++ b/alc/mixvoice.cpp @@ -281,6 +281,42 @@ constexpr ALshort aLawDecompressionTable[256] = { 944, 912, 1008, 976, 816, 784, 880, 848 }; +template +struct FmtTypeTraits { }; + +template<> +struct FmtTypeTraits { + using Type = ALubyte; + static constexpr ALfloat to_float(const Type val) { return (val-128) * (1.0f/128.0f); } +}; +template<> +struct FmtTypeTraits { + using Type = ALshort; + static constexpr ALfloat to_float(const Type val) { return val * (1.0f/32768.0f); } +}; +template<> +struct FmtTypeTraits { + using Type = ALfloat; + static constexpr ALfloat to_float(const Type val) { return val; } +}; +template<> +struct FmtTypeTraits { + using Type = ALdouble; + static constexpr ALfloat to_float(const Type val) { return static_cast(val); } +}; +template<> +struct FmtTypeTraits { + using Type = ALubyte; + static constexpr ALfloat to_float(const Type val) + { return muLawDecompressionTable[val] * (1.0f/32768.0f); } +}; +template<> +struct FmtTypeTraits { + using Type = ALubyte; + static constexpr ALfloat to_float(const Type val) + { return aLawDecompressionTable[val] * (1.0f/32768.0f); } +}; + void SendSourceStoppedEvent(ALCcontext *context, ALuint id) { @@ -328,25 +364,6 @@ const ALfloat *DoFilters(BiquadFilter *lpfilter, BiquadFilter *hpfilter, ALfloat } -/* Base template left undefined. Should be marked =delete, but Clang 3.8.1 - * chokes on that given the inline specializations. - */ -template -inline ALfloat LoadSample(typename FmtTypeTraits::Type val); - -template<> inline ALfloat LoadSample(FmtTypeTraits::Type val) -{ return (val-128) * (1.0f/128.0f); } -template<> inline ALfloat LoadSample(FmtTypeTraits::Type val) -{ return val * (1.0f/32768.0f); } -template<> inline ALfloat LoadSample(FmtTypeTraits::Type val) -{ return val; } -template<> inline ALfloat LoadSample(FmtTypeTraits::Type val) -{ return static_cast(val); } -template<> inline ALfloat LoadSample(FmtTypeTraits::Type val) -{ return muLawDecompressionTable[val] * (1.0f/32768.0f); } -template<> inline ALfloat LoadSample(FmtTypeTraits::Type val) -{ return aLawDecompressionTable[val] * (1.0f/32768.0f); } - template inline void LoadSampleArray(ALfloat *RESTRICT dst, const al::byte *src, ALint srcstep, const ptrdiff_t samples) @@ -355,7 +372,7 @@ inline void LoadSampleArray(ALfloat *RESTRICT dst, const al::byte *src, ALint sr const SampleType *RESTRICT ssrc{reinterpret_cast(src)}; for(ALsizei i{0};i < samples;i++) - dst[i] += LoadSample(ssrc[i*srcstep]); + dst[i] += FmtTypeTraits::to_float(ssrc[i*srcstep]); } void LoadSamples(ALfloat *RESTRICT dst, const al::byte *src, ALint srcstep, FmtType srctype,