From ea7992455a9704e2eb6bd6c9b39fabd111a7b997 Mon Sep 17 00:00:00 2001 From: Magnus Holmgren Date: Wed, 15 Nov 2006 20:26:33 +0000 Subject: Make the updated %rg tag match playback behaviour (fall back to track gain if album gain requested but not available). Share the mode decision logic with playback code and simplify the %rg tag handling. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11532 a1c6a512-1295-4272-9138-f99709370657 --- apps/dsp.c | 7 +++---- apps/gui/gwps-common.c | 50 ++++++++++++++------------------------------------ apps/misc.c | 16 ++++++++++++++++ apps/misc.h | 8 ++++++++ 4 files changed, 41 insertions(+), 40 deletions(-) diff --git a/apps/dsp.c b/apps/dsp.c index 94e825c532..5627b05bca 100644 --- a/apps/dsp.c +++ b/apps/dsp.c @@ -26,6 +26,7 @@ #include "system.h" #include "settings.h" #include "replaygain.h" +#include "misc.h" #include "debug.h" #ifndef SIMULATOR @@ -1093,10 +1094,8 @@ void dsp_set_replaygain(bool always) if (global_settings.replaygain || global_settings.replaygain_noclip) { - bool track_mode - = ((global_settings.replaygain_type == REPLAYGAIN_TRACK) - || ((global_settings.replaygain_type == REPLAYGAIN_SHUFFLE) - && global_settings.playlist_shuffle)); + bool track_mode = get_replaygain_mode(dsp->track_gain != 0, + dsp->album_gain != 0) == REPLAYGAIN_TRACK; long peak = (track_mode || !dsp->album_peak) ? dsp->track_peak : dsp->album_peak; diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c index 2e7b7ef09c..7e795ffd96 100644 --- a/apps/gui/gwps-common.c +++ b/apps/gui/gwps-common.c @@ -941,46 +941,24 @@ static char* get_tag(struct wps_data* wps_data, *intval = 1; /* off */ else { - switch (global_settings.replaygain_type) - { - case REPLAYGAIN_TRACK: /* track */ - if (id3->track_gain_string == NULL) - *intval = 6; /* no tag */ - else - *intval = 2; - break; - case REPLAYGAIN_ALBUM: /* album */ - if (id3->album_gain_string == NULL) - *intval = 6; /* no tag */ - else - *intval = 3; - break; - case REPLAYGAIN_SHUFFLE: /* shuffle */ - if (global_settings.playlist_shuffle) - { - if (id3->track_gain_string == NULL) - *intval = 6; /* no tag */ - else - *intval = 4; /* shuffle track */ - } - else - { - if (id3->album_gain_string == NULL) - *intval = 6; /* no tag */ - else - *intval = 5; /* shuffle album */ - } - break; - default: - *intval = 1; /* shoudn't happen, treat as off */ - break; - } /* switch - replay gain type */ - } /* if - replay gain set */ + int type = get_replaygain_mode( + id3->track_gain_string != NULL, + id3->album_gain_string != NULL); + + if (type < 0) + *intval = 6; /* no tag */ + else + *intval = type + 2; + + if (global_settings.replaygain_type == REPLAYGAIN_SHUFFLE) + *intval += 2; + } + switch (*intval) { case 1: case 6: - strncpy(buf, "+0.00 dB", buf_size); + return "+0.00 dB"; break; case 2: case 4: diff --git a/apps/misc.c b/apps/misc.c index 80c4588f0f..709bc49208 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -802,3 +802,19 @@ int show_logo( void ) return 0; } + +#if CONFIG_CODEC == SWCODEC +int get_replaygain_mode(bool have_track_gain, bool have_album_gain) +{ + int type; + + bool track = ((global_settings.replaygain_type == REPLAYGAIN_TRACK) + || ((global_settings.replaygain_type == REPLAYGAIN_SHUFFLE) + && global_settings.playlist_shuffle)); + + type = (!track && have_album_gain) ? REPLAYGAIN_ALBUM + : have_track_gain ? REPLAYGAIN_TRACK : -1; + + return type; +} +#endif diff --git a/apps/misc.h b/apps/misc.h index 6c660e0a5e..f273631030 100644 --- a/apps/misc.h +++ b/apps/misc.h @@ -82,4 +82,12 @@ long default_event_handler(long event); void car_adapter_mode_init(void); extern int show_logo(void); +#if CONFIG_CODEC == SWCODEC +/* Return current ReplayGain mode a file should have (REPLAYGAIN_TRACK or + * REPLAYGAIN_ALBUM) if ReplayGain processing is enabled, or -1 if no + * information present. + */ +int get_replaygain_mode(bool have_track_gain, bool have_album_gain); +#endif + #endif /* MISC_H */ -- cgit v1.2.3