diff options
author | Max Kellermann <max@duempel.org> | 2010-02-15 14:36:05 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2010-02-15 19:09:24 +0100 |
commit | eeef501ed865b4ef9e0c971829a39a98c7b81ee9 (patch) | |
tree | 89e5df10c0b123ed75d73f47ad3ffac84ba8ada1 /src/replay_gain_state.c | |
parent | f4e9275f7c2f6b304aa3b2d3c83ee4ad1cf6ed95 (diff) | |
download | mpd-eeef501ed865b4ef9e0c971829a39a98c7b81ee9.tar.gz mpd-eeef501ed865b4ef9e0c971829a39a98c7b81ee9.tar.xz mpd-eeef501ed865b4ef9e0c971829a39a98c7b81ee9.zip |
replay_gain: added function defined()
This function determines whether replay gain data is available.
Diffstat (limited to 'src/replay_gain_state.c')
-rw-r--r-- | src/replay_gain_state.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/replay_gain_state.c b/src/replay_gain_state.c index c14ff6e10..db77dc1e9 100644 --- a/src/replay_gain_state.c +++ b/src/replay_gain_state.c @@ -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); state->preamp = preamp; - state->missing_preamp = missing_preamp; + state->scale = state->missing_preamp = missing_preamp; state->mode = REPLAY_GAIN_OFF; state->info = NULL; @@ -65,8 +65,6 @@ calc_replay_gain_scale(float gain, float peak, float preamp) { float scale; - if (gain == 0.0) - return (1); scale = pow(10.0, gain / 20.0); scale *= preamp; if (scale > 15.0) @@ -88,12 +86,14 @@ replay_gain_state_calc_scale(struct replay_gain_state *state) const struct replay_gain_tuple *tuple = &state->info->tuples[state->mode]; - - g_debug("computing ReplayGain scale with gain %f, peak %f", - tuple->gain, tuple->peak); - - state->scale = calc_replay_gain_scale(tuple->gain, tuple->peak, - state->preamp); + if (replay_gain_tuple_defined(tuple)) { + g_debug("computing ReplayGain scale with gain %f, peak %f", + tuple->gain, tuple->peak); + + state->scale = calc_replay_gain_scale(tuple->gain, tuple->peak, + state->preamp); + } else + state->scale = state->missing_preamp; } void @@ -136,7 +136,5 @@ replay_gain_state_apply(const struct replay_gain_state *state, if (state->mode == REPLAY_GAIN_OFF) return; - float scale = state->info != NULL - ? state->scale : state->missing_preamp; - pcm_volume(buffer, size, format, pcm_float_to_volume(scale)); + pcm_volume(buffer, size, format, pcm_float_to_volume(state->scale)); } |