Set the MacroFXFactor default
[openal-soft.git] / core / fmt_traits.h
blobf797f836ffa2df15d22b55207e90200a77515846
1 #ifndef CORE_FMT_TRAITS_H
2 #define CORE_FMT_TRAITS_H
4 #include <stddef.h>
5 #include <stdint.h>
7 #include "albyte.h"
8 #include "buffer_storage.h"
11 namespace al {
13 extern const int16_t muLawDecompressionTable[256];
14 extern const int16_t aLawDecompressionTable[256];
17 template<FmtType T>
18 struct FmtTypeTraits { };
20 template<>
21 struct FmtTypeTraits<FmtUByte> {
22 using Type = uint8_t;
24 template<typename OutT>
25 static constexpr inline OutT to(const Type val) noexcept
26 { return val*OutT{1.0/128.0} - OutT{1.0}; }
28 template<>
29 struct FmtTypeTraits<FmtShort> {
30 using Type = int16_t;
32 template<typename OutT>
33 static constexpr inline OutT to(const Type val) noexcept { return val*OutT{1.0/32768.0}; }
35 template<>
36 struct FmtTypeTraits<FmtFloat> {
37 using Type = float;
39 template<typename OutT>
40 static constexpr inline OutT to(const Type val) noexcept { return val; }
42 template<>
43 struct FmtTypeTraits<FmtDouble> {
44 using Type = double;
46 template<typename OutT>
47 static constexpr inline OutT to(const Type val) noexcept { return static_cast<OutT>(val); }
49 template<>
50 struct FmtTypeTraits<FmtMulaw> {
51 using Type = uint8_t;
53 template<typename OutT>
54 static constexpr inline OutT to(const Type val) noexcept
55 { return muLawDecompressionTable[val] * OutT{1.0/32768.0}; }
57 template<>
58 struct FmtTypeTraits<FmtAlaw> {
59 using Type = uint8_t;
61 template<typename OutT>
62 static constexpr inline OutT to(const Type val) noexcept
63 { return aLawDecompressionTable[val] * OutT{1.0/32768.0}; }
67 template<FmtType SrcType, typename DstT>
68 inline void LoadSampleArray(DstT *RESTRICT dst, const al::byte *src, const size_t srcstep,
69 const size_t samples) noexcept
71 using TypeTraits = FmtTypeTraits<SrcType>;
72 using SampleType = typename TypeTraits::Type;
74 const SampleType *RESTRICT ssrc{reinterpret_cast<const SampleType*>(src)};
75 for(size_t i{0u};i < samples;i++)
76 dst[i] = TypeTraits::template to<DstT>(ssrc[i*srcstep]);
79 } // namespace al
81 #endif /* CORE_FMT_TRAITS_H */