aboutsummaryrefslogtreecommitdiffstats
path: root/src/replay_gain.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2010-01-04 13:31:20 +0100
committerMax Kellermann <max@duempel.org>2010-01-04 20:54:01 +0100
commit0e183d3fa1f216729725127d868d66268e1a35d4 (patch)
tree63f14bdadec2e24104fa0fe957d2a30900e25385 /src/replay_gain.c
parentcd8f92c9285e9b3b460ff47d2f251bfabce544da (diff)
downloadmpd-0e183d3fa1f216729725127d868d66268e1a35d4.tar.gz
mpd-0e183d3fa1f216729725127d868d66268e1a35d4.tar.xz
mpd-0e183d3fa1f216729725127d868d66268e1a35d4.zip
replay_gain: refactor API, move code to replay_gain_state.c
The replay_gain_state struct holds the precalculated scale factor, which is removed from struct replay_gain_info.
Diffstat (limited to 'src/replay_gain.c')
-rw-r--r--src/replay_gain.c55
1 files changed, 2 insertions, 53 deletions
diff --git a/src/replay_gain.c b/src/replay_gain.c
index 482cd4bd3..3537a96ed 100644
--- a/src/replay_gain.c
+++ b/src/replay_gain.c
@@ -23,8 +23,6 @@
#include "config.h"
#include "replay_gain.h"
#include "conf.h"
-#include "audio_format.h"
-#include "pcm_volume.h"
#include "idle.h"
#include <glib.h>
@@ -41,8 +39,8 @@ static const char *const replay_gain_mode_names[] = {
enum replay_gain_mode replay_gain_mode = REPLAY_GAIN_OFF;
-static float replay_gain_preamp = 1.0;
-static float replay_gain_missing_preamp = 1.0;
+float replay_gain_preamp = 1.0;
+float replay_gain_missing_preamp = 1.0;
const char *
replay_gain_get_mode_string(void)
@@ -130,23 +128,6 @@ void replay_gain_global_init(void)
}
}
-static float calc_replay_gain_scale(float gain, float peak)
-{
- float scale;
-
- if (gain == 0.0)
- return (1);
- scale = pow(10.0, gain / 20.0);
- scale *= replay_gain_preamp;
- if (scale > 15.0)
- scale = 15.0;
-
- if (scale * peak > 1.0) {
- scale = 1.0 / peak;
- }
- return (scale);
-}
-
struct replay_gain_info *replay_gain_info_new(void)
{
struct replay_gain_info *ret = g_new(struct replay_gain_info, 1);
@@ -156,9 +137,6 @@ struct replay_gain_info *replay_gain_info_new(void)
ret->tuples[i].peak = 0.0;
}
- /* set to -1 so that we know in replay_gain_apply to compute the scale */
- ret->scale = -1.0;
-
return ret;
}
@@ -172,32 +150,3 @@ void replay_gain_info_free(struct replay_gain_info *info)
{
g_free(info);
}
-
-void
-replay_gain_apply(struct replay_gain_info *info, char *buffer, int size,
- const struct audio_format *format)
-{
- float scale;
-
- if (replay_gain_mode == REPLAY_GAIN_OFF)
- return;
-
- if (info) {
- if (info->scale < 0) {
- const struct replay_gain_tuple *tuple =
- &info->tuples[replay_gain_mode];
-
- g_debug("computing ReplayGain %s scale with gain %f, peak %f\n",
- replay_gain_mode_names[replay_gain_mode],
- tuple->gain, tuple->peak);
-
- info->scale = calc_replay_gain_scale(tuple->gain, tuple->peak);
- }
- scale = info->scale;
- }
- else {
- scale = replay_gain_missing_preamp;
- }
-
- pcm_volume(buffer, size, format, pcm_float_to_volume(scale));
-}