From f3b7cac4b4ea529b79ca6605a6fe8bec215568d3 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Sat, 26 Sep 2009 21:00:05 +0200 Subject: added replaygain peak scaling --- conf.c | 4 ++++ conf.h | 1 + config-example | 5 +++++ gtkplaylist.c | 5 +++++ streamer.c | 34 ++++++++++++++++++++++++++++------ 5 files changed, 43 insertions(+), 6 deletions(-) diff --git a/conf.c b/conf.c index 45d62dee..017da7d0 100644 --- a/conf.c +++ b/conf.c @@ -28,6 +28,7 @@ int conf_hvsc_enable = 0; char conf_blacklist_plugins[1024]; // plugins listed in this option will not be loaded int conf_close_send_to_tray = 0; int conf_replaygain_mode = 0; +int conf_replaygain_scale = 1; int conf_load (void) { @@ -103,6 +104,9 @@ conf_load (void) { fprintf (stderr, "config warning: replaygain_mode must be one of 0, 1 or 2\n"); } } + else if (!strcasecmp (str, "replaygain_scale")) { + conf_replaygain_scale = atoi (value); + } else { fprintf (stderr, "error in config file line %d\n", line); } diff --git a/conf.h b/conf.h index dc04f8ce..683db68b 100644 --- a/conf.h +++ b/conf.h @@ -26,6 +26,7 @@ extern int conf_hvsc_enable; extern char conf_blacklist_plugins[1024]; extern int conf_close_send_to_tray; extern int conf_replaygain_mode; +extern int conf_replaygain_scale; int conf_load (void); diff --git a/config-example b/config-example index 104fe1f6..a09f41a5 100644 --- a/config-example +++ b/config-example @@ -48,4 +48,9 @@ src_quality 2 # 1 track # 2 album (audiophile) # you must preprocess your collection with some external application to use that +# foobar2000 is the best to do it so far replaygain_mode 0 + +# replay gain scale +# set to 0 if you'd like to ignore peak scale (default is 1) +replaygain_scale 1 diff --git a/gtkplaylist.c b/gtkplaylist.c index 6a434b83..54e6b36f 100644 --- a/gtkplaylist.c +++ b/gtkplaylist.c @@ -783,6 +783,11 @@ gtkpl_keypress (gtkplaylist_t *ps, int keyval, int state) { replaygain = 1-replaygain; fprintf (stderr, "replaygain=%d\n", replaygain); } + else if (keyval == GDK_t) { + extern int replaygain_scale; + replaygain_scale = 1-replaygain_scale; + fprintf (stderr, "replaygain_scale=%d\n", replaygain_scale); + } else if (keyval == GDK_Up && ps->row > 0) { ps->row--; if (ps->row < ps->scrollpos) { diff --git a/streamer.c b/streamer.c index b6753304..5e0df775 100644 --- a/streamer.c +++ b/streamer.c @@ -45,7 +45,7 @@ static float g_fbuffer[200000]; // hack! static float g_srcbuffer[200000]; // hack! static int streaming_terminate; -#define STREAM_BUFFER_SIZE (200000*5) +#define STREAM_BUFFER_SIZE (200000) static int streambuffer_fill; static int bytes_until_next_song = 0; static char streambuffer[STREAM_BUFFER_SIZE]; @@ -274,6 +274,7 @@ streamer_thread (uintptr_t ctx) { if (orig_playing_song) { orig_playing_song->played = 1; orig_playing_song->started_timestamp = time (NULL); + str_playing_song.started_timestamp = time (NULL); } playlist_current_ptr = orig_playing_song; // that is needed for playlist drawing @@ -375,6 +376,7 @@ streamer_reset (int full) { // must be called when current song changes by exter } int replaygain = 1; +int replaygain_scale = 1; static void apply_replay_gain_int16 (playItem_t *it, char *bytes, int size) { @@ -386,13 +388,23 @@ apply_replay_gain_int16 (playItem_t *it, char *bytes, int size) { if (it->replaygain_track_gain == 0) { return; } - vol = db_to_amp (str_streaming_song.replaygain_track_gain) * 1000; + if (conf_replaygain_scale && replaygain_scale) { + vol = db_to_amp (str_streaming_song.replaygain_track_gain)/str_streaming_song.replaygain_track_peak * 1000; + } + else { + vol = db_to_amp (str_streaming_song.replaygain_track_gain) * 1000; + } } else if (conf_replaygain_mode == 2) { if (it->replaygain_album_gain == 0) { return; } - vol = db_to_amp (str_streaming_song.replaygain_album_gain) * 1000; + if (conf_replaygain_scale && replaygain_scale) { + vol = db_to_amp (str_streaming_song.replaygain_album_gain)/str_streaming_song.replaygain_album_peak * 1000; + } + else { + vol = db_to_amp (str_streaming_song.replaygain_album_gain) * 1000; + } } int16_t *s = (int16_t*)bytes; for (int j = 0; j < size/2; j++) { @@ -413,18 +425,28 @@ apply_replay_gain_float32 (playItem_t *it, char *bytes, int size) { if (!replaygain || !conf_replaygain_mode) { return; } - float vol = 1; + float vol = 1.f; if (conf_replaygain_mode == 1) { if (it->replaygain_track_gain == 0) { return; } - vol = db_to_amp (it->replaygain_track_gain); + if (conf_replaygain_scale && replaygain_scale) { + vol = db_to_amp (it->replaygain_track_gain)/it->replaygain_track_peak; + } + else { + vol = db_to_amp (it->replaygain_track_gain); + } } else if (conf_replaygain_mode == 2) { if (it->replaygain_album_gain == 0) { return; } - vol = db_to_amp (it->replaygain_album_gain); + if (conf_replaygain_scale && replaygain_scale) { + vol = db_to_amp (it->replaygain_album_gain)/it->replaygain_album_peak; + } + else { + vol = db_to_amp (it->replaygain_album_gain); + } } float *s = (float*)bytes; for (int j = 0; j < size/4; j++) { -- cgit v1.2.3