Recogmize jack64 for finding the JACK library name
[openal-soft.git] / core / fmt_traits.h
blobe87ea57cedecfe9f28e6d0d4ecbca3d60e69eeed
1 #ifndef CORE_FMT_TRAITS_H
2 #define CORE_FMT_TRAITS_H
4 #include <array>
5 #include <cstdint>
7 #include "storage_formats.h"
10 namespace al {
12 extern const std::array<std::int16_t,256> muLawDecompressionTable;
13 extern const std::array<std::int16_t,256> aLawDecompressionTable;
16 template<FmtType T>
17 struct FmtTypeTraits { };
19 template<>
20 struct FmtTypeTraits<FmtUByte> {
21 using Type = std::uint8_t;
23 constexpr float operator()(const Type val) const noexcept
24 { return float(val)*(1.0f/128.0f) - 1.0f; }
26 template<>
27 struct FmtTypeTraits<FmtShort> {
28 using Type = std::int16_t;
30 constexpr float operator()(const Type val) const noexcept
31 { return float(val) * (1.0f/32768.0f); }
33 template<>
34 struct FmtTypeTraits<FmtInt> {
35 using Type = std::int32_t;
37 constexpr float operator()(const Type val) const noexcept
38 { return static_cast<float>(val)*(1.0f/2147483648.0f); }
40 template<>
41 struct FmtTypeTraits<FmtFloat> {
42 using Type = float;
44 constexpr float operator()(const Type val) const noexcept { return val; }
46 template<>
47 struct FmtTypeTraits<FmtDouble> {
48 using Type = double;
50 constexpr float operator()(const Type val) const noexcept { return static_cast<float>(val); }
52 template<>
53 struct FmtTypeTraits<FmtMulaw> {
54 using Type = std::uint8_t;
56 constexpr float operator()(const Type val) const noexcept
57 { return float(muLawDecompressionTable[val]) * (1.0f/32768.0f); }
59 template<>
60 struct FmtTypeTraits<FmtAlaw> {
61 using Type = std::uint8_t;
63 constexpr float operator()(const Type val) const noexcept
64 { return float(aLawDecompressionTable[val]) * (1.0f/32768.0f); }
67 } // namespace al
69 #endif /* CORE_FMT_TRAITS_H */