Commit 31268ad7 authored by Max Kellermann's avatar Max Kellermann

decoder/opus: fix track/album ReplayGain fallback

Fixes regression by commit 23d5a2b8 - that commit always pretended that any Opus file has both track and album gain, and thus disabled the fallback to the other if one is not set. This patch changes the logic to only submit ReplayGain if at least one value is set, and apply the offset only to that value. If none is available, then the new check in HandleAudio() will submit only the output gain. Closes https://github.com/MusicPlayerDaemon/MPD/issues/977
parent a0d43dd8
ver 0.22.1 (not yet released) ver 0.22.1 (not yet released)
* decoder * decoder
- opus: apply the OpusHead output gain even if there is no EBU R128 tag - opus: apply the OpusHead output gain even if there is no EBU R128 tag
- opus: fix track/album ReplayGain fallback
* output * output
- alsa: don't deadlock when the ALSA driver is buggy - alsa: don't deadlock when the ALSA driver is buggy
- jack, pulse: reduce the delay when stopping or pausing playback - jack, pulse: reduce the delay when stopping or pausing playback
......
...@@ -268,7 +268,6 @@ MPDOpusDecoder::HandleTags(const ogg_packet &packet) ...@@ -268,7 +268,6 @@ MPDOpusDecoder::HandleTags(const ogg_packet &packet)
{ {
ReplayGainInfo rgi; ReplayGainInfo rgi;
rgi.Clear(); rgi.Clear();
rgi.track.gain = rgi.album.gain = EbuR128ToReplayGain(output_gain);
TagBuilder tag_builder; TagBuilder tag_builder;
AddTagHandler h(tag_builder); AddTagHandler h(tag_builder);
...@@ -276,8 +275,16 @@ MPDOpusDecoder::HandleTags(const ogg_packet &packet) ...@@ -276,8 +275,16 @@ MPDOpusDecoder::HandleTags(const ogg_packet &packet)
if (!ScanOpusTags(packet.packet, packet.bytes, &rgi, h)) if (!ScanOpusTags(packet.packet, packet.bytes, &rgi, h))
return; return;
if (rgi.IsDefined()) {
/* submit all valid EBU R128 values with output_gain
applied */
if (rgi.track.IsDefined())
rgi.track.gain += EbuR128ToReplayGain(output_gain);
if (rgi.album.IsDefined())
rgi.album.gain += EbuR128ToReplayGain(output_gain);
client.SubmitReplayGain(&rgi); client.SubmitReplayGain(&rgi);
submitted_replay_gain = true; submitted_replay_gain = true;
}
if (!tag_builder.empty()) { if (!tag_builder.empty()) {
Tag tag = tag_builder.Commit(); Tag tag = tag_builder.Commit();
......
...@@ -61,7 +61,7 @@ ScanOneOpusTag(StringView name, StringView value, ...@@ -61,7 +61,7 @@ ScanOneOpusTag(StringView name, StringView value,
const char *endptr; const char *endptr;
const auto l = ParseInt64(value, &endptr, 10); const auto l = ParseInt64(value, &endptr, 10);
if (endptr > value.begin() && endptr == value.end()) if (endptr > value.begin() && endptr == value.end())
rgi->track.gain += float(l) / 256.0f; rgi->track.gain = float(l) / 256.0f;
} else if (rgi != nullptr && } else if (rgi != nullptr &&
name.EqualsIgnoreCase("R128_ALBUM_GAIN")) { name.EqualsIgnoreCase("R128_ALBUM_GAIN")) {
/* R128_ALBUM_GAIN is a Q7.8 fixed point number in /* R128_ALBUM_GAIN is a Q7.8 fixed point number in
...@@ -70,7 +70,7 @@ ScanOneOpusTag(StringView name, StringView value, ...@@ -70,7 +70,7 @@ ScanOneOpusTag(StringView name, StringView value,
const char *endptr; const char *endptr;
const auto l = ParseInt64(value, &endptr, 10); const auto l = ParseInt64(value, &endptr, 10);
if (endptr > value.begin() && endptr == value.end()) if (endptr > value.begin() && endptr == value.end())
rgi->album.gain += float(l) / 256.0f; rgi->album.gain = float(l) / 256.0f;
} }
handler.OnPair(name, value); handler.OnPair(name, value);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment