diff options
Diffstat (limited to 'apps/metadata/mpc.c')
-rw-r--r-- | apps/metadata/mpc.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/apps/metadata/mpc.c b/apps/metadata/mpc.c index a8cd128828..c6f3c3df72 100644 --- a/apps/metadata/mpc.c +++ b/apps/metadata/mpc.c | |||
@@ -8,6 +8,7 @@ | |||
8 | * $Id$ | 8 | * $Id$ |
9 | * | 9 | * |
10 | * Copyright (C) 2005 Thom Johansen | 10 | * Copyright (C) 2005 Thom Johansen |
11 | * Copyright (C) 2010 Andree Buschmann | ||
11 | * | 12 | * |
12 | * This program is free software; you can redistribute it and/or | 13 | * This program is free software; you can redistribute it and/or |
13 | * modify it under the terms of the GNU General Public License | 14 | * modify it under the terms of the GNU General Public License |
@@ -27,9 +28,11 @@ | |||
27 | #include "metadata_parsers.h" | 28 | #include "metadata_parsers.h" |
28 | #include "logf.h" | 29 | #include "logf.h" |
29 | #include "replaygain.h" | 30 | #include "replaygain.h" |
31 | #include "fixedpoint.h" | ||
30 | 32 | ||
31 | /* Needed for replay gain in sv8, please search MPC_OLD_GAIN_REF in libmusepack */ | 33 | /* Needed for replay gain and clipping prevention of SV8 files. */ |
32 | #define SV8_TO_SV7_CONVERT_GAIN (6482) /* 64.82 * 100 */ | 34 | #define SV8_TO_SV7_CONVERT_GAIN (6482) /* 64.82 * 100, MPC_OLD_GAIN_REF */ |
35 | #define SV8_TO_SV7_CONVERT_PEAK (23119) /* 256 * 20 * log10(32768) */ | ||
33 | 36 | ||
34 | static int set_replaygain_sv7(struct mp3entry* id3, | 37 | static int set_replaygain_sv7(struct mp3entry* id3, |
35 | bool album, | 38 | bool album, |
@@ -39,15 +42,9 @@ static int set_replaygain_sv7(struct mp3entry* id3, | |||
39 | long gain = (int16_t) ((value >> 16) & 0xffff); | 42 | long gain = (int16_t) ((value >> 16) & 0xffff); |
40 | long peak = (uint16_t) (value & 0xffff); | 43 | long peak = (uint16_t) (value & 0xffff); |
41 | 44 | ||
42 | /* Remark: mpc sv7 outputs peak as amplitude, not as dB. The following | ||
43 | * useage of peak is not correct and needs to be fixed. */ | ||
44 | |||
45 | /* We use a peak value of 0 to indicate a given gain type isn't used. */ | 45 | /* We use a peak value of 0 to indicate a given gain type isn't used. */ |
46 | if (peak != 0) { | 46 | if (peak != 0) { |
47 | /* Use the Xing TOC field to store ReplayGain strings for use in the | 47 | /* Save the ReplayGain data to id3-structure for further processing. */ |
48 | * ID3 screen, since Musepack files shouldn't need to use it in any | ||
49 | * other way. | ||
50 | */ | ||
51 | used += parse_replaygain_int(album, gain * 512 / 100, peak << 9, | 48 | used += parse_replaygain_int(album, gain * 512 / 100, peak << 9, |
52 | id3, id3->toc + used, sizeof(id3->toc) - used); | 49 | id3, id3->toc + used, sizeof(id3->toc) - used); |
53 | } | 50 | } |
@@ -63,13 +60,19 @@ static int set_replaygain_sv8(struct mp3entry* id3, | |||
63 | { | 60 | { |
64 | gain = (long)(SV8_TO_SV7_CONVERT_GAIN - ((gain*100)/256)); | 61 | gain = (long)(SV8_TO_SV7_CONVERT_GAIN - ((gain*100)/256)); |
65 | 62 | ||
63 | /* Transform SV8's logarithmic peak representation to the desired linear | ||
64 | * representation: linear = pow(10, peak/256/20). | ||
65 | * | ||
66 | * FP_BITS = 24 bits = desired fp representation for dsp routines | ||
67 | * FRAC_BITS = 12 bits = resolution used for fp_bits | ||
68 | * fp_factor(peak*(1<<FRAC_BITS)/256, FRAC_BITS) << (FP_BITS-FRAC_BITS) | ||
69 | **/ | ||
70 | peak = (fp_factor((peak-SV8_TO_SV7_CONVERT_PEAK)*16, 12) << 12); | ||
71 | |||
66 | /* 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. */ |
67 | if (peak != 0) { | 73 | if (peak != 0) { |
68 | /* Use the Xing TOC field to store ReplayGain strings for use in the | 74 | /* Save the ReplayGain data to id3-structure for further processing. */ |
69 | * ID3 screen, since Musepack files shouldn't need to use it in any | 75 | used += parse_replaygain_int(album, gain * 512 / 100, peak, |
70 | * other way. | ||
71 | */ | ||
72 | used += parse_replaygain_int(album, gain * 512 / 100, peak << 9, | ||
73 | id3, id3->toc + used, sizeof(id3->toc) - used); | 76 | id3, id3->toc + used, sizeof(id3->toc) - used); |
74 | } | 77 | } |
75 | 78 | ||