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.
This commit is contained in:
Max Kellermann 2017-12-03 11:15:11 +01:00
parent 396defaea9
commit de90d401d2
3 changed files with 11 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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 {