diff --git a/src/Partition.cxx b/src/Partition.cxx index f3027e05c..03de4d16a 100644 --- a/src/Partition.cxx +++ b/src/Partition.cxx @@ -23,6 +23,7 @@ #include "DetachedSong.hxx" #include "mixer/Volume.hxx" #include "IdleFlags.hxx" +#include "ReplayGainGlobal.hxx" Partition::Partition(Instance &_instance, unsigned max_length, @@ -50,6 +51,8 @@ Partition::UpdateEffectiveReplayGainMode(ReplayGainMode mode) ? ReplayGainMode::TRACK : ReplayGainMode::ALBUM; + pc.LockSetReplayGain(replay_gain_config, mode); + outputs.SetReplayGainMode(mode); } diff --git a/src/decoder/Bridge.cxx b/src/decoder/Bridge.cxx index 4bd5e5c8b..8e9941192 100644 --- a/src/decoder/Bridge.cxx +++ b/src/decoder/Bridge.cxx @@ -30,7 +30,6 @@ #include "pcm/PcmConvert.hxx" #include "tag/Tag.hxx" #include "AudioConfig.hxx" -#include "ReplayGainGlobal.hxx" #include "Log.hxx" #include "input/InputStream.hxx" #include "util/ConstBuffer.hxx" @@ -592,14 +591,14 @@ DecoderBridge::SubmitReplayGain(const ReplayGainInfo *new_replay_gain_info) if (++serial == 0) serial = 1; - if (ReplayGainMode::OFF != replay_gain_mode) { - ReplayGainMode rgm = replay_gain_mode; + if (ReplayGainMode::OFF != dc.replay_gain_mode) { + ReplayGainMode rgm = dc.replay_gain_mode; if (rgm != ReplayGainMode::ALBUM) rgm = ReplayGainMode::TRACK; const auto &tuple = new_replay_gain_info->Get(rgm); const auto scale = - tuple.CalculateScale(replay_gain_config); + tuple.CalculateScale(dc.replay_gain_config); dc.replay_gain_db = 20.0 * log10f(scale); } diff --git a/src/decoder/DecoderControl.hxx b/src/decoder/DecoderControl.hxx index 79bd119a7..7afd187e0 100644 --- a/src/decoder/DecoderControl.hxx +++ b/src/decoder/DecoderControl.hxx @@ -27,6 +27,8 @@ #include "thread/Cond.hxx" #include "thread/Thread.hxx" #include "Chrono.hxx" +#include "ReplayGainConfig.hxx" +#include "ReplayGainMode.hxx" #include @@ -156,6 +158,9 @@ struct DecoderControl { */ MusicPipe *pipe; + ReplayGainConfig replay_gain_config; + ReplayGainMode replay_gain_mode = ReplayGainMode::OFF; + float replay_gain_db = 0; float replay_gain_prev_db = 0; diff --git a/src/player/Control.hxx b/src/player/Control.hxx index 4af87e964..8ff9306a4 100644 --- a/src/player/Control.hxx +++ b/src/player/Control.hxx @@ -26,6 +26,8 @@ #include "thread/Thread.hxx" #include "CrossFade.hxx" #include "Chrono.hxx" +#include "ReplayGainConfig.hxx" +#include "ReplayGainMode.hxx" #include @@ -167,6 +169,9 @@ struct PlayerControl { CrossFadeSettings cross_fade; + ReplayGainConfig replay_gain_config; + ReplayGainMode replay_gain_mode = ReplayGainMode::OFF; + double total_play_time; /** @@ -463,6 +468,13 @@ public: return cross_fade.mixramp_delay; } + void LockSetReplayGain(const ReplayGainConfig &_config, + ReplayGainMode _mode) { + const ScopeLock protect(mutex); + replay_gain_config = _config; + replay_gain_mode = _mode; + } + double GetTotalPlayTime() const { return total_play_time; } diff --git a/src/player/Thread.cxx b/src/player/Thread.cxx index 8d45e2e2a..f26261aa5 100644 --- a/src/player/Thread.cxx +++ b/src/player/Thread.cxx @@ -342,6 +342,13 @@ Player::StartDecoder(MusicPipe &_pipe) assert(queued || pc.command == PlayerCommand::SEEK); assert(pc.next_song != nullptr); + { + /* copy ReplayGain parameters to the decoder */ + const ScopeLock protect(pc.mutex); + dc.replay_gain_config = pc.replay_gain_config; + dc.replay_gain_mode = pc.replay_gain_mode; + } + SongTime start_time = pc.next_song->GetStartTime() + pc.seek_time; dc.Start(new DetachedSong(*pc.next_song),