1 #ifndef CORE_FMT_TRAITS_H
2 #define CORE_FMT_TRAITS_H
7 #include "storage_formats.h"
12 extern const std::array
<std::int16_t,256> muLawDecompressionTable
;
13 extern const std::array
<std::int16_t,256> aLawDecompressionTable
;
17 struct FmtTypeTraits
{ };
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
; }
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
); }
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
); }
41 struct FmtTypeTraits
<FmtFloat
> {
44 constexpr float operator()(const Type val
) const noexcept
{ return val
; }
47 struct FmtTypeTraits
<FmtDouble
> {
50 constexpr float operator()(const Type val
) const noexcept
{ return static_cast<float>(val
); }
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
); }
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
); }
69 #endif /* CORE_FMT_TRAITS_H */