player/Thread: merge the cross_fading flag into enum CrossFadeState
This commit is contained in:
parent
9dc7b5a6d9
commit
e753c924ef
@ -111,12 +111,12 @@ class Player {
|
|||||||
* song.
|
* song.
|
||||||
*/
|
*/
|
||||||
ENABLED,
|
ENABLED,
|
||||||
} xfade_state;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* has cross-fading begun?
|
* Currently cross-fading to the next song.
|
||||||
*/
|
*/
|
||||||
bool cross_fading;
|
ACTIVE,
|
||||||
|
} xfade_state;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of chunks used for crossfading.
|
* The number of chunks used for crossfading.
|
||||||
@ -156,7 +156,6 @@ public:
|
|||||||
output_open(false),
|
output_open(false),
|
||||||
song(nullptr),
|
song(nullptr),
|
||||||
xfade_state(CrossFadeState::UNKNOWN),
|
xfade_state(CrossFadeState::UNKNOWN),
|
||||||
cross_fading(false),
|
|
||||||
cross_fade_chunks(0),
|
cross_fade_chunks(0),
|
||||||
cross_fade_tag(nullptr),
|
cross_fade_tag(nullptr),
|
||||||
elapsed_time(SongTime::zero()) {}
|
elapsed_time(SongTime::zero()) {}
|
||||||
@ -784,22 +783,27 @@ Player::PlayNextChunk()
|
|||||||
another chunk */
|
another chunk */
|
||||||
return true;
|
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;
|
MusicChunk *chunk = nullptr;
|
||||||
if (xfade_state == CrossFadeState::ENABLED && IsDecoderAtNextSong() &&
|
if (xfade_state == CrossFadeState::ACTIVE) {
|
||||||
(cross_fade_position = pipe->GetSize()) <= cross_fade_chunks) {
|
|
||||||
/* perform cross fade */
|
/* perform cross fade */
|
||||||
|
|
||||||
|
assert(IsDecoderAtNextSong());
|
||||||
|
|
||||||
|
unsigned cross_fade_position = pipe->GetSize();
|
||||||
|
assert(cross_fade_position <= cross_fade_chunks);
|
||||||
|
|
||||||
MusicChunk *other_chunk = dc.pipe->Shift();
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (other_chunk != nullptr) {
|
if (other_chunk != nullptr) {
|
||||||
chunk = pipe->Shift();
|
chunk = pipe->Shift();
|
||||||
assert(chunk != nullptr);
|
assert(chunk != nullptr);
|
||||||
@ -862,7 +866,7 @@ Player::PlayNextChunk()
|
|||||||
|
|
||||||
/* insert the postponed tag if cross-fading is finished */
|
/* 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);
|
chunk->tag = Tag::MergeReplace(chunk->tag, cross_fade_tag);
|
||||||
cross_fade_tag = nullptr;
|
cross_fade_tag = nullptr;
|
||||||
}
|
}
|
||||||
@ -1042,10 +1046,9 @@ Player::Run()
|
|||||||
play_audio_format,
|
play_audio_format,
|
||||||
buffer.GetSize() -
|
buffer.GetSize() -
|
||||||
pc.buffered_before_play);
|
pc.buffered_before_play);
|
||||||
if (cross_fade_chunks > 0) {
|
if (cross_fade_chunks > 0)
|
||||||
xfade_state = CrossFadeState::ENABLED;
|
xfade_state = CrossFadeState::ENABLED;
|
||||||
cross_fading = false;
|
else
|
||||||
} else
|
|
||||||
/* cross fading is disabled or the
|
/* cross fading is disabled or the
|
||||||
next song is too short */
|
next song is too short */
|
||||||
xfade_state = CrossFadeState::DISABLED;
|
xfade_state = CrossFadeState::DISABLED;
|
||||||
|
Loading…
Reference in New Issue
Block a user