PlayerControl: move attributes to struct CrossFadeSettings

This commit is contained in:
Max Kellermann 2013-10-29 00:14:27 +01:00
parent 095c390df7
commit 03747ba93e
5 changed files with 74 additions and 64 deletions

View File

@ -87,13 +87,12 @@ mixramp_interpolate(const char *ramp_list, float required_db)
}
unsigned
cross_fade_calc(float duration, float total_time,
float mixramp_db, float mixramp_delay,
CrossFadeSettings::Calculate(float total_time,
float replay_gain_db, float replay_gain_prev_db,
const char *mixramp_start, const char *mixramp_prev_end,
const AudioFormat af,
const AudioFormat old_format,
unsigned max_chunks)
unsigned max_chunks) const
{
unsigned int chunks = 0;
float chunks_f;

View File

@ -22,8 +22,29 @@
#include "Compiler.h"
#include <cmath>
struct AudioFormat;
struct music_chunk;
struct CrossFadeSettings {
/**
* The configured cross fade duration [s].
*/
float duration;
float mixramp_db;
/**
* The configured MixRapm delay [s].
*/
float mixramp_delay;
CrossFadeSettings()
:duration(0),
mixramp_db(0),
mixramp_delay(std::nanf(""))
{}
/**
* Calculate how many music pipe chunks should be used for crossfading.
@ -43,12 +64,12 @@ struct music_chunk;
* should be disabled for this song change
*/
gcc_pure
unsigned
cross_fade_calc(float duration, float total_time,
float mixramp_db, float mixramp_delay,
unsigned Calculate(float total_time,
float replay_gain_db, float replay_gain_prev_db,
const char *mixramp_start, const char *mixramp_prev_end,
const char *mixramp_start,
const char *mixramp_prev_end,
AudioFormat af, AudioFormat old_format,
unsigned max_chunks);
unsigned max_chunks) const;
};
#endif

View File

@ -36,15 +36,6 @@ PlayerControl::PlayerControl(unsigned _buffer_chunks,
error_type(PlayerError::NONE),
tagged_song(nullptr),
next_song(nullptr),
cross_fade_seconds(0),
mixramp_db(0),
#if defined(__GLIBCXX__) && !defined(_GLIBCXX_USE_C99_MATH_TR1)
/* workaround: on MacPorts, this option is disabled on gcc47,
and therefore std::nanf() is not available */
mixramp_delay_seconds(nanf("")),
#else
mixramp_delay_seconds(std::nanf("")),
#endif
total_play_time(0),
border_pause(false)
{
@ -260,7 +251,7 @@ PlayerControl::SetCrossFade(float _cross_fade_seconds)
{
if (_cross_fade_seconds < 0)
_cross_fade_seconds = 0;
cross_fade_seconds = _cross_fade_seconds;
cross_fade.duration = _cross_fade_seconds;
idle_add(IDLE_OPTIONS);
}
@ -268,7 +259,7 @@ PlayerControl::SetCrossFade(float _cross_fade_seconds)
void
PlayerControl::SetMixRampDb(float _mixramp_db)
{
mixramp_db = _mixramp_db;
cross_fade.mixramp_db = _mixramp_db;
idle_add(IDLE_OPTIONS);
}
@ -276,7 +267,7 @@ PlayerControl::SetMixRampDb(float _mixramp_db)
void
PlayerControl::SetMixRampDelay(float _mixramp_delay_seconds)
{
mixramp_delay_seconds = _mixramp_delay_seconds;
cross_fade.mixramp_delay = _mixramp_delay_seconds;
idle_add(IDLE_OPTIONS);
}

View File

@ -25,6 +25,7 @@
#include "thread/Cond.hxx"
#include "thread/Thread.hxx"
#include "util/Error.hxx"
#include "CrossFade.hxx"
#include <stdint.h>
@ -155,9 +156,9 @@ struct PlayerControl {
Song *next_song;
double seek_where;
float cross_fade_seconds;
float mixramp_db;
float mixramp_delay_seconds;
CrossFadeSettings cross_fade;
double total_play_time;
/**
@ -430,19 +431,19 @@ public:
void SetCrossFade(float cross_fade_seconds);
float GetCrossFade() const {
return cross_fade_seconds;
return cross_fade.duration;
}
void SetMixRampDb(float mixramp_db);
float GetMixRampDb() const {
return mixramp_db;
return cross_fade.mixramp_db;
}
void SetMixRampDelay(float mixramp_delay_seconds);
float GetMixRampDelay() const {
return mixramp_delay_seconds;
return cross_fade.mixramp_delay;
}
double GetTotalPlayTime() const {

View File

@ -779,7 +779,7 @@ Player::PlayNextChunk()
other_chunk->tag);
other_chunk->tag = nullptr;
if (std::isnan(pc.mixramp_delay_seconds)) {
if (std::isnan(pc.cross_fade.mixramp_delay)) {
chunk->mix_ratio = ((float)cross_fade_position)
/ cross_fade_chunks;
} else {
@ -999,9 +999,7 @@ Player::Run()
calculate how many chunks will be required
for it */
cross_fade_chunks =
cross_fade_calc(pc.cross_fade_seconds, dc.total_time,
pc.mixramp_db,
pc.mixramp_delay_seconds,
pc.cross_fade.Calculate(dc.total_time,
dc.replay_gain_db,
dc.replay_gain_prev_db,
dc.GetMixRampStart(),