Hello Henrik,
I finally found some time to make a proper patch for the ReplayGain
support. Let me know if this is acceptable, or if it needs some more
tweaking. I've added the following options to gnupod_addsong.pl:
--disable-ape Do not read APE Tags (MP3 Only)
--disable-v1 with --disable-v2 implies --disable-ape
--replaygain-album Use the ReplayGain album value instead of
the ReplayGain track value (default)
On 4/20/09 3:32 PM, H. Langos wrote:
- Change the call to something like this: (I'm improvising here so don't
use it as it is...)
$soundcheck = ( _parse_ReplayGain($hs->{REPLAYGAIN_TRACK_GAIN}) ||
_parse_iTunNORM($hs->{COMM} || $hs->{COM} || $h->{COMMENT}) )
This will probably fail if _parse_ReplayGain() ever returns a valid value
of 0. So you might have to write a more elaborate version like this:
$soundcheck = _parse_iTunNORM($hs->{COMM} || $hs->{COM} || $h->{COMMENT})
unless defined ($soundcheck = _parse_ReplayGain($hs->{REPLAYGAIN_TRACK_GAIN})) ;
But taking a second look at that sub, it probably never does. So the first
and easier to understand version should be ok.
Actually, if the ReplayGain value is anything above 33.01 dB
_parse_ReplayGain() will return 0. It's not very likely, but possible.
So I went with the second form which seems to work well.
Cheers,
Richard
? .gnupod_version
? Makefile
? autom4te.cache
? config.log
? config.status
? configure
? src/ext/FileMagic.pm.org
Index: src/gnupod_addsong.pl
===================================================================
RCS file: /sources/gnupod/gnupod/src/gnupod_addsong.pl,v
retrieving revision 1.104
diff -u -r1.104 gnupod_addsong.pl
--- src/gnupod_addsong.pl 25 Mar 2009 13:43:27 -0000 1.104
+++ src/gnupod_addsong.pl 6 May 2009 10:17:49 -0000
@@ -44,14 +44,14 @@
$opts{mount} = $ENV{IPOD_MOUNTPOINT};
#Don't add xml and itunes opts.. we *NEED* the mount opt to be set..
GetOptions(\%opts, "version", "help|h", "mount|m=s", "decode|x=s",
"restore|r", "duplicate|d", "disable-v2", "disable-v1",
- "set-title|t=s", "set-artist|a=s", "set-album|l=s",
"set-genre|g=s", "set-rating=i", "set-playcount=i",
- "set-bookmarkable|b", "set-shuffleskip", "artwork=s",
+ "disable-ape", "set-title|t=s", "set-artist|a=s",
"set-album|l=s", "set-genre|g=s", "set-rating=i",
+ "set-playcount=i", "set-bookmarkable|b", "set-shuffleskip",
"artwork=s", "replaygain-album",
"set-songnum", "playlist|p=s@", "reencode|e=i",
"min-vol-adj=i", "max-vol-adj=i", "playlist-is-podcast",
"podcast-files-limit=i", "podcast-cache-dir=s",
"podcast-artwork", "set-compilation");
-GNUpod::FooBar::GetConfig(\%opts, {'decode'=>'s', mount=>'s', duplicate=>'b',
model=>'s',
- 'disable-v1'=>'b', 'disable-v2'=>'b',
'set-songnum'=>'b',
+GNUpod::FooBar::GetConfig(\%opts, {'decode'=>'s', mount=>'s', duplicate=>'b',
model=>'s', 'replaygain-album'=>'b',
+ 'disable-v1'=>'b', 'disable-v2'=>'b',
'disable-ape'=>'b', 'set-songnum'=>'b',
'min-vol-adj'=>'i', 'max-vol-adj'=>'i',
'automktunes'=>'b',
'podcast-files-limit'=>'i',
'podcast-cache-dir'=>'s', 'podcast-artwork'=>'b' },
"gnupod_addsong");
@@ -157,6 +157,8 @@
#Get the filetype
my ($fh,$media_h,$converter) =
GNUpod::FileMagic::wtf_is($file, {noIDv1=>$opts{'disable-v1'},
noIDv2=>$opts{'disable-v2'},
+
noAPE=>$opts{'disable-ape'},
+
rgalbum=>$opts{'replaygain-album'},
decode=>$opts{'decode'}},$con);
unless($fh) {
@@ -734,6 +736,8 @@
0 = download all (default), -X = download
X oldest items, X = download X newest items
--disable-v1 Do not read ID3v1 Tags (MP3 Only)
--disable-v2 Do not read ID3v2 Tags (MP3 Only)
+ --disable-ape Do not read APE Tags (MP3 Only)
--disable-v1 with --disable-v2 implies --disable-ape
+ --replaygain-album Use the ReplayGain album value instead of
the ReplayGain track value (default)
-x --decode=pcm|mp3|aac|aacbm Convert FLAC Files to WAVE/MP3 or AAC
'on-the-fly'. Use '-e' to specify a quality/bitrate
-x --decode=video Convert .avi Files into iPod video
'on-the-fly' (needs ffmpeg with AAC support)
-x --decode=alac Convert FLAC Files into Apple Lossless
'on-the-fly' (needs ffmpeg with ALAC support)
Index: src/ext/FileMagic.pm
===================================================================
RCS file: /sources/gnupod/gnupod/src/ext/FileMagic.pm,v
retrieving revision 1.81
diff -u -r1.81 FileMagic.pm
--- src/ext/FileMagic.pm 17 Sep 2008 09:41:55 -0000 1.81
+++ src/ext/FileMagic.pm 6 May 2009 10:17:49 -0000
@@ -75,8 +75,13 @@
and converters to convert the $file into something iPod compatible and to
extract the meta/media information.
-FLAGS is a hash that may contain a true value for the keys 'noIDv1' and
'noIDv2' if
-you want to skip the extraction of ID3v1 or ID3v2 tags from MP3 files.
+FLAGS is a hash that may contain a true value for the keys 'noIDv1', 'noIDv2'
+and 'noAPE' if you want to skip the extraction of ID3v1, ID3v2 or APE tags
+from MP3 files. APE tags are always read in conjunction with ID3 tags.
+Disabling the use of both ID3v1 and ID3v2 tags also disables the reading
+of APE tags from MP3 files. Set a true value for the key 'rgalbum' if you
+want to use the album ReplayGain value instead of the track ReplayGain
+value (default).
Returns:
@@ -482,8 +487,8 @@
$rh{time} = int($h->{SECS}*1000);
$rh{fdesc} = "MPEG ${$h}{VERSION} layer ${$h}{LAYER} file";
- $h = MP3::Info::get_mp3tag($file,1) unless $flags->{'noIDv1'};
#Get the IDv1 tag
- $hs = MP3::Info::get_mp3tag($file,2,2) unless $flags->{'noIDv2'};
#Get the IDv2 tag
+ $h = MP3::Info::get_mp3tag($file,1,0,$flags->{'noAPE'}?0:1) unless
$flags->{'noIDv1'}; #Get the IDv1 tag
+ $hs = MP3::Info::get_mp3tag($file,2,2,$flags->{'noAPE'}?0:1) unless
$flags->{'noIDv2'}; #Get the IDv2 tag
my $nonitunescomment = undef;
#The IDv2 Hashref may return arrays.. kill them :)
@@ -505,6 +510,10 @@
#Try to parse things like 01/01
my @songa = pss($hs->{TRCK} || $hs->{TRK} || $h->{TRACKNUM});
my @cda = pss($hs->{TPOS});
+
+ # Use track ReplayGain by default, use album ReplayGain if requested
+ my $rgtag = "REPLAYGAIN_TRACK_GAIN";
+ $rgtag = "REPLAYGAIN_ALBUM_GAIN" if($flags->{'rgalbum'});
$rh{songs} = int($songa[1]);
$rh{songnum} = int($songa[0]);
@@ -519,7 +528,7 @@
$rh{desc} = __merge_strings({joinby => " ", wspace => "norm",
case => "ignore"},($hs->{USLT} || $hs->{ULT}),($nonitunescomment ||
$h->{COMMENT}));
$rh{composer} = ($hs->{TCOM} || $hs->{TCM} || "");
$rh{playcount} = int($hs->{PCNT} || $hs->{CNT}) || 0;
- $rh{soundcheck} = _parse_iTunNORM($hs->{COMM} || $hs->{COM} ||
$h->{COMMENT});
+ $rh{soundcheck} = _parse_iTunNORM($hs->{COMM} || $hs->{COM} ||
$h->{COMMENT}) unless defined($rh{soundcheck} = _parse_ReplayGain($hs->{$rgtag}
|| $h->{$rgtag}));
$rh{mediatype} = MEDIATYPE_AUDIO;
# Handle volume adjustment information
@@ -789,6 +798,32 @@
=cut
+#########################################################
+# Convert ReplayGain to SoundCheck
+# Code adapted from http://projects.robinbowes.com/flac2mp3/trac/ticket/30
+
+=item _parse_ReplayGain(VALUE)
+
+Converts ReplayGain VALUE in dB to iTunes Sound Check value. Anything
+outside the range of -18.16 dB to 33.01 dB will be rounded to those values.
+For more information on ReplayGain see http://replaygain.hydrogenaudio.org/
+
+=cut
+
+sub _parse_ReplayGain {
+ my ($gain) = @_;
+ return undef unless defined($gain);
+ if($gain =~ /(.*)\s+dB$/) {
+ $gain = $1
+ }
+ return undef unless ($gain =~ /^\s*-?\d+\.?\d*\s*$/);
+ my $result = int((10 ** (-$gain / 10)) * 1000 + .5);
+ if ($result > 65534) {
+ $result = 65534;
+ }
+ return oct(sprintf("0x%08X",$result));
+}
+
1;
_______________________________________________
Bug-gnupod mailing list
Bug-gnupod@nongnu.org
http://lists.nongnu.org/mailman/listinfo/bug-gnupod