replay_gain: added function defined()
This function determines whether replay gain data is available.
This commit is contained in:
parent
f4e9275f7c
commit
eeef501ed8
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
enum replay_gain_mode {
|
enum replay_gain_mode {
|
||||||
REPLAY_GAIN_OFF = -1,
|
REPLAY_GAIN_OFF = -1,
|
||||||
REPLAY_GAIN_ALBUM,
|
REPLAY_GAIN_ALBUM,
|
||||||
@ -49,4 +51,10 @@ replay_gain_info_dup(const struct replay_gain_info *src);
|
|||||||
void
|
void
|
||||||
replay_gain_info_free(struct replay_gain_info *info);
|
replay_gain_info_free(struct replay_gain_info *info);
|
||||||
|
|
||||||
|
static inline bool
|
||||||
|
replay_gain_tuple_defined(const struct replay_gain_tuple *tuple)
|
||||||
|
{
|
||||||
|
return tuple->gain > 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -42,7 +42,7 @@ replay_gain_state_new(float preamp, float missing_preamp)
|
|||||||
struct replay_gain_state *state = g_new(struct replay_gain_state, 1);
|
struct replay_gain_state *state = g_new(struct replay_gain_state, 1);
|
||||||
|
|
||||||
state->preamp = preamp;
|
state->preamp = preamp;
|
||||||
state->missing_preamp = missing_preamp;
|
state->scale = state->missing_preamp = missing_preamp;
|
||||||
state->mode = REPLAY_GAIN_OFF;
|
state->mode = REPLAY_GAIN_OFF;
|
||||||
state->info = NULL;
|
state->info = NULL;
|
||||||
|
|
||||||
@ -65,8 +65,6 @@ calc_replay_gain_scale(float gain, float peak, float preamp)
|
|||||||
{
|
{
|
||||||
float scale;
|
float scale;
|
||||||
|
|
||||||
if (gain == 0.0)
|
|
||||||
return (1);
|
|
||||||
scale = pow(10.0, gain / 20.0);
|
scale = pow(10.0, gain / 20.0);
|
||||||
scale *= preamp;
|
scale *= preamp;
|
||||||
if (scale > 15.0)
|
if (scale > 15.0)
|
||||||
@ -88,12 +86,14 @@ replay_gain_state_calc_scale(struct replay_gain_state *state)
|
|||||||
|
|
||||||
const struct replay_gain_tuple *tuple =
|
const struct replay_gain_tuple *tuple =
|
||||||
&state->info->tuples[state->mode];
|
&state->info->tuples[state->mode];
|
||||||
|
if (replay_gain_tuple_defined(tuple)) {
|
||||||
|
g_debug("computing ReplayGain scale with gain %f, peak %f",
|
||||||
|
tuple->gain, tuple->peak);
|
||||||
|
|
||||||
g_debug("computing ReplayGain scale with gain %f, peak %f",
|
state->scale = calc_replay_gain_scale(tuple->gain, tuple->peak,
|
||||||
tuple->gain, tuple->peak);
|
state->preamp);
|
||||||
|
} else
|
||||||
state->scale = calc_replay_gain_scale(tuple->gain, tuple->peak,
|
state->scale = state->missing_preamp;
|
||||||
state->preamp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -136,7 +136,5 @@ replay_gain_state_apply(const struct replay_gain_state *state,
|
|||||||
if (state->mode == REPLAY_GAIN_OFF)
|
if (state->mode == REPLAY_GAIN_OFF)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float scale = state->info != NULL
|
pcm_volume(buffer, size, format, pcm_float_to_volume(state->scale));
|
||||||
? state->scale : state->missing_preamp;
|
|
||||||
pcm_volume(buffer, size, format, pcm_float_to_volume(scale));
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user