summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2019-09-13 19:41:54 +0200
committerMax Kellermann <max@musicpd.org>2019-09-13 19:52:11 +0200
commit92495d2b0b33a1088e41f03597ba4ad596ae4e50 (patch)
tree9a42b149a379fde0d27ee3bf12975514c2e46653
parent9270829b5b8c02e2e3dba1d3cc41d983616f68d1 (diff)
decoder/mpcdec: fix bogus ReplayGain values
Apparently, libmpcdec sets gain/peak variables to zero if they are not present. This clashes with our formula and results in bogus values which cause noise during playback. Closes https://github.com/MusicPlayerDaemon/MPD/issues/640
-rw-r--r--NEWS1
-rw-r--r--src/decoder/plugins/MpcdecDecoderPlugin.cxx11
2 files changed, 9 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index 057dba43c..a509c8e13 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
ver 0.21.15 (not yet released)
* decoder
- dsdiff, dsf: fix displayed bit rate
+ - mpcdec: fix bogus ReplayGain values
* output
- solaris: fix build with glibc 2.30
diff --git a/src/decoder/plugins/MpcdecDecoderPlugin.cxx b/src/decoder/plugins/MpcdecDecoderPlugin.cxx
index f7f0870fd..68ecc115d 100644
--- a/src/decoder/plugins/MpcdecDecoderPlugin.cxx
+++ b/src/decoder/plugins/MpcdecDecoderPlugin.cxx
@@ -141,8 +141,12 @@ static constexpr ReplayGainTuple
ImportMpcdecReplayGain(mpc_uint16_t gain, mpc_uint16_t peak) noexcept
{
auto t = ReplayGainTuple::Undefined();
- t.gain = MPC_OLD_GAIN_REF - (gain / 256.);
- t.peak = pow(10, peak / 256. / 20) / 32767;
+
+ if (gain != 0 && peak != 0) {
+ t.gain = MPC_OLD_GAIN_REF - (gain / 256.);
+ t.peak = pow(10, peak / 256. / 20) / 32767;
+ }
+
return t;
}
@@ -187,7 +191,8 @@ mpcdec_decode(DecoderClient &client, InputStream &is)
{
const auto rgi = ImportMpcdecReplayGain(info);
- client.SubmitReplayGain(&rgi);
+ if (rgi.IsDefined())
+ client.SubmitReplayGain(&rgi);
}
client.Ready(audio_format, is.IsSeekable(),