From de90d401d290f69fb19bd1f8124ce43fcb932dc0 Mon Sep 17 00:00:00 2001 From: Max Kellermann <max@musicpd.org> Date: Sun, 3 Dec 2017 11:15:11 +0100 Subject: [PATCH] MusicChunk: add magic value IGNORE_REPLAY_GAIN This fixes spurious replay gain logs when the player inserts silence chunks, because those silence chunks had no replay gain attached, resetting the ReplayGainFilter state, flipping it forth and back. --- src/MusicChunk.hxx | 8 ++++++++ src/output/Source.cxx | 3 ++- src/player/Thread.cxx | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/MusicChunk.hxx b/src/MusicChunk.hxx index 54c0c7753..a730a0b2d 100644 --- a/src/MusicChunk.hxx +++ b/src/MusicChunk.hxx @@ -79,6 +79,14 @@ struct MusicChunk { */ ReplayGainInfo replay_gain_info; + /** + * A magic value for #replay_gain_serial which omits updating + * the #ReplayGainFilter. This is used by "silence" chunks + * (see PlayerThread::SendSilence()) so they don't affect the + * replay gain. + */ + static constexpr unsigned IGNORE_REPLAY_GAIN = ~0u; + /** * A serial number for checking if replay gain info has * changed since the last chunk. The magic value 0 indicates diff --git a/src/output/Source.cxx b/src/output/Source.cxx index de11595f5..73266687c 100644 --- a/src/output/Source.cxx +++ b/src/output/Source.cxx @@ -142,7 +142,8 @@ AudioOutputSource::GetChunkData(const MusicChunk &chunk, replay_gain_filter_set_mode(*replay_gain_filter, replay_gain_mode); - if (chunk.replay_gain_serial != *replay_gain_serial_p) { + if (chunk.replay_gain_serial != *replay_gain_serial_p && + chunk.replay_gain_serial != MusicChunk::IGNORE_REPLAY_GAIN) { replay_gain_filter_set_info(*replay_gain_filter, chunk.replay_gain_serial != 0 ? &chunk.replay_gain_info diff --git a/src/player/Thread.cxx b/src/player/Thread.cxx index be34d8af9..913e541e1 100644 --- a/src/player/Thread.cxx +++ b/src/player/Thread.cxx @@ -561,7 +561,7 @@ Player::SendSilence() chunk->bit_rate = 0; chunk->time = SignedSongTime::Negative(); /* undefined time stamp */ chunk->length = num_frames * frame_size; - chunk->replay_gain_serial = 0; + chunk->replay_gain_serial = MusicChunk::IGNORE_REPLAY_GAIN; PcmSilence({chunk->data, chunk->length}, play_audio_format.format); try {