Rework parts of the replaygain code to be able to differentiate between 0.00 dB set intentionally and having no replaygain information at all. Bump codec api.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29679 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Andree Buschmann 2011-04-04 15:21:44 +00:00
parent f0132528fd
commit d1766a1510
7 changed files with 23 additions and 18 deletions

View File

@ -75,12 +75,12 @@
#define CODEC_ENC_MAGIC 0x52454E43 /* RENC */
/* increase this every time the api struct changes */
#define CODEC_API_VERSION 40
#define CODEC_API_VERSION 41
/* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any
new function which are "waiting" at the end of the function table) */
#define CODEC_MIN_API_VERSION 40
#define CODEC_MIN_API_VERSION 41
/* codec return codes */
enum codec_status {

View File

@ -1475,12 +1475,12 @@ intptr_t dsp_configure(struct dsp_config *dsp, int setting, intptr_t value)
case DSP_SET_TRACK_GAIN:
if (dsp == &AUDIO_DSP)
dsp_set_gain_var(&track_gain, value ? convert_gain(value) : 0);
dsp_set_gain_var(&track_gain, value);
break;
case DSP_SET_ALBUM_GAIN:
if (dsp == &AUDIO_DSP)
dsp_set_gain_var(&album_gain, value ? convert_gain(value) : 0);
dsp_set_gain_var(&album_gain, value);
break;
case DSP_SET_TRACK_PEAK:

View File

@ -1332,11 +1332,11 @@ const char *get_token_value(struct gui_wps *gwps,
/* due to above, coming here with !id3 shouldn't be possible */
case 2:
case 4:
replaygain_itoa(buf, buf_size, id3->track_gain);
replaygain_itoa(buf, buf_size, id3->track_level);
break;
case 3:
case 5:
replaygain_itoa(buf, buf_size, id3->album_gain);
replaygain_itoa(buf, buf_size, id3->album_level);
break;
}
return buf;

View File

@ -282,6 +282,8 @@ struct mp3entry {
/* replaygain support */
#if CONFIG_CODEC == SWCODEC
long track_level; /* holds the level in dB * (1<<FP_BITS) */
long album_level;
long track_gain; /* s19.12 signed fixed point. 0 for no gain. */
long album_gain;
long track_peak; /* s19.12 signed fixed point. 0 for no peak. */

View File

@ -118,7 +118,7 @@ static long fp_atof(const char* s, int precision)
+ (((int64_t) frac_part * int_one) / frac_max_int));
}
long convert_gain(long gain)
static long convert_gain(long gain)
{
/* Don't allow unreasonably low or high gain changes.
* Our math code can't handle it properly anyway. :) */
@ -171,13 +171,15 @@ void parse_replaygain(const char* key, const char* value,
(strcasecmp(key, "rg_radio") == 0)) &&
!entry->track_gain)
{
entry->track_gain = get_replaygain(value);
entry->track_level = get_replaygain(value);
entry->track_gain = convert_gain(entry->track_level);
}
else if (((strcasecmp(key, "replaygain_album_gain") == 0) ||
(strcasecmp(key, "rg_audiophile") == 0)) &&
!entry->album_gain)
{
entry->album_gain = get_replaygain(value);
entry->album_level = get_replaygain(value);
entry->album_gain = convert_gain(entry->album_level);
}
else if (((strcasecmp(key, "replaygain_track_peak") == 0) ||
(strcasecmp(key, "rg_peak") == 0)) &&
@ -207,12 +209,14 @@ void parse_replaygain_int(bool album, long gain, long peak,
if (album)
{
entry->album_gain = gain;
entry->album_peak = peak;
entry->album_level = gain;
entry->album_gain = convert_gain(gain);
entry->album_peak = peak;
}
else
{
entry->track_gain = gain;
entry->track_peak = peak;
entry->track_level = gain;
entry->track_gain = convert_gain(gain);
entry->track_peak = peak;
}
}

View File

@ -30,6 +30,5 @@ void parse_replaygain(const char* key, const char* value,
void parse_replaygain_int(bool album, long gain, long peak,
struct mp3entry* entry);
void replaygain_itoa(char* buffer, int length, long int_gain);
long convert_gain(long gain);
#endif

View File

@ -729,12 +729,12 @@ static const char* id3_get_info(int selected_item, void* data,
break;
#if CONFIG_CODEC == SWCODEC
case LANG_ID3_TRACK_GAIN:
replaygain_itoa(buffer, buffer_len, id3->track_gain);
val=(id3->track_gain) ? buffer : NULL; /* only show gains!=0 */
replaygain_itoa(buffer, buffer_len, id3->track_level);
val=(id3->track_level) ? buffer : NULL; /* only show level!=0 */
break;
case LANG_ID3_ALBUM_GAIN:
replaygain_itoa(buffer, buffer_len, id3->album_gain);
val=(id3->album_gain) ? buffer : NULL; /* only show gains!=0 */
replaygain_itoa(buffer, buffer_len, id3->album_level);
val=(id3->album_level) ? buffer : NULL; /* only show level!=0 */
break;
#endif
case LANG_ID3_PATH: