diff options
author | Max Kellermann <max@duempel.org> | 2013-12-22 17:39:26 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-12-28 18:30:24 +0100 |
commit | afcf0795c44260f54e74ec854297de439e7562c3 (patch) | |
tree | f4ec95c5d889d81ec840f83f105a03625f663cb6 /src/pcm/PcmDither.cxx | |
parent | 394e2815dbaf0edb8d0f34b6ceab96b58f071ea8 (diff) | |
download | mpd-afcf0795c44260f54e74ec854297de439e7562c3.tar.gz mpd-afcf0795c44260f54e74ec854297de439e7562c3.tar.xz mpd-afcf0795c44260f54e74ec854297de439e7562c3.zip |
pcm/Volume: improved dithering
Instead of just adding a rectangular random value before shifting back
to the normal scale, use the existing PcmDither library.
Diffstat (limited to '')
-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) |