#ifndef CORE_FMT_TRAITS_H #define CORE_FMT_TRAITS_H #include #include #include "albyte.h" #include "buffer_storage.h" namespace al { extern const int16_t muLawDecompressionTable[256]; extern const int16_t aLawDecompressionTable[256]; template struct FmtTypeTraits { }; template<> struct FmtTypeTraits { using Type = uint8_t; template static constexpr inline OutT to(const Type val) noexcept { return val*OutT{1.0/128.0} - OutT{1.0}; } }; template<> struct FmtTypeTraits { using Type = int16_t; template static constexpr inline OutT to(const Type val) noexcept { return val*OutT{1.0/32768.0}; } }; template<> struct FmtTypeTraits { using Type = float; template static constexpr inline OutT to(const Type val) noexcept { return val; } }; template<> struct FmtTypeTraits { using Type = double; template static constexpr inline OutT to(const Type val) noexcept { return static_cast(val); } }; template<> struct FmtTypeTraits { using Type = uint8_t; template static constexpr inline OutT to(const Type val) noexcept { return muLawDecompressionTable[val] * OutT{1.0/32768.0}; } }; template<> struct FmtTypeTraits { using Type = uint8_t; template static constexpr inline OutT to(const Type val) noexcept { return aLawDecompressionTable[val] * OutT{1.0/32768.0}; } }; template inline void LoadSampleArray(DstT *RESTRICT dst, const al::byte *src, const size_t srcstep, const size_t samples) noexcept { using TypeTraits = FmtTypeTraits; using SampleType = typename TypeTraits::Type; const SampleType *RESTRICT ssrc{reinterpret_cast(src)}; for(size_t i{0u};i < samples;i++) dst[i] = TypeTraits::template to(ssrc[i*srcstep]); } } // namespace al #endif /* CORE_FMT_TRAITS_H */