| 1 |
/* SPDX-License-Identifier: BSD-3-Clause */ |
| 2 |
/* SPDX-FileCopyrightText: OpenMPT Project Developers and Contributors */ |
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include "openmpt/all/BuildSettings.hpp" |
| 8 |
|
| 9 |
#include "mpt/base/macros.hpp" |
| 10 |
#include "openmpt/soundbase/MixSample.hpp" |
| 11 |
#include "openmpt/soundbase/SampleConvert.hpp" |
| 12 |
#include "openmpt/soundbase/SampleConvertFixedPoint.hpp" |
| 13 |
|
| 14 |
|
| 15 |
OPENMPT_NAMESPACE_BEGIN |
| 16 |
|
| 17 |
|
| 18 |
template <typename Tdst, typename Tsrc> |
| 19 |
struct ConvertMixSample; |
| 20 |
|
| 21 |
template <> |
| 22 |
struct ConvertMixSample<MixSampleInt, MixSampleInt> |
| 23 |
{ |
| 24 |
MPT_FORCEINLINE MixSampleInt conv(MixSampleInt src) |
| 25 |
{ |
| 26 |
return src; |
| 27 |
} |
| 28 |
}; |
| 29 |
|
| 30 |
template <> |
| 31 |
struct ConvertMixSample<MixSampleFloat, MixSampleFloat> |
| 32 |
{ |
| 33 |
MPT_FORCEINLINE MixSampleFloat conv(MixSampleFloat src) |
| 34 |
{ |
| 35 |
return src; |
| 36 |
} |
| 37 |
}; |
| 38 |
|
| 39 |
template <typename Tsrc> |
| 40 |
struct ConvertMixSample<MixSampleInt, Tsrc> |
| 41 |
{ |
| 42 |
MPT_FORCEINLINE MixSampleInt conv(Tsrc src) |
| 43 |
{ |
| 44 |
return SC::ConvertToFixedPoint<MixSampleInt, Tsrc, MixSampleIntTraits::mix_fractional_bits>{}(src); |
| 45 |
} |
| 46 |
}; |
| 47 |
|
| 48 |
template <typename Tdst> |
| 49 |
struct ConvertMixSample<Tdst, MixSampleInt> |
| 50 |
{ |
| 51 |
MPT_FORCEINLINE Tdst conv(MixSampleInt src) |
| 52 |
{ |
| 53 |
return SC::ConvertFixedPoint<Tdst, MixSampleInt, MixSampleIntTraits::mix_fractional_bits>{}(src); |
| 54 |
} |
| 55 |
}; |
| 56 |
|
| 57 |
template <typename Tsrc> |
| 58 |
struct ConvertMixSample<MixSampleFloat, Tsrc> |
| 59 |
{ |
| 60 |
MPT_FORCEINLINE MixSampleFloat conv(Tsrc src) |
| 61 |
{ |
| 62 |
return SC::Convert<MixSampleFloat, Tsrc>{}(src); |
| 63 |
} |
| 64 |
}; |
| 65 |
|
| 66 |
template <typename Tdst> |
| 67 |
struct ConvertMixSample<Tdst, MixSampleFloat> |
| 68 |
{ |
| 69 |
MPT_FORCEINLINE Tdst conv(MixSampleFloat src) |
| 70 |
{ |
| 71 |
return SC::Convert<Tdst, MixSampleFloat>{}(src); |
| 72 |
} |
| 73 |
}; |
| 74 |
|
| 75 |
template <> |
| 76 |
struct ConvertMixSample<MixSampleInt, MixSampleFloat> |
| 77 |
{ |
| 78 |
MPT_FORCEINLINE MixSampleInt conv(MixSampleFloat src) |
| 79 |
{ |
| 80 |
return SC::ConvertToFixedPoint<MixSampleInt, MixSampleFloat, MixSampleIntTraits::mix_fractional_bits>{}(src); |
| 81 |
} |
| 82 |
}; |
| 83 |
|
| 84 |
template <> |
| 85 |
struct ConvertMixSample<MixSampleFloat, MixSampleInt> |
| 86 |
{ |
| 87 |
MPT_FORCEINLINE MixSampleFloat conv(MixSampleInt src) |
| 88 |
{ |
| 89 |
return SC::ConvertFixedPoint<MixSampleFloat, MixSampleInt, MixSampleIntTraits::mix_fractional_bits>{}(src); |
| 90 |
} |
| 91 |
}; |
| 92 |
|
| 93 |
|
| 94 |
template <typename Tdst, typename Tsrc> |
| 95 |
MPT_FORCEINLINE Tdst mix_sample_cast(Tsrc src) |
| 96 |
{ |
| 97 |
return ConvertMixSample<Tdst, Tsrc>{}.conv(src); |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
OPENMPT_NAMESPACE_END |