diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/dsp.c | 8 | ||||
-rw-r--r-- | apps/gui/skin_engine/skin_tokens.c | 9 | ||||
-rw-r--r-- | apps/metadata.c | 6 | ||||
-rw-r--r-- | apps/metadata.h | 7 | ||||
-rw-r--r-- | apps/metadata/asf.c | 12 | ||||
-rw-r--r-- | apps/metadata/id3tags.c | 18 | ||||
-rw-r--r-- | apps/metadata/metadata_common.c | 2 | ||||
-rw-r--r-- | apps/metadata/mp4.c | 8 | ||||
-rw-r--r-- | apps/metadata/mpc.c | 6 | ||||
-rw-r--r-- | apps/replaygain.c | 130 | ||||
-rw-r--r-- | apps/replaygain.h | 10 | ||||
-rw-r--r-- | apps/screens.c | 7 |
12 files changed, 65 insertions, 158 deletions
diff --git a/apps/dsp.c b/apps/dsp.c index 3cff1918d7..c462fc37a6 100644 --- a/apps/dsp.c +++ b/apps/dsp.c | |||
@@ -1475,22 +1475,22 @@ intptr_t dsp_configure(struct dsp_config *dsp, int setting, intptr_t value) | |||
1475 | 1475 | ||
1476 | case DSP_SET_TRACK_GAIN: | 1476 | case DSP_SET_TRACK_GAIN: |
1477 | if (dsp == &AUDIO_DSP) | 1477 | if (dsp == &AUDIO_DSP) |
1478 | dsp_set_gain_var(&track_gain, value); | 1478 | dsp_set_gain_var(&track_gain, convert_gain(value)); |
1479 | break; | 1479 | break; |
1480 | 1480 | ||
1481 | case DSP_SET_ALBUM_GAIN: | 1481 | case DSP_SET_ALBUM_GAIN: |
1482 | if (dsp == &AUDIO_DSP) | 1482 | if (dsp == &AUDIO_DSP) |
1483 | dsp_set_gain_var(&album_gain, value); | 1483 | dsp_set_gain_var(&album_gain, convert_gain(value)); |
1484 | break; | 1484 | break; |
1485 | 1485 | ||
1486 | case DSP_SET_TRACK_PEAK: | 1486 | case DSP_SET_TRACK_PEAK: |
1487 | if (dsp == &AUDIO_DSP) | 1487 | if (dsp == &AUDIO_DSP) |
1488 | dsp_set_gain_var(&track_peak, value); | 1488 | dsp_set_gain_var(&track_peak, convert_gain(value)); |
1489 | break; | 1489 | break; |
1490 | 1490 | ||
1491 | case DSP_SET_ALBUM_PEAK: | 1491 | case DSP_SET_ALBUM_PEAK: |
1492 | if (dsp == &AUDIO_DSP) | 1492 | if (dsp == &AUDIO_DSP) |
1493 | dsp_set_gain_var(&album_peak, value); | 1493 | dsp_set_gain_var(&album_peak, convert_gain(value)); |
1494 | break; | 1494 | break; |
1495 | 1495 | ||
1496 | default: | 1496 | default: |
diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c index f455999b2a..1fbe3d714e 100644 --- a/apps/gui/skin_engine/skin_tokens.c +++ b/apps/gui/skin_engine/skin_tokens.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include "sound.h" | 35 | #include "sound.h" |
36 | #include "debug.h" | 36 | #include "debug.h" |
37 | #include "cuesheet.h" | 37 | #include "cuesheet.h" |
38 | #include "replaygain.h" | ||
38 | #ifdef HAVE_LCD_CHARCELLS | 39 | #ifdef HAVE_LCD_CHARCELLS |
39 | #include "hwcompat.h" | 40 | #include "hwcompat.h" |
40 | #endif | 41 | #endif |
@@ -1305,8 +1306,8 @@ const char *get_token_value(struct gui_wps *gwps, | |||
1305 | { | 1306 | { |
1306 | int type; | 1307 | int type; |
1307 | if (LIKELY(id3)) | 1308 | if (LIKELY(id3)) |
1308 | type = get_replaygain_mode(id3->track_gain_string != NULL, | 1309 | type = get_replaygain_mode(id3->track_gain != 0, |
1309 | id3->album_gain_string != NULL); | 1310 | id3->album_gain != 0); |
1310 | else | 1311 | else |
1311 | type = -1; | 1312 | type = -1; |
1312 | 1313 | ||
@@ -1331,11 +1332,11 @@ const char *get_token_value(struct gui_wps *gwps, | |||
1331 | /* due to above, coming here with !id3 shouldn't be possible */ | 1332 | /* due to above, coming here with !id3 shouldn't be possible */ |
1332 | case 2: | 1333 | case 2: |
1333 | case 4: | 1334 | case 4: |
1334 | strlcpy(buf, id3->track_gain_string, buf_size); | 1335 | replaygain_itoa(buf, buf_size, id3->track_gain); |
1335 | break; | 1336 | break; |
1336 | case 3: | 1337 | case 3: |
1337 | case 5: | 1338 | case 5: |
1338 | strlcpy(buf, id3->album_gain_string, buf_size); | 1339 | replaygain_itoa(buf, buf_size, id3->album_gain); |
1339 | break; | 1340 | break; |
1340 | } | 1341 | } |
1341 | return buf; | 1342 | return buf; |
diff --git a/apps/metadata.c b/apps/metadata.c index 12bea286d0..4e4ffb6ad2 100644 --- a/apps/metadata.c +++ b/apps/metadata.c | |||
@@ -411,12 +411,6 @@ void adjust_mp3entry(struct mp3entry *entry, void *dest, const void *orig) | |||
411 | entry->albumartist += offset; | 411 | entry->albumartist += offset; |
412 | if (entry->grouping) | 412 | if (entry->grouping) |
413 | entry->grouping += offset; | 413 | entry->grouping += offset; |
414 | #if CONFIG_CODEC == SWCODEC | ||
415 | if (entry->track_gain_string) | ||
416 | entry->track_gain_string += offset; | ||
417 | if (entry->album_gain_string) | ||
418 | entry->album_gain_string += offset; | ||
419 | #endif | ||
420 | if (entry->mb_track_id) | 414 | if (entry->mb_track_id) |
421 | entry->mb_track_id += offset; | 415 | entry->mb_track_id += offset; |
422 | } | 416 | } |
diff --git a/apps/metadata.h b/apps/metadata.h index 8d20882835..5662c2e840 100644 --- a/apps/metadata.h +++ b/apps/metadata.h | |||
@@ -283,13 +283,10 @@ struct mp3entry { | |||
283 | #endif | 283 | #endif |
284 | 284 | ||
285 | /* replaygain support */ | 285 | /* replaygain support */ |
286 | |||
287 | #if CONFIG_CODEC == SWCODEC | 286 | #if CONFIG_CODEC == SWCODEC |
288 | char* track_gain_string; | 287 | long track_gain; /* s19.12 signed fixed point. 0 for no gain. */ |
289 | char* album_gain_string; | ||
290 | long track_gain; /* 7.24 signed fixed point. 0 for no gain. */ | ||
291 | long album_gain; | 288 | long album_gain; |
292 | long track_peak; /* 7.24 signed fixed point. 0 for no peak. */ | 289 | long track_peak; /* s19.12 signed fixed point. 0 for no peak. */ |
293 | long album_peak; | 290 | long album_peak; |
294 | #endif | 291 | #endif |
295 | 292 | ||
diff --git a/apps/metadata/asf.c b/apps/metadata/asf.c index c445e485a2..56d5c87f9d 100644 --- a/apps/metadata/asf.c +++ b/apps/metadata/asf.c | |||
@@ -456,18 +456,8 @@ static int asf_parse_header(int fd, struct mp3entry* id3, | |||
456 | lseek(fd, length, SEEK_CUR); | 456 | lseek(fd, length, SEEK_CUR); |
457 | } | 457 | } |
458 | } else if (!strncmp("replaygain_", utf8buf, 11)) { | 458 | } else if (!strncmp("replaygain_", utf8buf, 11)) { |
459 | char* value = id3buf; | ||
460 | int buf_len = id3buf_remaining; | ||
461 | int len; | ||
462 | asf_utf16LEdecode(fd, length, &id3buf, &id3buf_remaining); | 459 | asf_utf16LEdecode(fd, length, &id3buf, &id3buf_remaining); |
463 | len = parse_replaygain(utf8buf, value, id3, | 460 | parse_replaygain(utf8buf, id3buf, id3); |
464 | value, buf_len); | ||
465 | |||
466 | if (len == 0) { | ||
467 | /* Don't need to keep the value */ | ||
468 | id3buf = value; | ||
469 | id3buf_remaining = buf_len; | ||
470 | } | ||
471 | } else if (!strcmp("MusicBrainz/Track Id", utf8buf)) { | 461 | } else if (!strcmp("MusicBrainz/Track Id", utf8buf)) { |
472 | id3->mb_track_id = id3buf; | 462 | id3->mb_track_id = id3buf; |
473 | asf_utf16LEdecode(fd, length, &id3buf, &id3buf_remaining); | 463 | asf_utf16LEdecode(fd, length, &id3buf, &id3buf_remaining); |
diff --git a/apps/metadata/id3tags.c b/apps/metadata/id3tags.c index 3cbebc12e3..c1d9cb2020 100644 --- a/apps/metadata/id3tags.c +++ b/apps/metadata/id3tags.c | |||
@@ -370,14 +370,8 @@ static int parseuser( struct mp3entry* entry, char* tag, int bufferpos ) | |||
370 | entry->albumartist = tag; | 370 | entry->albumartist = tag; |
371 | #if CONFIG_CODEC == SWCODEC | 371 | #if CONFIG_CODEC == SWCODEC |
372 | } else { | 372 | } else { |
373 | /* Calculate residual buffer size in bytes which can be used by | 373 | /* Call parse_replaygain(). */ |
374 | * parse_replaygain() to save the string representation of | 374 | parse_replaygain(tag, value, entry); |
375 | * replaygain data.*/ | ||
376 | length = sizeof(entry->id3v2buf) - (tag - entry->id3v2buf); | ||
377 | |||
378 | /* Call parse_replaygain(), returns length in bytes used by the | ||
379 | * string representation of replaygain data. */ | ||
380 | length = parse_replaygain(tag, value, entry, tag, length); | ||
381 | #endif | 375 | #endif |
382 | } | 376 | } |
383 | } | 377 | } |
@@ -387,12 +381,11 @@ static int parseuser( struct mp3entry* entry, char* tag, int bufferpos ) | |||
387 | 381 | ||
388 | #if CONFIG_CODEC == SWCODEC | 382 | #if CONFIG_CODEC == SWCODEC |
389 | /* parse RVA2 binary data and convert to replaygain information. */ | 383 | /* parse RVA2 binary data and convert to replaygain information. */ |
390 | static int parserva2( struct mp3entry* entry, char* tag, int bufferpos ) | 384 | static int parserva2( struct mp3entry* entry, char* tag, int bufferpos) |
391 | { | 385 | { |
392 | int desc_len = strlen(tag); | 386 | int desc_len = strlen(tag); |
393 | int start_pos = tag - entry->id3v2buf; | 387 | int start_pos = tag - entry->id3v2buf; |
394 | int end_pos = start_pos + desc_len + 5; | 388 | int end_pos = start_pos + desc_len + 5; |
395 | int value_len = 0; | ||
396 | unsigned char* value = tag + desc_len + 1; | 389 | unsigned char* value = tag + desc_len + 1; |
397 | 390 | ||
398 | /* Only parse RVA2 replaygain tags if tag version == 2.4 and channel | 391 | /* Only parse RVA2 replaygain tags if tag version == 2.4 and channel |
@@ -447,11 +440,10 @@ static int parserva2( struct mp3entry* entry, char* tag, int bufferpos ) | |||
447 | } | 440 | } |
448 | } | 441 | } |
449 | 442 | ||
450 | value_len = parse_replaygain_int(album, gain, peak * 2, entry, | 443 | parse_replaygain_int(album, gain, peak * 2, entry); |
451 | tag, sizeof(entry->id3v2buf) - start_pos); | ||
452 | } | 444 | } |
453 | 445 | ||
454 | return start_pos + value_len; | 446 | return start_pos; |
455 | } | 447 | } |
456 | #endif | 448 | #endif |
457 | 449 | ||
diff --git a/apps/metadata/metadata_common.c b/apps/metadata/metadata_common.c index 341d279b5d..ae6b245616 100644 --- a/apps/metadata/metadata_common.c +++ b/apps/metadata/metadata_common.c | |||
@@ -333,7 +333,7 @@ long parse_tag(const char* name, char* value, struct mp3entry* id3, | |||
333 | } | 333 | } |
334 | else | 334 | else |
335 | { | 335 | { |
336 | len = parse_replaygain(name, value, id3, buf, buf_remaining); | 336 | parse_replaygain(name, value, id3); |
337 | p = NULL; | 337 | p = NULL; |
338 | } | 338 | } |
339 | 339 | ||
diff --git a/apps/metadata/mp4.c b/apps/metadata/mp4.c index 6130135bae..a431231e12 100644 --- a/apps/metadata/mp4.c +++ b/apps/metadata/mp4.c | |||
@@ -528,13 +528,7 @@ static bool read_mp4_tags(int fd, struct mp3entry* id3, | |||
528 | buffer -= length; | 528 | buffer -= length; |
529 | buffer_left += length; | 529 | buffer_left += length; |
530 | 530 | ||
531 | if (parse_replaygain(tag_name, buffer, id3, | 531 | parse_replaygain(tag_name, buffer, id3); |
532 | buffer, buffer_left) > 0) | ||
533 | { | ||
534 | /* Data used, keep it. */ | ||
535 | buffer += length; | ||
536 | buffer_left -= length; | ||
537 | } | ||
538 | } | 532 | } |
539 | } | 533 | } |
540 | } | 534 | } |
diff --git a/apps/metadata/mpc.c b/apps/metadata/mpc.c index 0387dc9f77..0b75ed04dd 100644 --- a/apps/metadata/mpc.c +++ b/apps/metadata/mpc.c | |||
@@ -46,8 +46,7 @@ static int set_replaygain_sv7(struct mp3entry* id3, | |||
46 | /* We use a peak value of 0 to indicate a given gain type isn't used. */ | 46 | /* We use a peak value of 0 to indicate a given gain type isn't used. */ |
47 | if (peak != 0) { | 47 | if (peak != 0) { |
48 | /* Save the ReplayGain data to id3-structure for further processing. */ | 48 | /* Save the ReplayGain data to id3-structure for further processing. */ |
49 | used += parse_replaygain_int(album, gain * 512 / 100, peak << 9, | 49 | parse_replaygain_int(album, gain * 512 / 100, peak << 9, id3); |
50 | id3, id3->toc + used, sizeof(id3->toc) - used); | ||
51 | } | 50 | } |
52 | 51 | ||
53 | return used; | 52 | return used; |
@@ -73,8 +72,7 @@ static int set_replaygain_sv8(struct mp3entry* id3, | |||
73 | /* We use a peak value of 0 to indicate a given gain type isn't used. */ | 72 | /* We use a peak value of 0 to indicate a given gain type isn't used. */ |
74 | if (peak != 0) { | 73 | if (peak != 0) { |
75 | /* Save the ReplayGain data to id3-structure for further processing. */ | 74 | /* Save the ReplayGain data to id3-structure for further processing. */ |
76 | used += parse_replaygain_int(album, gain * 512 / 100, peak, | 75 | parse_replaygain_int(album, gain * 512 / 100, peak, id3); |
77 | id3, id3->toc + used, sizeof(id3->toc) - used); | ||
78 | } | 76 | } |
79 | 77 | ||
80 | return used; | 78 | return used; |
diff --git a/apps/replaygain.c b/apps/replaygain.c index 81f1a45ad7..9f0dda7a0b 100644 --- a/apps/replaygain.c +++ b/apps/replaygain.c | |||
@@ -36,6 +36,13 @@ | |||
36 | #define FP_BITS (12) | 36 | #define FP_BITS (12) |
37 | #define FP_ONE (1 << FP_BITS) | 37 | #define FP_ONE (1 << FP_BITS) |
38 | 38 | ||
39 | void replaygain_itoa(char* buffer, int length, long int_gain) | ||
40 | { | ||
41 | /* int_gain uses Q19.12 format. */ | ||
42 | int one = abs(int_gain) >> FP_BITS; | ||
43 | int cent = ((abs(int_gain) & 0x0fff) * 100 + (FP_ONE/2)) >> FP_BITS; | ||
44 | snprintf(buffer, length, "%d.%02d dB", (int_gain<0) ? -one : one, cent); | ||
45 | } | ||
39 | 46 | ||
40 | static long fp_atof(const char* s, int precision) | 47 | static long fp_atof(const char* s, int precision) |
41 | { | 48 | { |
@@ -109,42 +116,25 @@ static long fp_atof(const char* s, int precision) | |||
109 | + (((int64_t) frac_part * int_one) / frac_max_int)); | 116 | + (((int64_t) frac_part * int_one) / frac_max_int)); |
110 | } | 117 | } |
111 | 118 | ||
112 | static long convert_gain(long gain) | 119 | long convert_gain(long gain) |
113 | { | 120 | { |
114 | /* Don't allow unreasonably low or high gain changes. | 121 | /* Don't allow unreasonably low or high gain changes. |
115 | * Our math code can't handle it properly anyway. :) | 122 | * Our math code can't handle it properly anyway. :) |
116 | */ | 123 | */ |
117 | if (gain < (-48 * FP_ONE)) | 124 | gain = MAX(gain,-48 * FP_ONE); |
118 | { | 125 | gain = MIN(gain, 17 * FP_ONE); |
119 | gain = -48 * FP_ONE; | ||
120 | } | ||
121 | |||
122 | if (gain > (17 * FP_ONE)) | ||
123 | { | ||
124 | gain = 17 * FP_ONE; | ||
125 | } | ||
126 | |||
127 | gain = fp_factor(gain, FP_BITS) << (24 - FP_BITS); | ||
128 | 126 | ||
129 | return gain; | 127 | return fp_factor(gain, FP_BITS) << (24 - FP_BITS); |
130 | } | 128 | } |
131 | 129 | ||
132 | /* Get the sample scale factor in Q7.24 format from a gain value. Returns 0 | 130 | /* Get the sample scale factor in Q19.12 format from a gain value. Returns 0 |
133 | * for no gain. | 131 | * for no gain. |
134 | * | 132 | * |
135 | * str Gain in dB as a string. E.g., "-3.45 dB"; the "dB" part is ignored. | 133 | * str Gain in dB as a string. E.g., "-3.45 dB"; the "dB" part is ignored. |
136 | */ | 134 | */ |
137 | static long get_replaygain(const char* str) | 135 | static long get_replaygain(const char* str) |
138 | { | 136 | { |
139 | long gain = 0; | 137 | return fp_atof(str, FP_BITS); |
140 | |||
141 | if (str) | ||
142 | { | ||
143 | gain = fp_atof(str, FP_BITS); | ||
144 | gain = convert_gain(gain); | ||
145 | } | ||
146 | |||
147 | return gain; | ||
148 | } | 138 | } |
149 | 139 | ||
150 | /* Get the peak volume in Q7.24 format. | 140 | /* Get the peak volume in Q7.24 format. |
@@ -153,14 +143,7 @@ static long get_replaygain(const char* str) | |||
153 | */ | 143 | */ |
154 | static long get_replaypeak(const char* str) | 144 | static long get_replaypeak(const char* str) |
155 | { | 145 | { |
156 | long peak = 0; | 146 | return fp_atof(str, 24); |
157 | |||
158 | if (str) | ||
159 | { | ||
160 | peak = fp_atof(str, 24); | ||
161 | } | ||
162 | |||
163 | return peak; | ||
164 | } | 147 | } |
165 | 148 | ||
166 | /* Get a sample scale factor in Q7.24 format from a gain value. | 149 | /* Get a sample scale factor in Q7.24 format from a gain value. |
@@ -174,107 +157,60 @@ long get_replaygain_int(long int_gain) | |||
174 | 157 | ||
175 | /* Parse a ReplayGain tag conforming to the "VorbisGain standard". If a | 158 | /* Parse a ReplayGain tag conforming to the "VorbisGain standard". If a |
176 | * valid tag is found, update mp3entry struct accordingly. Existing values | 159 | * valid tag is found, update mp3entry struct accordingly. Existing values |
177 | * are not overwritten. Returns number of bytes written to buffer. | 160 | * are not overwritten. |
178 | * | 161 | * |
179 | * key Name of the tag. | 162 | * key Name of the tag. |
180 | * value Value of the tag. | 163 | * value Value of the tag. |
181 | * entry mp3entry struct to update. | 164 | * entry mp3entry struct to update. |
182 | * buffer Where to store the text for gain values (for later display). | ||
183 | * length Bytes left in buffer. | ||
184 | */ | 165 | */ |
185 | long parse_replaygain(const char* key, const char* value, | 166 | void parse_replaygain(const char* key, const char* value, |
186 | struct mp3entry* entry, char* buffer, int length) | 167 | struct mp3entry* entry) |
187 | { | 168 | { |
188 | char **p = NULL; | 169 | if (((strcasecmp(key, "replaygain_track_gain") == 0) || |
189 | 170 | (strcasecmp(key, "rg_radio") == 0)) && | |
190 | if (((strcasecmp(key, "replaygain_track_gain") == 0) | 171 | !entry->track_gain) |
191 | || (strcasecmp(key, "rg_radio") == 0)) && !entry->track_gain) | ||
192 | { | 172 | { |
193 | entry->track_gain = get_replaygain(value); | 173 | entry->track_gain = get_replaygain(value); |
194 | p = &(entry->track_gain_string); | ||
195 | } | 174 | } |
196 | else if (((strcasecmp(key, "replaygain_album_gain") == 0) | 175 | else if (((strcasecmp(key, "replaygain_album_gain") == 0) || |
197 | || (strcasecmp(key, "rg_audiophile") == 0)) && !entry->album_gain) | 176 | (strcasecmp(key, "rg_audiophile") == 0)) && |
177 | !entry->album_gain) | ||
198 | { | 178 | { |
199 | entry->album_gain = get_replaygain(value); | 179 | entry->album_gain = get_replaygain(value); |
200 | p = &(entry->album_gain_string); | ||
201 | } | 180 | } |
202 | else if (((strcasecmp(key, "replaygain_track_peak") == 0) | 181 | else if (((strcasecmp(key, "replaygain_track_peak") == 0) || |
203 | || (strcasecmp(key, "rg_peak") == 0)) && !entry->track_peak) | 182 | (strcasecmp(key, "rg_peak") == 0)) && |
183 | !entry->track_peak) | ||
204 | { | 184 | { |
205 | entry->track_peak = get_replaypeak(value); | 185 | entry->track_peak = get_replaypeak(value); |
206 | } | 186 | } |
207 | else if ((strcasecmp(key, "replaygain_album_peak") == 0) | 187 | else if ((strcasecmp(key, "replaygain_album_peak") == 0) && |
208 | && !entry->album_peak) | 188 | !entry->album_peak) |
209 | { | 189 | { |
210 | entry->album_peak = get_replaypeak(value); | 190 | entry->album_peak = get_replaypeak(value); |
211 | } | 191 | } |
212 | |||
213 | if (p) | ||
214 | { | ||
215 | int len = strlen(value); | ||
216 | |||
217 | len = MIN(len, length - 1); | ||
218 | |||
219 | /* A few characters just isn't interesting... */ | ||
220 | if (len > 1) | ||
221 | { | ||
222 | strlcpy(buffer, value, len + 1); | ||
223 | *p = buffer; | ||
224 | return len + 1; | ||
225 | } | ||
226 | } | ||
227 | |||
228 | return 0; | ||
229 | } | 192 | } |
230 | 193 | ||
231 | /* Set ReplayGain values from integers. Existing values are not overwritten. | 194 | /* Set ReplayGain values from integers. Existing values are not overwritten. |
232 | * Returns number of bytes written to buffer. | ||
233 | * | 195 | * |
234 | * album If true, set album values, otherwise set track values. | 196 | * album If true, set album values, otherwise set track values. |
235 | * gain Gain value in dB, multiplied by 512. 0 for no gain. | 197 | * gain Gain value in dB, multiplied by 512. 0 for no gain. |
236 | * peak Peak volume in Q7.24 format, where 1.0 is full scale. 0 for no | 198 | * peak Peak volume in Q7.24 format, where 1.0 is full scale. 0 for no |
237 | * peak volume. | 199 | * peak volume. |
238 | * buffer Where to store the text for gain values (for later display). | ||
239 | * length Bytes left in buffer. | ||
240 | */ | 200 | */ |
241 | long parse_replaygain_int(bool album, long gain, long peak, | 201 | void parse_replaygain_int(bool album, long gain, long peak, |
242 | struct mp3entry* entry, char* buffer, int length) | 202 | struct mp3entry* entry) |
243 | { | 203 | { |
244 | long len = 0; | 204 | gain = gain * FP_ONE / 512; |
245 | |||
246 | if (buffer != NULL) | ||
247 | { | ||
248 | len = snprintf(buffer, length, "%ld.%02d dB", gain / 512, | ||
249 | ((abs(gain) & 0x01ff) * 100 + 256) / 512); | ||
250 | len++; | ||
251 | } | ||
252 | |||
253 | if (gain != 0) | ||
254 | { | ||
255 | gain = convert_gain(gain * FP_ONE / 512); | ||
256 | } | ||
257 | 205 | ||
258 | if (album) | 206 | if (album) |
259 | { | 207 | { |
260 | entry->album_gain = gain; | 208 | entry->album_gain = gain; |
261 | entry->album_gain_string = buffer; | 209 | entry->album_peak = peak; |
262 | |||
263 | if (peak) | ||
264 | { | ||
265 | entry->album_peak = peak; | ||
266 | } | ||
267 | } | 210 | } |
268 | else | 211 | else |
269 | { | 212 | { |
270 | entry->track_gain = gain; | 213 | entry->track_gain = gain; |
271 | entry->track_gain_string = buffer; | 214 | entry->track_peak = peak; |
272 | |||
273 | if (peak) | ||
274 | { | ||
275 | entry->track_peak = peak; | ||
276 | } | ||
277 | } | 215 | } |
278 | |||
279 | return len; | ||
280 | } | 216 | } |
diff --git a/apps/replaygain.h b/apps/replaygain.h index 02ca2e0bae..4fb5476e23 100644 --- a/apps/replaygain.h +++ b/apps/replaygain.h | |||
@@ -25,9 +25,11 @@ | |||
25 | #include "metadata.h" | 25 | #include "metadata.h" |
26 | 26 | ||
27 | long get_replaygain_int(long int_gain); | 27 | long get_replaygain_int(long int_gain); |
28 | long parse_replaygain(const char* key, const char* value, | 28 | void parse_replaygain(const char* key, const char* value, |
29 | struct mp3entry* entry, char* buffer, int length); | 29 | struct mp3entry* entry); |
30 | long parse_replaygain_int(bool album, long gain, long peak, | 30 | void parse_replaygain_int(bool album, long gain, long peak, |
31 | struct mp3entry* entry, char* buffer, int length); | 31 | struct mp3entry* entry); |
32 | void replaygain_itoa(char* buffer, int length, long int_gain); | ||
33 | long convert_gain(long gain); | ||
32 | 34 | ||
33 | #endif | 35 | #endif |
diff --git a/apps/screens.c b/apps/screens.c index 81472e6cc7..b1a48c5bd6 100644 --- a/apps/screens.c +++ b/apps/screens.c | |||
@@ -53,6 +53,7 @@ | |||
53 | #include "backdrop.h" | 53 | #include "backdrop.h" |
54 | #include "viewport.h" | 54 | #include "viewport.h" |
55 | #include "language.h" | 55 | #include "language.h" |
56 | #include "replaygain.h" | ||
56 | 57 | ||
57 | #if CONFIG_CODEC == SWCODEC | 58 | #if CONFIG_CODEC == SWCODEC |
58 | #include "dsp.h" | 59 | #include "dsp.h" |
@@ -728,10 +729,12 @@ static const char* id3_get_info(int selected_item, void* data, | |||
728 | break; | 729 | break; |
729 | #if CONFIG_CODEC == SWCODEC | 730 | #if CONFIG_CODEC == SWCODEC |
730 | case LANG_ID3_TRACK_GAIN: | 731 | case LANG_ID3_TRACK_GAIN: |
731 | val=id3->track_gain_string; | 732 | replaygain_itoa(buffer, buffer_len, id3->track_gain); |
733 | val=(id3->track_gain) ? buffer : NULL; /* only show gains!=0 */ | ||
732 | break; | 734 | break; |
733 | case LANG_ID3_ALBUM_GAIN: | 735 | case LANG_ID3_ALBUM_GAIN: |
734 | val=id3->album_gain_string; | 736 | replaygain_itoa(buffer, buffer_len, id3->album_gain); |
737 | val=(id3->album_gain) ? buffer : NULL; /* only show gains!=0 */ | ||
735 | break; | 738 | break; |
736 | #endif | 739 | #endif |
737 | case LANG_ID3_PATH: | 740 | case LANG_ID3_PATH: |