1 #ifndef CORE_FMT_TRAITS_H
2 #define CORE_FMT_TRAITS_H
8 #include "buffer_storage.h"
13 extern const int16_t muLawDecompressionTable
[256];
14 extern const int16_t aLawDecompressionTable
[256];
18 struct FmtTypeTraits
{ };
21 struct FmtTypeTraits
<FmtUByte
> {
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}; }
29 struct FmtTypeTraits
<FmtShort
> {
32 template<typename OutT
>
33 static constexpr inline OutT
to(const Type val
) noexcept
{ return val
*OutT
{1.0/32768.0}; }
36 struct FmtTypeTraits
<FmtFloat
> {
39 template<typename OutT
>
40 static constexpr inline OutT
to(const Type val
) noexcept
{ return val
; }
43 struct FmtTypeTraits
<FmtDouble
> {
46 template<typename OutT
>
47 static constexpr inline OutT
to(const Type val
) noexcept
{ return static_cast<OutT
>(val
); }
50 struct FmtTypeTraits
<FmtMulaw
> {
53 template<typename OutT
>
54 static constexpr inline OutT
to(const Type val
) noexcept
55 { return muLawDecompressionTable
[val
] * OutT
{1.0/32768.0}; }
58 struct FmtTypeTraits
<FmtAlaw
> {
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
]);
81 #endif /* CORE_FMT_TRAITS_H */