From 864d6f312d30ea3ae145d901d245f90c8bd11185 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 5 Aug 2019 13:06:33 +0200 Subject: [PATCH] Revert "decoder/mad: use MAD_F_MIN and MAD_F_MAX" This reverts commit f7ed7446ae4be9226de554d6d75a14a9fb71dd7c. It was a bad idea, because MAD_F_MIN and MAD_F_MAX do not represent the clamping limits, but the theoretical minimum and maximum values of the mad_fixed_t data type. Closes https://github.com/MusicPlayerDaemon/MPD/issues/617 --- NEWS | 2 ++ src/decoder/plugins/MadDecoderPlugin.cxx | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index fb4034a1f..34b6c0a00 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,6 @@ ver 0.21.13 (not yet released) +* decoder + - mad: fix crackling sound (0.21.12 regression) ver 0.21.12 (2019/08/03) * decoder diff --git a/src/decoder/plugins/MadDecoderPlugin.cxx b/src/decoder/plugins/MadDecoderPlugin.cxx index 1e357fd81..66cf8fb96 100644 --- a/src/decoder/plugins/MadDecoderPlugin.cxx +++ b/src/decoder/plugins/MadDecoderPlugin.cxx @@ -79,12 +79,14 @@ static inline int32_t mad_fixed_to_24_sample(mad_fixed_t sample) noexcept { static constexpr unsigned bits = 24; + static constexpr mad_fixed_t MIN = -MAD_F_ONE; + static constexpr mad_fixed_t MAX = MAD_F_ONE - 1; /* round */ sample = sample + (1L << (MAD_F_FRACBITS - bits)); /* quantize */ - return Clamp(sample, MAD_F_MIN, MAD_F_MAX) + return Clamp(sample, MIN, MAX) >> (MAD_F_FRACBITS + 1 - bits); }