diff options
author | Max Kellermann <max@duempel.org> | 2015-10-27 21:02:53 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-10-27 22:43:46 +0100 |
commit | e753c924ef7770a6f65cf2cb86a2b403707d62f3 (patch) | |
tree | f5fd558b538bed19d800c6ea3366bbba65972d60 | |
parent | 9dc7b5a6d99b6a7bc691663cee7d5748489d3d62 (diff) | |
download | mpd-e753c924ef7770a6f65cf2cb86a2b403707d62f3.tar.gz mpd-e753c924ef7770a6f65cf2cb86a2b403707d62f3.tar.xz mpd-e753c924ef7770a6f65cf2cb86a2b403707d62f3.zip |
player/Thread: merge the cross_fading flag into enum CrossFadeState
-rw-r--r-- | src/player/Thread.cxx | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/src/player/Thread.cxx b/src/player/Thread.cxx index a89724ae8..9358dc1f5 100644 --- a/src/player/Thread.cxx +++ b/src/player/Thread.cxx @@ -111,12 +111,12 @@ class Player { * song. */ ENABLED, - } xfade_state; - /** - * has cross-fading begun? - */ - bool cross_fading; + /** + * Currently cross-fading to the next song. + */ + ACTIVE, + } xfade_state; /** * The number of chunks used for crossfading. @@ -156,7 +156,6 @@ public: output_open(false), song(nullptr), xfade_state(CrossFadeState::UNKNOWN), - cross_fading(false), cross_fade_chunks(0), cross_fade_tag(nullptr), elapsed_time(SongTime::zero()) {} @@ -784,22 +783,27 @@ Player::PlayNextChunk() another chunk */ return true; - unsigned cross_fade_position; + /* activate cross-fading? */ + if (xfade_state == CrossFadeState::ENABLED && + IsDecoderAtNextSong() && + pipe->GetSize() <= cross_fade_chunks) { + /* beginning of the cross fade - adjust + cross_fade_chunks which might be bigger than the + remaining number of chunks in the old song */ + cross_fade_chunks = pipe->GetSize(); + xfade_state = CrossFadeState::ACTIVE; + } + MusicChunk *chunk = nullptr; - if (xfade_state == CrossFadeState::ENABLED && IsDecoderAtNextSong() && - (cross_fade_position = pipe->GetSize()) <= cross_fade_chunks) { + if (xfade_state == CrossFadeState::ACTIVE) { /* perform cross fade */ - MusicChunk *other_chunk = dc.pipe->Shift(); - if (!cross_fading) { - /* beginning of the cross fade - adjust - crossFadeChunks which might be bigger than - the remaining number of chunks in the old - song */ - cross_fade_chunks = cross_fade_position; - cross_fading = true; - } + assert(IsDecoderAtNextSong()); + + unsigned cross_fade_position = pipe->GetSize(); + assert(cross_fade_position <= cross_fade_chunks); + MusicChunk *other_chunk = dc.pipe->Shift(); if (other_chunk != nullptr) { chunk = pipe->Shift(); assert(chunk != nullptr); @@ -862,7 +866,7 @@ Player::PlayNextChunk() /* insert the postponed tag if cross-fading is finished */ - if (xfade_state != CrossFadeState::ENABLED && cross_fade_tag != nullptr) { + if (xfade_state != CrossFadeState::ACTIVE && cross_fade_tag != nullptr) { chunk->tag = Tag::MergeReplace(chunk->tag, cross_fade_tag); cross_fade_tag = nullptr; } @@ -1042,10 +1046,9 @@ Player::Run() play_audio_format, buffer.GetSize() - pc.buffered_before_play); - if (cross_fade_chunks > 0) { + if (cross_fade_chunks > 0) xfade_state = CrossFadeState::ENABLED; - cross_fading = false; - } else + else /* cross fading is disabled or the next song is too short */ xfade_state = CrossFadeState::DISABLED; |