diff options
Diffstat (limited to 'src/pcm/PcmDither.cxx')
-rw-r--r-- | src/pcm/PcmDither.cxx | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/pcm/PcmDither.cxx b/src/pcm/PcmDither.cxx index f07d0b343..d9d4d28ca 100644 --- a/src/pcm/PcmDither.cxx +++ b/src/pcm/PcmDither.cxx @@ -62,6 +62,19 @@ PcmDither::Dither(T sample) return output >> scale_bits; } +template<typename ST, unsigned SBITS, unsigned DBITS> +inline ST +PcmDither::DitherShift(ST sample) +{ + static_assert(sizeof(ST) * 8 > SBITS, "Source type too small"); + static_assert(SBITS > DBITS, "Non-positive scale_bits"); + + static constexpr ST MIN = -(ST(1) << (SBITS - 1)); + static constexpr ST MAX = (ST(1) << (SBITS - 1)) - 1; + + return Dither<ST, MIN, MAX, SBITS - DBITS>(sample); +} + template<typename ST, typename DT> inline typename DT::value_type PcmDither::DitherConvert(typename ST::value_type sample) |